]> git.saurik.com Git - apple/xnu.git/blame - bsd/hfs/hfscommon/Catalog/FileIDsServices.c
xnu-344.tar.gz
[apple/xnu.git] / bsd / hfs / hfscommon / Catalog / FileIDsServices.c
CommitLineData
1c79356b 1/*
9bccf70c 2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
1c79356b
A
22
23#include "../../hfs_macos_defs.h"
24#include "../../hfs_format.h"
25
26#include "../headers/FileMgrInternal.h"
27#include "../headers/HFSUnicodeWrappers.h"
28#include "../headers/CatalogPrivate.h"
29
30
31struct ExtentsRecBuffer {
9bccf70c 32 ExtentKey extentKey;
1c79356b
A
33 ExtentRecord extentData;
34};
35typedef struct ExtentsRecBuffer ExtentsRecBuffer;
36
37
1c79356b
A
38UInt32 CheckExtents( void *extents, UInt32 blocks, Boolean isHFSPlus );
39OSErr DeleteExtents( ExtendedVCB *vcb, UInt32 fileNumber, Boolean isHFSPlus );
40OSErr MoveExtents( ExtendedVCB *vcb, UInt32 srcFileID, UInt32 destFileID, Boolean isHFSPlus );
41void CopyCatalogNodeInfo( CatalogRecord *src, CatalogRecord *dest );
42void CopyBigCatalogNodeInfo( CatalogRecord *src, CatalogRecord *dest );
1c79356b 43void CopyExtentInfo( ExtentKey *key, ExtentRecord *data, ExtentsRecBuffer *buffer, UInt16 bufferCount );
1c79356b
A
44
45
46
47OSErr ExchangeFileIDs( ExtendedVCB *vcb, ConstUTF8Param srcName, ConstUTF8Param destName, HFSCatalogNodeID srcID, HFSCatalogNodeID destID, UInt32 srcHint, UInt32 destHint )
48{
9bccf70c
A
49 CatalogKey srcKey; // 518 bytes
50 CatalogKey destKey; // 518 bytes
1c79356b 51 CatalogRecord srcData; // 520 bytes
1c79356b
A
52 CatalogRecord destData; // 520 bytes
53 CatalogRecord swapData; // 520 bytes
9bccf70c
A
54 SInt16 numSrcExtentBlocks;
55 SInt16 numDestExtentBlocks;
56 OSErr err;
57 Boolean isHFSPlus = ( vcb->vcbSigWord == kHFSPlusSigWord );
1c79356b
A
58
59 TrashCatalogIterator(vcb, srcID); // invalidate any iterators for this parentID
60 TrashCatalogIterator(vcb, destID); // invalidate any iterators for this parentID
61
0b4e3aa0 62 err = BuildCatalogKeyUTF8(vcb, srcID, srcName, kUndefinedStrLen, &srcKey, NULL);
1c79356b
A
63 ReturnIfError(err);
64
0b4e3aa0 65 err = BuildCatalogKeyUTF8(vcb, destID, destName, kUndefinedStrLen, &destKey, NULL);
1c79356b
A
66 ReturnIfError(err);
67
68 if ( isHFSPlus )
69 {
70 //-- Step 1: Check the catalog nodes for extents
71
72 //-- locate the source file, test for extents in extent file, and copy the cat record for later
73 err = LocateCatalogNodeByKey( vcb, srcHint, &srcKey, &srcData, &srcHint );
74 ReturnIfError( err );
75
76 if ( srcData.recordType != kHFSPlusFileRecord )
77 return( cmFThdDirErr ); // Error "cmFThdDirErr = it is a directory"
78
79 //-- Check if there are any extents in the source file
80