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"
67 #if PRAGMA_STRUCT_ALIGN
68 #pragma options align=mac68k
69 #elif PRAGMA_STRUCT_PACKPUSH
71 #elif PRAGMA_STRUCT_PACK
75 /* CatalogNodeID is used to track catalog objects */
76 typedef UInt32 HFSCatalogNodeID
;
78 /* internal error codes*/
80 #if TARGET_API_MACOS_X
81 #define ERR_BASE -32767
88 fxRangeErr
= ERR_BASE
+ 16, /* file position beyond mapped range*/
89 fxOvFlErr
= ERR_BASE
+ 17, /* extents file overflow*/
91 uniTooLongErr
= ERR_BASE
+ 24, /* Unicode string too long to convert to Str31*/
92 uniBufferTooSmallErr
= ERR_BASE
+ 25, /* Unicode output buffer too small*/
93 uniNotMappableErr
= ERR_BASE
+ 26, /* Unicode string can't be mapped to given script*/
94 /* BTree Manager errors*/
95 btNotFound
= ERR_BASE
+ 32, /* record not found*/
96 btExists
= ERR_BASE
+ 33, /* record already exists*/
97 btNoSpaceAvail
= ERR_BASE
+ 34, /* no available space*/
98 btNoFit
= ERR_BASE
+ 35, /* record doesn't fit in node */
99 btBadNode
= ERR_BASE
+ 36, /* bad node detected*/
100 btBadHdr
= ERR_BASE
+ 37, /* bad BTree header record detected*/
101 dsBadRotate
= ERR_BASE
+ 64, /* bad BTree rotate*/
102 /* Catalog Manager errors*/
103 cmNotFound
= ERR_BASE
+ 48, /* CNode not found*/
104 cmExists
= ERR_BASE
+ 49, /* CNode already exists*/
105 cmNotEmpty
= ERR_BASE
+ 50, /* directory CNode not empty (valence = 0)*/
106 cmRootCN
= ERR_BASE
+ 51, /* invalid reference to root CNode*/
107 cmBadNews
= ERR_BASE
+ 52, /* detected bad catalog structure*/
108 cmFThdDirErr
= ERR_BASE
+ 53, /* thread belongs to a directory not a file*/
109 cmFThdGone
= ERR_BASE
+ 54, /* file thread doesn't exist*/
110 cmParentNotFound
= ERR_BASE
+ 55, /* CNode for parent ID does not exist*/
111 /* TFS internal errors*/
112 fsDSIntErr
= -127 /* Internal file system error*/
119 kEFAllMask
= 0x01, /* allocate all requested bytes or none */
120 kEFContigMask
= 0x02, /* force contiguous allocation */
121 kEFReserveMask
= 0x04, /* keep block reserve */
122 kEFDeferMask
= 0x08, /* defer file block allocations */
123 kEFNoClumpMask
= 0x10, /* don't round up to clump size */
124 kEFMetadataMask
= 0x20, /* metadata allocation */
126 kTFTrunExtBit
= 0, /* truncate to the extent containing new PEOF*/
131 kUndefinedStrLen
= 0, /* Unknown string length */
134 /* FileIDs variables*/
135 kNumExtentsToCache
= 4 /* just guessing for ExchangeFiles*/
139 /* Universal Extent Key */
143 HFSPlusExtentKey hfsPlus
;
145 typedef union ExtentKey ExtentKey
;
146 /* Universal extent descriptor */
148 union ExtentDescriptor
{
149 HFSExtentDescriptor hfs
;
150 HFSPlusExtentDescriptor hfsPlus
;
152 typedef union ExtentDescriptor ExtentDescriptor
;
153 /* Universal extent record */
157 HFSPlusExtentRecord hfsPlus
;
159 typedef union ExtentRecord ExtentRecord
;
163 CMMaxCName
= kHFSMaxFileNameChars
168 /* Universal catalog name*/
174 typedef union CatalogName CatalogName
;
178 * MacOS accessor routines
180 #define GetFileControlBlock(fref) VTOF((fref))
181 #define GetFileRefNumFromFCB(fcb) FTOV((fcb))
184 /* The following macro marks a VCB as dirty by setting the upper 8 bits of the flags*/
186 MarkVCBDirty (ExtendedVCB
*vcb
);
189 MarkVCBClean (ExtendedVCB
*vcb
);
191 EXTERN_API_C( Boolean
)
192 IsVCBDirty (ExtendedVCB
*vcb
);
195 #define MarkVCBDirty(vcb) { ((vcb)->vcbFlags |= 0xFF00); }
196 #define MarkVCBClean(vcb) { ((vcb)->vcbFlags &= 0x00FF); }
197 #define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
200 /* Test for error and return if error occurred*/
202 ReturnIfError (OSErr result
);
204 #define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
206 /* Exit function on error*/
208 ExitOnError (OSErr result
);
210 #define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
214 /* Catalog Manager Routines (IPI)*/
216 EXTERN_API_C( OSErr
)
217 ExchangeFileIDs (ExtendedVCB
* volume
,
218 ConstUTF8Param srcName
,
219 ConstUTF8Param destName
,
220 HFSCatalogNodeID srcID
,
221 HFSCatalogNodeID destID
,
226 /* BTree Manager Routines*/
228 typedef CALLBACK_API_C( SInt32
, KeyCompareProcPtr
)(void *a
, void *b
);
231 EXTERN_API_C( OSErr
)
232 SearchBTreeRecord (FileReference refNum
,
240 EXTERN_API_C( OSErr
)
241 ReplaceBTreeRecord (FileReference refNum
,
249 /* Prototypes for exported routines in VolumeAllocation.c*/
250 EXTERN_API_C( OSErr
)
251 BlockAllocate (ExtendedVCB
* vcb
,
252 UInt32 startingBlock
,
255 Boolean forceContiguous
,
258 UInt32
* actualBlocks
);
260 EXTERN_API_C( OSErr
)
261 BlockDeallocate (ExtendedVCB
* vcb
,
265 EXTERN_API_C( OSErr
)
266 BlockMarkAllocated(ExtendedVCB
*vcb
, UInt32 startingBlock
, UInt32 numBlocks
);
268 EXTERN_API_C( OSErr
)
269 BlockMarkFree( ExtendedVCB
*vcb
, UInt32 startingBlock
, UInt32 numBlocks
);
271 EXTERN_API_C( UInt32
)
272 MetaZoneFreeBlocks(ExtendedVCB
*vcb
);
274 /* File Extent Mapping routines*/
275 EXTERN_API_C( OSErr
)
276 FlushExtentFile (ExtendedVCB
* vcb
);
278 EXTERN_API_C( SInt32
)
279 CompareExtentKeys (const HFSExtentKey
* searchKey
,
280 const HFSExtentKey
* trialKey
);
282 EXTERN_API_C( SInt32
)
283 CompareExtentKeysPlus (const HFSPlusExtentKey
*searchKey
,
284 const HFSPlusExtentKey
*trialKey
);
286 EXTERN_API_C( OSErr
)
287 TruncateFileC (ExtendedVCB
* vcb
,
290 Boolean truncateToExtent
);
292 EXTERN_API_C( OSErr
)
293 ExtendFileC (ExtendedVCB
* vcb
,
298 SInt64
* actualBytesAdded
);
300 EXTERN_API_C( OSErr
)
301 MapFileBlockC (ExtendedVCB
* vcb
,
303 size_t numberOfBytes
,
305 daddr64_t
* startBlock
,
306 size_t * availableBytes
);
308 OSErr
HeadTruncateFile(ExtendedVCB
*vcb
, FCB
*fcb
, UInt32 headblks
);
311 AddFileExtent (ExtendedVCB
*vcb
, FCB
*fcb
, UInt32 startBlock
, UInt32 blockCount
);
313 #if TARGET_API_MACOS_X
314 EXTERN_API_C( Boolean
)
315 NodesAreContiguous (ExtendedVCB
* vcb
,
322 /* Get the current time in UTC (GMT)*/
323 EXTERN_API_C( UInt32
)
326 EXTERN_API_C( UInt32
)
327 LocalToUTC (UInt32 localTime
);
329 EXTERN_API_C( UInt32
)
330 UTCToLocal (UInt32 utcTime
);
333 #if PRAGMA_STRUCT_ALIGN
334 #pragma options align=reset
335 #elif PRAGMA_STRUCT_PACKPUSH
337 #elif PRAGMA_STRUCT_PACK
341 #ifdef PRAGMA_IMPORT_OFF
351 #endif /* __APPLE_API_PRIVATE */
353 #endif /* __FILEMGRINTERNAL__ */