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