2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 Contains: IPI for File Manager (HFS Plus)
35 Copyright: © 1996-2001 by Apple Computer, Inc., all rights reserved.
38 #ifndef __FILEMGRINTERNAL__
39 #define __FILEMGRINTERNAL__
41 #include <sys/appleapiopts.h>
44 #ifdef __APPLE_API_PRIVATE
46 #include <sys/param.h>
47 #include <sys/vnode.h>
49 #include "../../hfs.h"
50 #include "../../hfs_macos_defs.h"
51 #include "../../hfs_format.h"
52 #include "../../hfs_cnode.h"
59 /* CatalogNodeID is used to track catalog objects */
60 typedef u_int32_t HFSCatalogNodeID
;
62 /* internal error codes*/
64 #if TARGET_API_MACOS_X
65 #define ERR_BASE -32767
72 fxRangeErr
= ERR_BASE
+ 16, /* file position beyond mapped range*/
73 fxOvFlErr
= ERR_BASE
+ 17, /* extents file overflow*/
75 uniTooLongErr
= ERR_BASE
+ 24, /* Unicode string too long to convert to Str31*/
76 uniBufferTooSmallErr
= ERR_BASE
+ 25, /* Unicode output buffer too small*/
77 uniNotMappableErr
= ERR_BASE
+ 26, /* Unicode string can't be mapped to given script*/
78 /* BTree Manager errors*/
79 btNotFound
= ERR_BASE
+ 32, /* record not found*/
80 btExists
= ERR_BASE
+ 33, /* record already exists*/
81 btNoSpaceAvail
= ERR_BASE
+ 34, /* no available space*/
82 btNoFit
= ERR_BASE
+ 35, /* record doesn't fit in node */
83 btBadNode
= ERR_BASE
+ 36, /* bad node detected*/
84 btBadHdr
= ERR_BASE
+ 37, /* bad BTree header record detected*/
85 dsBadRotate
= ERR_BASE
+ 64, /* bad BTree rotate*/
86 /* Catalog Manager errors*/
87 cmNotFound
= ERR_BASE
+ 48, /* CNode not found*/
88 cmExists
= ERR_BASE
+ 49, /* CNode already exists*/
89 cmNotEmpty
= ERR_BASE
+ 50, /* directory CNode not empty (valence = 0)*/
90 cmRootCN
= ERR_BASE
+ 51, /* invalid reference to root CNode*/
91 cmBadNews
= ERR_BASE
+ 52, /* detected bad catalog structure*/
92 cmFThdDirErr
= ERR_BASE
+ 53, /* thread belongs to a directory not a file*/
93 cmFThdGone
= ERR_BASE
+ 54, /* file thread doesn't exist*/
94 cmParentNotFound
= ERR_BASE
+ 55, /* CNode for parent ID does not exist*/
95 /* TFS internal errors*/
96 fsDSIntErr
= -127 /* Internal file system error*/
103 kEFAllMask
= 0x01, /* allocate all requested bytes or none */
104 kEFContigMask
= 0x02, /* force contiguous allocation */
105 kEFReserveMask
= 0x04, /* keep block reserve */
106 kEFDeferMask
= 0x08, /* defer file block allocations */
107 kEFNoClumpMask
= 0x10, /* don't round up to clump size */
108 kEFMetadataMask
= 0x20, /* metadata allocation */
110 kTFTrunExtBit
= 0, /* truncate to the extent containing new PEOF*/
115 kUndefinedStrLen
= 0, /* Unknown string length */
118 /* FileIDs variables*/
119 kNumExtentsToCache
= 4 /* just guessing for ExchangeFiles*/
123 /* Universal Extent Key */
127 HFSPlusExtentKey hfsPlus
;
129 typedef union ExtentKey ExtentKey
;
130 /* Universal extent descriptor */
132 union ExtentDescriptor
{
133 HFSExtentDescriptor hfs
;
134 HFSPlusExtentDescriptor hfsPlus
;
136 typedef union ExtentDescriptor ExtentDescriptor
;
137 /* Universal extent record */
141 HFSPlusExtentRecord hfsPlus
;
143 typedef union ExtentRecord ExtentRecord
;
147 CMMaxCName
= kHFSMaxFileNameChars
152 /* Universal catalog name*/
158 typedef union CatalogName CatalogName
;
162 * MacOS accessor routines
164 #define GetFileControlBlock(fref) VTOF((fref))
165 #define GetFileRefNumFromFCB(fcb) FTOV((fcb))
167 /* Test for error and return if error occurred*/
169 ReturnIfError (OSErr result
);
171 #define ReturnIfError(result) do { if ( (result) != noErr ) return (result); } while(0)
173 /* Exit function on error*/
175 ExitOnError (OSErr result
);
177 #define ExitOnError( result ) do { if ( ( result ) != noErr ) goto ErrorExit; } while(0)
181 /* Catalog Manager Routines (IPI)*/
183 EXTERN_API_C( OSErr
)
184 ExchangeFileIDs (ExtendedVCB
* volume
,
185 ConstUTF8Param srcName
,
186 ConstUTF8Param destName
,
187 HFSCatalogNodeID srcID
,
188 HFSCatalogNodeID destID
,
190 u_int32_t destHint
);
193 /* BTree Manager Routines*/
195 typedef CALLBACK_API_C( int32_t , KeyCompareProcPtr
)(void *a
, void *b
);
198 EXTERN_API_C( OSErr
)
199 ReplaceBTreeRecord (FileReference refNum
,
204 u_int32_t
* newHint
);
207 /* Prototypes for exported routines in VolumeAllocation.c*/
208 EXTERN_API_C( OSErr
)
209 BlockAllocate (ExtendedVCB
* vcb
,
210 u_int32_t startingBlock
,
213 Boolean forceContiguous
,
215 u_int32_t
* startBlock
,
216 u_int32_t
* actualBlocks
);
218 EXTERN_API_C( OSErr
)
219 BlockDeallocate (ExtendedVCB
* vcb
,
220 u_int32_t firstBlock
,
221 u_int32_t numBlocks
);
223 EXTERN_API_C( OSErr
)
224 BlockMarkAllocated(ExtendedVCB
*vcb
, u_int32_t startingBlock
, u_int32_t numBlocks
);
226 EXTERN_API_C( OSErr
)
227 BlockMarkFree( ExtendedVCB
*vcb
, u_int32_t startingBlock
, u_int32_t numBlocks
);
229 EXTERN_API_C( u_int32_t
)
230 MetaZoneFreeBlocks(ExtendedVCB
*vcb
);
232 /* File Extent Mapping routines*/
233 EXTERN_API_C( OSErr
)
234 FlushExtentFile (ExtendedVCB
* vcb
);
236 EXTERN_API_C( int32_t )
237 CompareExtentKeys (const HFSExtentKey
* searchKey
,
238 const HFSExtentKey
* trialKey
);
240 EXTERN_API_C( int32_t )
241 CompareExtentKeysPlus (const HFSPlusExtentKey
*searchKey
,
242 const HFSPlusExtentKey
*trialKey
);
244 EXTERN_API_C( OSErr
)
245 TruncateFileC (ExtendedVCB
* vcb
,
248 Boolean truncateToExtent
);
250 EXTERN_API_C( OSErr
)
251 ExtendFileC (ExtendedVCB
* vcb
,
256 int64_t * actualBytesAdded
);
258 EXTERN_API_C( OSErr
)
259 MapFileBlockC (ExtendedVCB
* vcb
,
261 size_t numberOfBytes
,
263 daddr64_t
* startBlock
,
264 size_t * availableBytes
);
266 OSErr
HeadTruncateFile(ExtendedVCB
*vcb
, FCB
*fcb
, u_int32_t headblks
);
269 AddFileExtent (ExtendedVCB
*vcb
, FCB
*fcb
, u_int32_t startBlock
, u_int32_t blockCount
);
271 #if TARGET_API_MACOS_X
272 EXTERN_API_C( Boolean
)
273 NodesAreContiguous (ExtendedVCB
* vcb
,
280 /* Get the current time in UTC (GMT)*/
281 EXTERN_API_C( u_int32_t
)
284 EXTERN_API_C( u_int32_t
)
285 LocalToUTC (u_int32_t localTime
);
287 EXTERN_API_C( u_int32_t
)
288 UTCToLocal (u_int32_t utcTime
);
295 #endif /* __APPLE_API_PRIVATE */
297 #endif /* __FILEMGRINTERNAL__ */