2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 Contains: IPI for File Manager (HFS Plus)
29 Copyright: © 1996-2001 by Apple Computer, Inc., all rights reserved.
32 #ifndef __FILEMGRINTERNAL__
33 #define __FILEMGRINTERNAL__
35 #include <sys/appleapiopts.h>
38 #ifdef __APPLE_API_PRIVATE
40 #include <sys/param.h>
41 #include <sys/vnode.h>
43 #include "../../hfs.h"
44 #include "../../hfs_macos_defs.h"
45 #include "../../hfs_format.h"
46 #include "../../hfs_cnode.h"
61 #if PRAGMA_STRUCT_ALIGN
62 #pragma options align=mac68k
63 #elif PRAGMA_STRUCT_PACKPUSH
65 #elif PRAGMA_STRUCT_PACK
69 /* CatalogNodeID is used to track catalog objects */
70 typedef UInt32 HFSCatalogNodeID
;
72 /* internal error codes*/
74 #if TARGET_API_MACOS_X
75 #define ERR_BASE -32767
82 fxRangeErr
= ERR_BASE
+ 16, /* file position beyond mapped range*/
83 fxOvFlErr
= ERR_BASE
+ 17, /* extents file overflow*/
85 uniTooLongErr
= ERR_BASE
+ 24, /* Unicode string too long to convert to Str31*/
86 uniBufferTooSmallErr
= ERR_BASE
+ 25, /* Unicode output buffer too small*/
87 uniNotMappableErr
= ERR_BASE
+ 26, /* Unicode string can't be mapped to given script*/
88 /* BTree Manager errors*/
89 btNotFound
= ERR_BASE
+ 32, /* record not found*/
90 btExists
= ERR_BASE
+ 33, /* record already exists*/
91 btNoSpaceAvail
= ERR_BASE
+ 34, /* no available space*/
92 btNoFit
= ERR_BASE
+ 35, /* record doesn't fit in node */
93 btBadNode
= ERR_BASE
+ 36, /* bad node detected*/
94 btBadHdr
= ERR_BASE
+ 37, /* bad BTree header record detected*/
95 dsBadRotate
= ERR_BASE
+ 64, /* bad BTree rotate*/
96 /* Catalog Manager errors*/
97 cmNotFound
= ERR_BASE
+ 48, /* CNode not found*/
98 cmExists
= ERR_BASE
+ 49, /* CNode already exists*/
99 cmNotEmpty
= ERR_BASE
+ 50, /* directory CNode not empty (valence = 0)*/
100 cmRootCN
= ERR_BASE
+ 51, /* invalid reference to root CNode*/
101 cmBadNews
= ERR_BASE
+ 52, /* detected bad catalog structure*/
102 cmFThdDirErr
= ERR_BASE
+ 53, /* thread belongs to a directory not a file*/
103 cmFThdGone
= ERR_BASE
+ 54, /* file thread doesn't exist*/
104 cmParentNotFound
= ERR_BASE
+ 55, /* CNode for parent ID does not exist*/
105 /* TFS internal errors*/
106 fsDSIntErr
= -127 /* Internal file system error*/
113 kEFAllMask
= 0x01, /* allocate all requested bytes or none */
114 kEFContigMask
= 0x02, /* force contiguous allocation */
115 kEFReserveMask
= 0x04, /* keep block reserve */
116 kEFDeferMask
= 0x08, /* defer file block allocations */
117 kEFNoClumpMask
= 0x10, /* don't round up to clump size */
118 kEFMetadataMask
= 0x20, /* metadata allocation */
120 kTFTrunExtBit
= 0, /* truncate to the extent containing new PEOF*/
125 kUndefinedStrLen
= 0, /* Unknown string length */
128 /* FileIDs variables*/
129 kNumExtentsToCache
= 4 /* just guessing for ExchangeFiles*/
133 /* Universal Extent Key */
137 HFSPlusExtentKey hfsPlus
;
139 typedef union ExtentKey ExtentKey
;
140 /* Universal extent descriptor */
142 union ExtentDescriptor
{
143 HFSExtentDescriptor hfs
;
144 HFSPlusExtentDescriptor hfsPlus
;
146 typedef union ExtentDescriptor ExtentDescriptor
;
147 /* Universal extent record */
151 HFSPlusExtentRecord hfsPlus
;
153 typedef union ExtentRecord ExtentRecord
;
157 CMMaxCName
= kHFSMaxFileNameChars
162 /* Universal catalog name*/
168 typedef union CatalogName CatalogName
;
172 * MacOS accessor routines
174 #define GetFileControlBlock(fref) VTOF((fref))
175 #define GetFileRefNumFromFCB(fcb) FTOV((fcb))
178 /* The following macro marks a VCB as dirty by setting the upper 8 bits of the flags*/
180 MarkVCBDirty (ExtendedVCB
*vcb
);
183 MarkVCBClean (ExtendedVCB
*vcb
);
185 EXTERN_API_C( Boolean
)
186 IsVCBDirty (ExtendedVCB
*vcb
);
189 #define MarkVCBDirty(vcb) { ((vcb)->vcbFlags |= 0xFF00); }
190 #define MarkVCBClean(vcb) { ((vcb)->vcbFlags &= 0x00FF); }
191 #define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
194 /* Test for error and return if error occurred*/
196 ReturnIfError (OSErr result
);
198 #define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
200 /* Exit function on error*/
202 ExitOnError (OSErr result
);
204 #define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
208 /* Catalog Manager Routines (IPI)*/
210 EXTERN_API_C( OSErr
)
211 ExchangeFileIDs (ExtendedVCB
* volume
,
212 ConstUTF8Param srcName
,
213 ConstUTF8Param destName
,
214 HFSCatalogNodeID srcID
,
215 HFSCatalogNodeID destID
,
220 /* BTree Manager Routines*/
222 typedef CALLBACK_API_C( SInt32
, KeyCompareProcPtr
)(void *a
, void *b
);
225 EXTERN_API_C( OSErr
)
226 SearchBTreeRecord (FileReference refNum
,
234 EXTERN_API_C( OSErr
)
235 ReplaceBTreeRecord (FileReference refNum
,
243 /* Prototypes for exported routines in VolumeAllocation.c*/
244 EXTERN_API_C( OSErr
)
245 BlockAllocate (ExtendedVCB
* vcb
,
246 UInt32 startingBlock
,
249 Boolean forceContiguous
,
252 UInt32
* actualBlocks
);
254 EXTERN_API_C( OSErr
)
255 BlockDeallocate (ExtendedVCB
* vcb
,
259 EXTERN_API_C( OSErr
)
260 BlockMarkAllocated(ExtendedVCB
*vcb
, UInt32 startingBlock
, UInt32 numBlocks
);
262 EXTERN_API_C( OSErr
)
263 BlockMarkFree( ExtendedVCB
*vcb
, UInt32 startingBlock
, UInt32 numBlocks
);
265 EXTERN_API_C( UInt32
)
266 MetaZoneFreeBlocks(ExtendedVCB
*vcb
);
268 /* File Extent Mapping routines*/
269 EXTERN_API_C( OSErr
)
270 FlushExtentFile (ExtendedVCB
* vcb
);
272 EXTERN_API_C( SInt32
)
273 CompareExtentKeys (const HFSExtentKey
* searchKey
,
274 const HFSExtentKey
* trialKey
);
276 EXTERN_API_C( SInt32
)
277 CompareExtentKeysPlus (const HFSPlusExtentKey
*searchKey
,
278 const HFSPlusExtentKey
*trialKey
);
280 EXTERN_API_C( OSErr
)
281 TruncateFileC (ExtendedVCB
* vcb
,
284 Boolean truncateToExtent
);
286 EXTERN_API_C( OSErr
)
287 ExtendFileC (ExtendedVCB
* vcb
,
292 SInt64
* actualBytesAdded
);
294 EXTERN_API_C( OSErr
)
295 MapFileBlockC (ExtendedVCB
* vcb
,
297 size_t numberOfBytes
,
299 daddr64_t
* startBlock
,
300 size_t * availableBytes
);
302 OSErr
HeadTruncateFile(ExtendedVCB
*vcb
, FCB
*fcb
, UInt32 headblks
);
305 AddFileExtent (ExtendedVCB
*vcb
, FCB
*fcb
, UInt32 startBlock
, UInt32 blockCount
);
307 #if TARGET_API_MACOS_X
308 EXTERN_API_C( Boolean
)
309 NodesAreContiguous (ExtendedVCB
* vcb
,
316 /* Get the current time in UTC (GMT)*/
317 EXTERN_API_C( UInt32
)
320 EXTERN_API_C( UInt32
)
321 LocalToUTC (UInt32 localTime
);
323 EXTERN_API_C( UInt32
)
324 UTCToLocal (UInt32 utcTime
);
327 #if PRAGMA_STRUCT_ALIGN
328 #pragma options align=reset
329 #elif PRAGMA_STRUCT_PACKPUSH
331 #elif PRAGMA_STRUCT_PACK
335 #ifdef PRAGMA_IMPORT_OFF
345 #endif /* __APPLE_API_PRIVATE */
347 #endif /* __FILEMGRINTERNAL__ */