]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfscommon/headers/FileMgrInternal.h
xnu-792.12.6.tar.gz
[apple/xnu.git] / bsd / hfs / hfscommon / headers / FileMgrInternal.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 File: FilesInternal.h
32
33 Contains: IPI for File Manager (HFS Plus)
34
35 Version: HFS Plus 1.0
36
37 Copyright: © 1996-2001 by Apple Computer, Inc., all rights reserved.
38
39 */
40 #ifndef __FILEMGRINTERNAL__
41 #define __FILEMGRINTERNAL__
42
43 #include <sys/appleapiopts.h>
44
45 #ifdef KERNEL
46 #ifdef __APPLE_API_PRIVATE
47
48 #include <sys/param.h>
49 #include <sys/vnode.h>
50
51 #include "../../hfs.h"
52 #include "../../hfs_macos_defs.h"
53 #include "../../hfs_format.h"
54 #include "../../hfs_cnode.h"
55
56
57 #if PRAGMA_ONCE
58 #pragma once
59 #endif
60
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64
65 #if PRAGMA_IMPORT
66 #pragma import on
67 #endif
68
69 #if PRAGMA_STRUCT_ALIGN
70 #pragma options align=mac68k
71 #elif PRAGMA_STRUCT_PACKPUSH
72 #pragma pack(push, 2)
73 #elif PRAGMA_STRUCT_PACK
74 #pragma pack(2)
75 #endif
76
77 /* CatalogNodeID is used to track catalog objects */
78 typedef UInt32 HFSCatalogNodeID;
79
80 /* internal error codes*/
81
82 #if TARGET_API_MACOS_X
83 #define ERR_BASE -32767
84 #else
85 #define ERR_BASE 0
86 #endif
87
88 enum {
89 /* FXM errors*/
90 fxRangeErr = ERR_BASE + 16, /* file position beyond mapped range*/
91 fxOvFlErr = ERR_BASE + 17, /* extents file overflow*/
92 /* Unicode errors*/
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*/
115 };
116
117
118 /* internal flags*/
119
120 enum {
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 */
127
128 kTFTrunExtBit = 0, /* truncate to the extent containing new PEOF*/
129 kTFTrunExtMask = 1
130 };
131
132 enum {
133 kUndefinedStrLen = 0, /* Unknown string length */
134 kNoHint = 0,
135
136 /* FileIDs variables*/
137 kNumExtentsToCache = 4 /* just guessing for ExchangeFiles*/
138 };
139
140
141 /* Universal Extent Key */
142
143 union ExtentKey {
144 HFSExtentKey hfs;
145 HFSPlusExtentKey hfsPlus;
146 };
147 typedef union ExtentKey ExtentKey;
148 /* Universal extent descriptor */
149
150 union ExtentDescriptor {
151 HFSExtentDescriptor hfs;
152 HFSPlusExtentDescriptor hfsPlus;
153 };
154 typedef union ExtentDescriptor ExtentDescriptor;
155 /* Universal extent record */
156
157 union ExtentRecord {
158 HFSExtentRecord hfs;
159 HFSPlusExtentRecord hfsPlus;
160 };
161 typedef union ExtentRecord ExtentRecord;
162
163
164 enum {
165 CMMaxCName = kHFSMaxFileNameChars
166 };
167
168
169
170 /* Universal catalog name*/
171
172 union CatalogName {
173 Str31 pstr;
174 HFSUniStr255 ustr;
175 };
176 typedef union CatalogName CatalogName;
177
178
179 /*
180 * MacOS accessor routines
181 */
182 #define GetFileControlBlock(fref) VTOF((fref))
183 #define GetFileRefNumFromFCB(fcb) FTOV((fcb))
184
185
186 /* The following macro marks a VCB as dirty by setting the upper 8 bits of the flags*/
187 EXTERN_API_C( void )
188 MarkVCBDirty (ExtendedVCB *vcb);
189
190 EXTERN_API_C( void )
191 MarkVCBClean (ExtendedVCB *vcb);
192
193 EXTERN_API_C( Boolean )
194 IsVCBDirty (ExtendedVCB *vcb);
195
196
197 #define MarkVCBDirty(vcb) { ((vcb)->vcbFlags |= 0xFF00); }
198 #define MarkVCBClean(vcb) { ((vcb)->vcbFlags &= 0x00FF); }
199 #define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
200
201
202 /* Test for error and return if error occurred*/
203 EXTERN_API_C( void )
204 ReturnIfError (OSErr result);
205
206 #define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
207
208 /* Exit function on error*/
209 EXTERN_API_C( void )
210 ExitOnError (OSErr result);
211
212 #define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
213
214
215
216 /* Catalog Manager Routines (IPI)*/
217
218 EXTERN_API_C( OSErr )
219 ExchangeFileIDs (ExtendedVCB * volume,
220 ConstUTF8Param srcName,
221 ConstUTF8Param destName,
222 HFSCatalogNodeID srcID,
223 HFSCatalogNodeID destID,
224 UInt32 srcHint,
225 UInt32 destHint );
226
227
228 /* BTree Manager Routines*/
229
230 typedef CALLBACK_API_C( SInt32 , KeyCompareProcPtr )(void *a, void *b);
231
232
233 EXTERN_API_C( OSErr )
234 SearchBTreeRecord (FileReference refNum,
235 const void * key,
236 UInt32 hint,
237 void * foundKey,
238 void * data,
239 UInt16 * dataSize,
240 UInt32 * newHint);
241
242 EXTERN_API_C( OSErr )
243 ReplaceBTreeRecord (FileReference refNum,
244 const void * key,
245 UInt32 hint,
246 void * newData,
247 UInt16 dataSize,
248 UInt32 * newHint);
249
250
251 /* Prototypes for exported routines in VolumeAllocation.c*/
252 EXTERN_API_C( OSErr )
253 BlockAllocate (ExtendedVCB * vcb,
254 UInt32 startingBlock,
255 UInt32 minBlocks,
256 UInt32 maxBlocks,
257 Boolean forceContiguous,
258 Boolean useMetaZone,
259 UInt32 * startBlock,
260 UInt32 * actualBlocks);
261
262 EXTERN_API_C( OSErr )
263 BlockDeallocate (ExtendedVCB * vcb,
264 UInt32 firstBlock,
265 UInt32 numBlocks);
266
267 EXTERN_API_C( OSErr )
268 BlockMarkAllocated(ExtendedVCB *vcb, UInt32 startingBlock, UInt32 numBlocks);
269
270 EXTERN_API_C( OSErr )
271 BlockMarkFree( ExtendedVCB *vcb, UInt32 startingBlock, UInt32 numBlocks);
272
273 EXTERN_API_C( UInt32 )
274 MetaZoneFreeBlocks(ExtendedVCB *vcb);
275
276 /* File Extent Mapping routines*/
277 EXTERN_API_C( OSErr )
278 FlushExtentFile (ExtendedVCB * vcb);
279
280 EXTERN_API_C( SInt32 )
281 CompareExtentKeys (const HFSExtentKey * searchKey,
282 const HFSExtentKey * trialKey);
283
284 EXTERN_API_C( SInt32 )
285 CompareExtentKeysPlus (const HFSPlusExtentKey *searchKey,
286 const HFSPlusExtentKey *trialKey);
287
288 EXTERN_API_C( OSErr )
289 TruncateFileC (ExtendedVCB * vcb,
290 FCB * fcb,
291 SInt64 peof,
292 Boolean truncateToExtent);
293
294 EXTERN_API_C( OSErr )
295 ExtendFileC (ExtendedVCB * vcb,
296 FCB * fcb,
297 SInt64 bytesToAdd,
298 UInt32 blockHint,
299 UInt32 flags,
300 SInt64 * actualBytesAdded);
301
302 EXTERN_API_C( OSErr )
303 MapFileBlockC (ExtendedVCB * vcb,
304 FCB * fcb,
305 size_t numberOfBytes,
306 off_t offset,
307 daddr64_t * startBlock,
308 size_t * availableBytes);
309
310 OSErr HeadTruncateFile(ExtendedVCB *vcb, FCB *fcb, UInt32 headblks);
311
312 EXTERN_API_C( int )
313 AddFileExtent (ExtendedVCB *vcb, FCB *fcb, UInt32 startBlock, UInt32 blockCount);
314
315 #if TARGET_API_MACOS_X
316 EXTERN_API_C( Boolean )
317 NodesAreContiguous (ExtendedVCB * vcb,
318 FCB * fcb,
319 UInt32 nodeSize);
320 #endif
321
322
323
324 /* Get the current time in UTC (GMT)*/
325 EXTERN_API_C( UInt32 )
326 GetTimeUTC (void);
327
328 EXTERN_API_C( UInt32 )
329 LocalToUTC (UInt32 localTime);
330
331 EXTERN_API_C( UInt32 )
332 UTCToLocal (UInt32 utcTime);
333
334
335 #if PRAGMA_STRUCT_ALIGN
336 #pragma options align=reset
337 #elif PRAGMA_STRUCT_PACKPUSH
338 #pragma pack(pop)
339 #elif PRAGMA_STRUCT_PACK
340 #pragma pack()
341 #endif
342
343 #ifdef PRAGMA_IMPORT_OFF
344 #pragma import off
345 #elif PRAGMA_IMPORT
346 #pragma import reset
347 #endif
348
349 #ifdef __cplusplus
350 }
351 #endif
352
353 #endif /* __APPLE_API_PRIVATE */
354 #endif /* KERNEL */
355 #endif /* __FILEMGRINTERNAL__ */
356