]> git.saurik.com Git - apple/xnu.git/blame - bsd/hfs/hfscommon/Catalog/FileIDsServices.c
xnu-792.24.17.tar.gz
[apple/xnu.git] / bsd / hfs / hfscommon / Catalog / FileIDsServices.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
1c79356b 5 *
6601e61a
A
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.
8f6c56a5 11 *
6601e61a
A
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
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
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.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
1c79356b 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
91447636
A
38static UInt32 CheckExtents( void *extents, UInt32 blocks, Boolean isHFSPlus );
39static OSErr DeleteExtents( ExtendedVCB *vcb, UInt32 fileNumber, Boolean isHFSPlus );
40static OSErr MoveExtents( ExtendedVCB *vcb, UInt32 srcFileID, UInt32 destFileID, Boolean isHFSPlus );
41static void CopyCatalogNodeInfo( CatalogRecord *src, CatalogRecord *dest );
42static void CopyBigCatalogNodeInfo( CatalogRecord *src, CatalogRecord *dest );
43static void 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 58
0b4e3aa0 59 err = BuildCatalogKeyUTF8(vcb, srcID, srcName, kUndefinedStrLen, &srcKey, NULL);
1c79356b
A
60 ReturnIfError(err);
61
0b4e3aa0 62 err = BuildCatalogKeyUTF8(vcb, destID, destName, kUndefinedStrLen, &destKey, NULL);
1c79356b
A
63 ReturnIfError(err);
64
65 if ( isHFSPlus )
66 {
67 //-- Step 1: Check the catalog nodes for extents
68
69 //-- locate the source file, test for extents in extent file, and copy the cat record for later
70 err = LocateCatalogNodeByKey( vcb, srcHint, &srcKey, &srcData, &srcHint );
71 ReturnIfError( err );
72
73 if ( srcData.recordType != kHFSPlusFileRecord )
74 return( cmFThdDirErr ); // Error "cmFThdDirErr = it is a directory"
75
76 //-- Check if there are any extents in the source file
77