]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/hfs/hfscommon/Catalog/FileIDsServices.c
xnu-792.24.17.tar.gz
[apple/xnu.git] / bsd / hfs / hfscommon / Catalog / FileIDsServices.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
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 */
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 {
32 ExtentKey extentKey;
33 ExtentRecord extentData;
34};
35typedef struct ExtentsRecBuffer ExtentsRecBuffer;
36
37
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 );
44
45
46
47OSErr ExchangeFileIDs( ExtendedVCB *vcb, ConstUTF8Param srcName, ConstUTF8Param destName, HFSCatalogNodeID srcID, HFSCatalogNodeID destID, UInt32 srcHint, UInt32 destHint )
48{
49 CatalogKey srcKey; // 518 bytes
50 CatalogKey destKey; // 518 bytes
51 CatalogRecord srcData; // 520 bytes
52 CatalogRecord destData; // 520 bytes
53 CatalogRecord swapData; // 520 bytes
54 SInt16 numSrcExtentBlocks;
55 SInt16 numDestExtentBlocks;
56 OSErr err;
57 Boolean isHFSPlus = ( vcb->vcbSigWord == kHFSPlusSigWord );
58
59 err = BuildCatalogKeyUTF8(vcb, srcID, srcName, kUndefinedStrLen, &srcKey, NULL);
60 ReturnIfError(err);
61
62 err = BuildCatalogKeyUTF8(vcb, destID, destName, kUndefinedStrLen, &destKey, NULL);
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