2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 Contains: IPI for File Manager (HFS Plus)
32 Copyright: © 1996-2001 by Apple Computer, Inc., all rights reserved.
35 #ifndef __FILEMGRINTERNAL__
36 #define __FILEMGRINTERNAL__
38 #include <sys/appleapiopts.h>
41 #ifdef __APPLE_API_PRIVATE
43 #include <sys/param.h>
44 #include <sys/vnode.h>
46 #include "../../hfs.h"
47 #include "../../hfs_macos_defs.h"
48 #include "../../hfs_format.h"
49 #include "../../hfs_cnode.h"
64 #if PRAGMA_STRUCT_ALIGN
65 #pragma options align=mac68k
66 #elif PRAGMA_STRUCT_PACKPUSH
68 #elif PRAGMA_STRUCT_PACK
72 /* CatalogNodeID is used to track catalog objects */
73 typedef UInt32 HFSCatalogNodeID
;
75 /* internal error codes*/
77 #if TARGET_API_MACOS_X
78 #define ERR_BASE -32767
85 fxRangeErr
= ERR_BASE
+ 16, /* file position beyond mapped range*/
86 fxOvFlErr
= ERR_BASE
+ 17, /* extents file overflow*/
88 uniTooLongErr
= ERR_BASE
+ 24, /* Unicode string too long to convert to Str31*/
89 uniBufferTooSmallErr
= ERR_BASE
+ 25, /* Unicode output buffer too small*/
90 uniNotMappableErr
= ERR_BASE
+ 26, /* Unicode string can't be mapped to given script*/
91 /* BTree Manager errors*/
92 btNotFound
= ERR_BASE
+ 32, /* record not found*/
93 btExists
= ERR_BASE
+ 33, /* record already exists*/
94 btNoSpaceAvail
= ERR_BASE
+ 34, /* no available space*/
95 btNoFit
= ERR_BASE
+ 35, /* record doesn't fit in node */
96 btBadNode
= ERR_BASE
+ 36, /* bad node detected*/
97 btBadHdr
= ERR_BASE
+ 37, /* bad BTree header record detected*/
98 dsBadRotate
= ERR_BASE
+ 64, /* bad BTree rotate*/
99 /* Catalog Manager errors*/
100 cmNotFound
= ERR_BASE
+ 48, /* CNode not found*/
101 cmExists
= ERR_BASE
+ 49, /* CNode already exists*/
102 cmNotEmpty
= ERR_BASE
+ 50, /* directory CNode not empty (valence = 0)*/
103 cmRootCN
= ERR_BASE
+ 51, /* invalid reference to root CNode*/
104 cmBadNews
= ERR_BASE
+ 52, /* detected bad catalog structure*/
105 cmFThdDirErr
= ERR_BASE
+ 53, /* thread belongs to a directory not a file*/
106 cmFThdGone
= ERR_BASE
+ 54, /* file thread doesn't exist*/
107 cmParentNotFound
= ERR_BASE
+ 55, /* CNode for parent ID does not exist*/
108 /* TFS internal errors*/
109 fsDSIntErr
= -127 /* Internal file system error*/
116 kEFAllMask
= 0x01, /* allocate all requested bytes or none */
117 kEFContigMask
= 0x02, /* force contiguous allocation */
118 kEFReserveMask
= 0x04, /* keep block reserve */
119 kEFDeferMask
= 0x08, /* defer file block allocations */
120 kEFNoClumpMask
= 0x10, /* don't round up to clump size */
122 kTFTrunExtBit
= 0, /* truncate to the extent containing new PEOF*/
127 kUndefinedStrLen
= 0, /* Unknown string length */
130 /* FileIDs variables*/
131 kNumExtentsToCache
= 4 /* just guessing for ExchangeFiles*/
135 /* Universal Extent Key */
139 HFSPlusExtentKey hfsPlus
;
141 typedef union ExtentKey ExtentKey
;
142 /* Universal extent descriptor */
144 union ExtentDescriptor
{
145 HFSExtentDescriptor hfs
;
146 HFSPlusExtentDescriptor hfsPlus
;
148 typedef union ExtentDescriptor ExtentDescriptor
;
149 /* Universal extent record */
153 HFSPlusExtentRecord hfsPlus
;
155 typedef union ExtentRecord ExtentRecord
;
156 /* Universal catalog key */
160 HFSPlusCatalogKey hfsPlus
;
162 typedef union CatalogKey CatalogKey
;
163 /* Universal catalog data record */
165 union CatalogRecord
{
167 HFSCatalogFolder hfsFolder
;
168 HFSCatalogFile hfsFile
;
169 HFSCatalogThread hfsThread
;
170 HFSPlusCatalogFolder hfsPlusFolder
;
171 HFSPlusCatalogFile hfsPlusFile
;
172 HFSPlusCatalogThread hfsPlusThread
;
174 typedef union CatalogRecord CatalogRecord
;
178 CMMaxCName
= kHFSMaxFileNameChars
183 /* Universal catalog name*/
189 typedef union CatalogName CatalogName
;
193 * MacOS accessor routines
195 #define GetFileControlBlock(fref) VTOF((fref))
196 #define GetFileRefNumFromFCB(fcb) FTOV((fcb))
199 /* The following macro marks a VCB as dirty by setting the upper 8 bits of the flags*/
201 MarkVCBDirty (ExtendedVCB
*vcb
);
204 MarkVCBClean (ExtendedVCB
*vcb
);
206 EXTERN_API_C( Boolean
)
207 IsVCBDirty (ExtendedVCB
*vcb
);
210 #define VCB_LOCK_INIT(vcb) simple_lock_init(&vcb->vcbSimpleLock)
211 #define VCB_LOCK(vcb) simple_lock(&vcb->vcbSimpleLock)
212 #define VCB_UNLOCK(vcb) simple_unlock(&vcb->vcbSimpleLock)
214 #define MarkVCBDirty(vcb) { ((vcb)->vcbFlags |= 0xFF00); }
215 #define MarkVCBClean(vcb) { ((vcb)->vcbFlags &= 0x00FF); }
216 #define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
219 /* Test for error and return if error occurred*/
221 ReturnIfError (OSErr result
);
223 #define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
224 /* Test for passed condition and return if true*/
226 ReturnErrorIf (Boolean condition
,
229 #define ReturnErrorIf(condition, error) if ( (condition) ) return( (error) );
230 /* Exit function on error*/
232 ExitOnError (OSErr result
);
234 #define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
238 /* Catalog Manager Routines (IPI)*/
240 EXTERN_API_C( OSErr
)
241 ExchangeFileIDs (ExtendedVCB
* volume
,
242 ConstUTF8Param srcName
,
243 ConstUTF8Param destName
,
244 HFSCatalogNodeID srcID
,
245 HFSCatalogNodeID destID
,
249 EXTERN_API_C( SInt32
)
250 CompareCatalogKeys (HFSCatalogKey
* searchKey
,
251 HFSCatalogKey
* trialKey
);
253 EXTERN_API_C( SInt32
)
254 CompareExtendedCatalogKeys (HFSPlusCatalogKey
* searchKey
,
255 HFSPlusCatalogKey
* trialKey
);
257 EXTERN_API_C( OSErr
)
258 InitCatalogCache (void);
261 InvalidateCatalogCache (ExtendedVCB
* volume
);
265 /* BTree Manager Routines*/
267 typedef CALLBACK_API_C( SInt32
, KeyCompareProcPtr
)(void *a
, void *b
);
270 EXTERN_API_C( OSErr
)
271 SearchBTreeRecord (FileReference refNum
,
279 EXTERN_API_C( OSErr
)
280 ReplaceBTreeRecord (FileReference refNum
,
288 /* Prototypes for exported routines in VolumeAllocation.c*/
289 EXTERN_API_C( OSErr
)
290 BlockAllocate (ExtendedVCB
* vcb
,
291 UInt32 startingBlock
,
292 SInt64 bytesRequested
,
294 Boolean forceContiguous
,
296 UInt32
* actualBlocks
);
298 EXTERN_API_C( OSErr
)
299 BlockDeallocate (ExtendedVCB
* vcb
,
303 EXTERN_API_C( UInt32
)
304 FileBytesToBlocks (SInt64 numerator
,
307 /* File Extent Mapping routines*/
308 EXTERN_API_C( OSErr
)
309 FlushExtentFile (ExtendedVCB
* vcb
);
311 EXTERN_API_C( SInt32
)
312 CompareExtentKeys (const HFSExtentKey
* searchKey
,
313 const HFSExtentKey
* trialKey
);
315 EXTERN_API_C( SInt32
)
316 CompareExtentKeysPlus (const HFSPlusExtentKey
*searchKey
,
317 const HFSPlusExtentKey
*trialKey
);
319 EXTERN_API_C( OSErr
)
320 TruncateFileC (ExtendedVCB
* vcb
,
323 Boolean truncateToExtent
);
325 EXTERN_API_C( OSErr
)
326 ExtendFileC (ExtendedVCB
* vcb
,
331 SInt64
* actualBytesAdded
);
333 EXTERN_API_C( OSErr
)
334 MapFileBlockC (ExtendedVCB
* vcb
,
336 size_t numberOfBytes
,
338 daddr_t
* startBlock
,
339 size_t * availableBytes
);
341 #if TARGET_API_MACOS_X
342 EXTERN_API_C( Boolean
)
343 NodesAreContiguous (ExtendedVCB
* vcb
,
348 /* Utility routines*/
350 EXTERN_API_C( OSErr
)
351 VolumeWritable (ExtendedVCB
* vcb
);
354 /* Get the current time in UTC (GMT)*/
355 EXTERN_API_C( UInt32
)
358 EXTERN_API_C( UInt32
)
359 LocalToUTC (UInt32 localTime
);
361 EXTERN_API_C( UInt32
)
362 UTCToLocal (UInt32 utcTime
);
365 #if PRAGMA_STRUCT_ALIGN
366 #pragma options align=reset
367 #elif PRAGMA_STRUCT_PACKPUSH
369 #elif PRAGMA_STRUCT_PACK
373 #ifdef PRAGMA_IMPORT_OFF
383 #endif /* __APPLE_API_PRIVATE */
385 #endif /* __FILEMGRINTERNAL__ */