2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
33 Contains: IPI for File Manager (HFS Plus)
37 Copyright: © 1996-2001 by Apple Computer, Inc., all rights reserved.
40 #ifndef __FILEMGRINTERNAL__
41 #define __FILEMGRINTERNAL__
43 #include <sys/appleapiopts.h>
46 #ifdef __APPLE_API_PRIVATE
48 #include <sys/param.h>
49 #include <sys/vnode.h>
51 #include "../../hfs.h"
52 #include "../../hfs_macos_defs.h"
53 #include "../../hfs_format.h"
54 #include "../../hfs_cnode.h"
69 #if PRAGMA_STRUCT_ALIGN
70 #pragma options align=mac68k
71 #elif PRAGMA_STRUCT_PACKPUSH
73 #elif PRAGMA_STRUCT_PACK
77 /* CatalogNodeID is used to track catalog objects */
78 typedef UInt32 HFSCatalogNodeID
;
80 /* internal error codes*/
82 #if TARGET_API_MACOS_X
83 #define ERR_BASE -32767
90 fxRangeErr
= ERR_BASE
+ 16, /* file position beyond mapped range*/
91 fxOvFlErr
= ERR_BASE
+ 17, /* extents file overflow*/
93 uniTooLongErr
= ERR_BASE
+ 24, /* Unicode string too long to convert to Str31*/
94 uniBufferTooSmallErr
= ERR_BASE
+ 25, /* Unicode output buffer too small*/
95 uniNotMappableErr
= ERR_BASE
+ 26, /* Unicode string can't be mapped to given script*/
96 /* BTree Manager errors*/
97 btNotFound
= ERR_BASE
+ 32, /* record not found*/
98 btExists
= ERR_BASE
+ 33, /* record already exists*/
99 btNoSpaceAvail
= ERR_BASE
+ 34, /* no available space*/
100 btNoFit
= ERR_BASE
+ 35, /* record doesn't fit in node */
101 btBadNode
= ERR_BASE
+ 36, /* bad node detected*/
102 btBadHdr
= ERR_BASE
+ 37, /* bad BTree header record detected*/
103 dsBadRotate
= ERR_BASE
+ 64, /* bad BTree rotate*/
104 /* Catalog Manager errors*/
105 cmNotFound
= ERR_BASE
+ 48, /* CNode not found*/
106 cmExists
= ERR_BASE
+ 49, /* CNode already exists*/
107 cmNotEmpty
= ERR_BASE
+ 50, /* directory CNode not empty (valence = 0)*/
108 cmRootCN
= ERR_BASE
+ 51, /* invalid reference to root CNode*/
109 cmBadNews
= ERR_BASE
+ 52, /* detected bad catalog structure*/
110 cmFThdDirErr
= ERR_BASE
+ 53, /* thread belongs to a directory not a file*/
111 cmFThdGone
= ERR_BASE
+ 54, /* file thread doesn't exist*/
112 cmParentNotFound
= ERR_BASE
+ 55, /* CNode for parent ID does not exist*/
113 /* TFS internal errors*/
114 fsDSIntErr
= -127 /* Internal file system error*/
121 kEFAllMask
= 0x01, /* allocate all requested bytes or none */
122 kEFContigMask
= 0x02, /* force contiguous allocation */
123 kEFReserveMask
= 0x04, /* keep block reserve */
124 kEFDeferMask
= 0x08, /* defer file block allocations */
125 kEFNoClumpMask
= 0x10, /* don't round up to clump size */
126 kEFMetadataMask
= 0x20, /* metadata allocation */
128 kTFTrunExtBit
= 0, /* truncate to the extent containing new PEOF*/
133 kUndefinedStrLen
= 0, /* Unknown string length */
136 /* FileIDs variables*/
137 kNumExtentsToCache
= 4 /* just guessing for ExchangeFiles*/
141 /* Universal Extent Key */
145 HFSPlusExtentKey hfsPlus
;
147 typedef union ExtentKey ExtentKey
;
148 /* Universal extent descriptor */
150 union ExtentDescriptor
{
151 HFSExtentDescriptor hfs
;
152 HFSPlusExtentDescriptor hfsPlus
;
154 typedef union ExtentDescriptor ExtentDescriptor
;
155 /* Universal extent record */
159 HFSPlusExtentRecord hfsPlus
;
161 typedef union ExtentRecord ExtentRecord
;
165 CMMaxCName
= kHFSMaxFileNameChars
170 /* Universal catalog name*/
176 typedef union CatalogName CatalogName
;
180 * MacOS accessor routines
182 #define GetFileControlBlock(fref) VTOF((fref))
183 #define GetFileRefNumFromFCB(fcb) FTOV((fcb))
186 /* The following macro marks a VCB as dirty by setting the upper 8 bits of the flags*/
188 MarkVCBDirty (ExtendedVCB
*vcb
);
191 MarkVCBClean (ExtendedVCB
*vcb
);
193 EXTERN_API_C( Boolean
)
194 IsVCBDirty (ExtendedVCB
*vcb
);
197 #define MarkVCBDirty(vcb) { ((vcb)->vcbFlags |= 0xFF00); }
198 #define MarkVCBClean(vcb) { ((vcb)->vcbFlags &= 0x00FF); }
199 #define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
202 /* Test for error and return if error occurred*/
204 ReturnIfError (OSErr result
);
206 #define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
208 /* Exit function on error*/
210 ExitOnError (OSErr result
);
212 #define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
216 /* Catalog Manager Routines (IPI)*/
218 EXTERN_API_C( OSErr
)
219 ExchangeFileIDs (ExtendedVCB
* volume
,
220 ConstUTF8Param srcName
,
221 ConstUTF8Param destName
,
222 HFSCatalogNodeID srcID
,
223 HFSCatalogNodeID destID
,
228 /* BTree Manager Routines*/
230 typedef CALLBACK_API_C( SInt32
, KeyCompareProcPtr
)(void *a
, void *b
);
233 EXTERN_API_C( OSErr
)
234 SearchBTreeRecord (FileReference refNum
,
242 EXTERN_API_C( OSErr
)
243 ReplaceBTreeRecord (FileReference refNum
,
251 /* Prototypes for exported routines in VolumeAllocation.c*/
252 EXTERN_API_C( OSErr
)
253 BlockAllocate (ExtendedVCB
* vcb
,
254 UInt32 startingBlock
,
257 Boolean forceContiguous
,
260 UInt32
* actualBlocks
);
262 EXTERN_API_C( OSErr
)
263 BlockDeallocate (ExtendedVCB
* vcb
,
267 EXTERN_API_C( OSErr
)
268 BlockMarkAllocated(ExtendedVCB
*vcb
, UInt32 startingBlock
, UInt32 numBlocks
);
270 EXTERN_API_C( OSErr
)
271 BlockMarkFree( ExtendedVCB
*vcb
, UInt32 startingBlock
, UInt32 numBlocks
);
273 EXTERN_API_C( UInt32
)
274 MetaZoneFreeBlocks(ExtendedVCB
*vcb
);
276 /* File Extent Mapping routines*/
277 EXTERN_API_C( OSErr
)
278 FlushExtentFile (ExtendedVCB
* vcb
);
280 EXTERN_API_C( SInt32
)
281 CompareExtentKeys (const HFSExtentKey
* searchKey
,
282 const HFSExtentKey
* trialKey
);
284 EXTERN_API_C( SInt32
)
285 CompareExtentKeysPlus (const HFSPlusExtentKey
*searchKey
,
286 const HFSPlusExtentKey
*trialKey
);
288 EXTERN_API_C( OSErr
)
289 TruncateFileC (ExtendedVCB
* vcb
,
292 Boolean truncateToExtent
);
294 EXTERN_API_C( OSErr
)
295 ExtendFileC (ExtendedVCB
* vcb
,
300 SInt64
* actualBytesAdded
);
302 EXTERN_API_C( OSErr
)
303 MapFileBlockC (ExtendedVCB
* vcb
,
305 size_t numberOfBytes
,
307 daddr64_t
* startBlock
,
308 size_t * availableBytes
);
310 OSErr
HeadTruncateFile(ExtendedVCB
*vcb
, FCB
*fcb
, UInt32 headblks
);
313 AddFileExtent (ExtendedVCB
*vcb
, FCB
*fcb
, UInt32 startBlock
, UInt32 blockCount
);
315 #if TARGET_API_MACOS_X
316 EXTERN_API_C( Boolean
)
317 NodesAreContiguous (ExtendedVCB
* vcb
,
324 /* Get the current time in UTC (GMT)*/
325 EXTERN_API_C( UInt32
)
328 EXTERN_API_C( UInt32
)
329 LocalToUTC (UInt32 localTime
);
331 EXTERN_API_C( UInt32
)
332 UTCToLocal (UInt32 utcTime
);
335 #if PRAGMA_STRUCT_ALIGN
336 #pragma options align=reset
337 #elif PRAGMA_STRUCT_PACKPUSH
339 #elif PRAGMA_STRUCT_PACK
343 #ifdef PRAGMA_IMPORT_OFF
353 #endif /* __APPLE_API_PRIVATE */
355 #endif /* __FILEMGRINTERNAL__ */