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