2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 Contains: IPI for File Manager (HFS Plus)
30 Copyright: © 1996-2001 by Apple Computer, Inc., all rights reserved.
33 #ifndef __FILEMGRINTERNAL__
34 #define __FILEMGRINTERNAL__
36 #include <sys/appleapiopts.h>
39 #ifdef __APPLE_API_PRIVATE
41 #include <sys/param.h>
42 #include <sys/vnode.h>
44 #include "../../hfs.h"
45 #include "../../hfs_macos_defs.h"
46 #include "../../hfs_format.h"
47 #include "../../hfs_cnode.h"
62 #if PRAGMA_STRUCT_ALIGN
63 #pragma options align=mac68k
64 #elif PRAGMA_STRUCT_PACKPUSH
66 #elif PRAGMA_STRUCT_PACK
70 /* CatalogNodeID is used to track catalog objects */
71 typedef UInt32 HFSCatalogNodeID
;
73 /* internal error codes*/
75 #if TARGET_API_MACOS_X
76 #define ERR_BASE -32767
83 fxRangeErr
= ERR_BASE
+ 16, /* file position beyond mapped range*/
84 fxOvFlErr
= ERR_BASE
+ 17, /* extents file overflow*/
86 uniTooLongErr
= ERR_BASE
+ 24, /* Unicode string too long to convert to Str31*/
87 uniBufferTooSmallErr
= ERR_BASE
+ 25, /* Unicode output buffer too small*/
88 uniNotMappableErr
= ERR_BASE
+ 26, /* Unicode string can't be mapped to given script*/
89 /* BTree Manager errors*/
90 btNotFound
= ERR_BASE
+ 32, /* record not found*/
91 btExists
= ERR_BASE
+ 33, /* record already exists*/
92 btNoSpaceAvail
= ERR_BASE
+ 34, /* no available space*/
93 btNoFit
= ERR_BASE
+ 35, /* record doesn't fit in node */
94 btBadNode
= ERR_BASE
+ 36, /* bad node detected*/
95 btBadHdr
= ERR_BASE
+ 37, /* bad BTree header record detected*/
96 dsBadRotate
= ERR_BASE
+ 64, /* bad BTree rotate*/
97 /* Catalog Manager errors*/
98 cmNotFound
= ERR_BASE
+ 48, /* CNode not found*/
99 cmExists
= ERR_BASE
+ 49, /* CNode already exists*/
100 cmNotEmpty
= ERR_BASE
+ 50, /* directory CNode not empty (valence = 0)*/
101 cmRootCN
= ERR_BASE
+ 51, /* invalid reference to root CNode*/
102 cmBadNews
= ERR_BASE
+ 52, /* detected bad catalog structure*/
103 cmFThdDirErr
= ERR_BASE
+ 53, /* thread belongs to a directory not a file*/
104 cmFThdGone
= ERR_BASE
+ 54, /* file thread doesn't exist*/
105 cmParentNotFound
= ERR_BASE
+ 55, /* CNode for parent ID does not exist*/
106 /* TFS internal errors*/
107 fsDSIntErr
= -127 /* Internal file system error*/
114 kEFAllMask
= 0x01, /* allocate all requested bytes or none */
115 kEFContigMask
= 0x02, /* force contiguous allocation */
116 kEFReserveMask
= 0x04, /* keep block reserve */
117 kEFDeferMask
= 0x08, /* defer file block allocations */
118 kEFNoClumpMask
= 0x10, /* don't round up to clump size */
119 kEFMetadataMask
= 0x20, /* metadata allocation */
121 kTFTrunExtBit
= 0, /* truncate to the extent containing new PEOF*/
126 kUndefinedStrLen
= 0, /* Unknown string length */
129 /* FileIDs variables*/
130 kNumExtentsToCache
= 4 /* just guessing for ExchangeFiles*/
134 /* Universal Extent Key */
138 HFSPlusExtentKey hfsPlus
;
140 typedef union ExtentKey ExtentKey
;
141 /* Universal extent descriptor */
143 union ExtentDescriptor
{
144 HFSExtentDescriptor hfs
;
145 HFSPlusExtentDescriptor hfsPlus
;
147 typedef union ExtentDescriptor ExtentDescriptor
;
148 /* Universal extent record */
152 HFSPlusExtentRecord hfsPlus
;
154 typedef union ExtentRecord ExtentRecord
;
158 CMMaxCName
= kHFSMaxFileNameChars
163 /* Universal catalog name*/
169 typedef union CatalogName CatalogName
;
173 * MacOS accessor routines
175 #define GetFileControlBlock(fref) VTOF((fref))
176 #define GetFileRefNumFromFCB(fcb) FTOV((fcb))
179 /* The following macro marks a VCB as dirty by setting the upper 8 bits of the flags*/
181 MarkVCBDirty (ExtendedVCB
*vcb
);
184 MarkVCBClean (ExtendedVCB
*vcb
);
186 EXTERN_API_C( Boolean
)
187 IsVCBDirty (ExtendedVCB
*vcb
);
190 #define MarkVCBDirty(vcb) { ((vcb)->vcbFlags |= 0xFF00); }
191 #define MarkVCBClean(vcb) { ((vcb)->vcbFlags &= 0x00FF); }
192 #define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
195 /* Test for error and return if error occurred*/
197 ReturnIfError (OSErr result
);
199 #define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
201 /* Exit function on error*/
203 ExitOnError (OSErr result
);
205 #define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
209 /* Catalog Manager Routines (IPI)*/
211 EXTERN_API_C( OSErr
)
212 ExchangeFileIDs (ExtendedVCB
* volume
,
213 ConstUTF8Param srcName
,
214 ConstUTF8Param destName
,
215 HFSCatalogNodeID srcID
,
216 HFSCatalogNodeID destID
,
221 /* BTree Manager Routines*/
223 typedef CALLBACK_API_C( SInt32
, KeyCompareProcPtr
)(void *a
, void *b
);
226 EXTERN_API_C( OSErr
)
227 SearchBTreeRecord (FileReference refNum
,
235 EXTERN_API_C( OSErr
)
236 ReplaceBTreeRecord (FileReference refNum
,
244 /* Prototypes for exported routines in VolumeAllocation.c*/
245 EXTERN_API_C( OSErr
)
246 BlockAllocate (ExtendedVCB
* vcb
,
247 UInt32 startingBlock
,
250 Boolean forceContiguous
,
253 UInt32
* actualBlocks
);
255 EXTERN_API_C( OSErr
)
256 BlockDeallocate (ExtendedVCB
* vcb
,
260 EXTERN_API_C( OSErr
)
261 BlockMarkAllocated(ExtendedVCB
*vcb
, UInt32 startingBlock
, UInt32 numBlocks
);
263 EXTERN_API_C( OSErr
)
264 BlockMarkFree( ExtendedVCB
*vcb
, UInt32 startingBlock
, UInt32 numBlocks
);
266 EXTERN_API_C( UInt32
)
267 MetaZoneFreeBlocks(ExtendedVCB
*vcb
);
269 /* File Extent Mapping routines*/
270 EXTERN_API_C( OSErr
)
271 FlushExtentFile (ExtendedVCB
* vcb
);
273 EXTERN_API_C( SInt32
)
274 CompareExtentKeys (const HFSExtentKey
* searchKey
,
275 const HFSExtentKey
* trialKey
);
277 EXTERN_API_C( SInt32
)
278 CompareExtentKeysPlus (const HFSPlusExtentKey
*searchKey
,
279 const HFSPlusExtentKey
*trialKey
);
281 EXTERN_API_C( OSErr
)
282 TruncateFileC (ExtendedVCB
* vcb
,
285 Boolean truncateToExtent
);
287 EXTERN_API_C( OSErr
)
288 ExtendFileC (ExtendedVCB
* vcb
,
293 SInt64
* actualBytesAdded
);
295 EXTERN_API_C( OSErr
)
296 MapFileBlockC (ExtendedVCB
* vcb
,
298 size_t numberOfBytes
,
300 daddr64_t
* startBlock
,
301 size_t * availableBytes
);
303 OSErr
HeadTruncateFile(ExtendedVCB
*vcb
, FCB
*fcb
, UInt32 headblks
);
306 AddFileExtent (ExtendedVCB
*vcb
, FCB
*fcb
, UInt32 startBlock
, UInt32 blockCount
);
308 #if TARGET_API_MACOS_X
309 EXTERN_API_C( Boolean
)
310 NodesAreContiguous (ExtendedVCB
* vcb
,
317 /* Get the current time in UTC (GMT)*/
318 EXTERN_API_C( UInt32
)
321 EXTERN_API_C( UInt32
)
322 LocalToUTC (UInt32 localTime
);
324 EXTERN_API_C( UInt32
)
325 UTCToLocal (UInt32 utcTime
);
328 #if PRAGMA_STRUCT_ALIGN
329 #pragma options align=reset
330 #elif PRAGMA_STRUCT_PACKPUSH
332 #elif PRAGMA_STRUCT_PACK
336 #ifdef PRAGMA_IMPORT_OFF
346 #endif /* __APPLE_API_PRIVATE */
348 #endif /* __FILEMGRINTERNAL__ */