]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfscommon/headers/FileMgrInternal.h
xnu-344.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
119 kTFTrunExtBit = 0, /* truncate to the extent containing new PEOF*/
120 kTFTrunExtMask = 1
121 };
122
123 enum {
124 kUndefinedStrLen = 0, /* Unknown string length */
125 kNoHint = 0,
126
127 /* FileIDs variables*/
128 kNumExtentsToCache = 4 /* just guessing for ExchangeFiles*/
129 };
130
131
132 /* Universal Extent Key */
133
134 union ExtentKey {
135 HFSExtentKey hfs;
136 HFSPlusExtentKey hfsPlus;
137 };
138 typedef union ExtentKey ExtentKey;
139 /* Universal extent descriptor */
140
141 union ExtentDescriptor {
142 HFSExtentDescriptor hfs;
143 HFSPlusExtentDescriptor hfsPlus;
144 };
145 typedef union ExtentDescriptor ExtentDescriptor;
146 /* Universal extent record */
147
148 union ExtentRecord {
149 HFSExtentRecord hfs;
150 HFSPlusExtentRecord hfsPlus;
151 };
152 typedef union ExtentRecord ExtentRecord;
153 /* Universal catalog key */
154
155 union CatalogKey {
156 HFSCatalogKey hfs;
157 HFSPlusCatalogKey hfsPlus;
158 };
159 typedef union CatalogKey CatalogKey;
160 /* Universal catalog data record */
161
162 union CatalogRecord {
163 SInt16 recordType;
164 HFSCatalogFolder hfsFolder;
165 HFSCatalogFile hfsFile;
166 HFSCatalogThread hfsThread;
167 HFSPlusCatalogFolder hfsPlusFolder;
168 HFSPlusCatalogFile hfsPlusFile;
169 HFSPlusCatalogThread hfsPlusThread;
170 };
171 typedef union CatalogRecord CatalogRecord;
172
173
174 enum {
175 CMMaxCName = kHFSMaxFileNameChars
176 };
177
178
179
180 /* Universal catalog name*/
181
182 union CatalogName {
183 Str31 pstr;
184 HFSUniStr255 ustr;
185 };
186 typedef union CatalogName CatalogName;
187
188
189 /*
190 * MacOS accessor routines
191 */
192 #define GetFileControlBlock(fref) VTOF((fref))
193 #define GetFileRefNumFromFCB(fcb) FTOV((fcb))
194
195
196 /* The following macro marks a VCB as dirty by setting the upper 8 bits of the flags*/
197 EXTERN_API_C( void )
198 MarkVCBDirty (ExtendedVCB *vcb);
199
200 EXTERN_API_C( void )
201 MarkVCBClean (ExtendedVCB *vcb);
202
203 EXTERN_API_C( Boolean )
204 IsVCBDirty (ExtendedVCB *vcb);
205
206
207 #define VCB_LOCK_INIT(vcb) simple_lock_init(&vcb->vcbSimpleLock)
208 #define VCB_LOCK(vcb) simple_lock(&vcb->vcbSimpleLock)
209 #define VCB_UNLOCK(vcb) simple_unlock(&vcb->vcbSimpleLock)
210
211 #define MarkVCBDirty(vcb) { ((vcb)->vcbFlags |= 0xFF00); }
212 #define MarkVCBClean(vcb) { ((vcb)->vcbFlags &= 0x00FF); }
213 #define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
214
215
216 /* Test for error and return if error occurred*/
217 EXTERN_API_C( void )
218 ReturnIfError (OSErr result);
219
220 #define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
221 /* Test for passed condition and return if true*/
222 EXTERN_API_C( void )
223 ReturnErrorIf (Boolean condition,
224 OSErr result);
225
226 #define ReturnErrorIf(condition, error) if ( (condition) ) return( (error) );
227 /* Exit function on error*/
228 EXTERN_API_C( void )
229 ExitOnError (OSErr result);
230
231 #define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
232
233
234
235 /* Catalog Manager Routines (IPI)*/
236
237 EXTERN_API_C( OSErr )
238 ExchangeFileIDs (ExtendedVCB * volume,
239 ConstUTF8Param srcName,
240 ConstUTF8Param destName,
241 HFSCatalogNodeID srcID,
242 HFSCatalogNodeID destID,
243 UInt32 srcHint,
244 UInt32 destHint );
245
246 EXTERN_API_C( SInt32 )
247 CompareCatalogKeys (HFSCatalogKey * searchKey,
248 HFSCatalogKey * trialKey);
249
250 EXTERN_API_C( SInt32 )
251 CompareExtendedCatalogKeys (HFSPlusCatalogKey * searchKey,
252 HFSPlusCatalogKey * trialKey);
253
254 EXTERN_API_C( OSErr )
255 InitCatalogCache (void);
256
257 EXTERN_API_C( void )
258 InvalidateCatalogCache (ExtendedVCB * volume);
259
260
261
262 /* BTree Manager Routines*/
263
264 typedef CALLBACK_API_C( SInt32 , KeyCompareProcPtr )(void *a, void *b);
265
266
267 EXTERN_API_C( OSErr )
268 SearchBTreeRecord (FileReference refNum,
269 const void * key,
270 UInt32 hint,
271 void * foundKey,
272 void * data,
273 UInt16 * dataSize,
274 UInt32 * newHint);
275
276 EXTERN_API_C( OSErr )
277 ReplaceBTreeRecord (FileReference refNum,
278 const void * key,
279 UInt32 hint,
280 void * newData,
281 UInt16 dataSize,
282 UInt32 * newHint);
283
284
285 /* Prototypes for exported routines in VolumeAllocation.c*/
286 EXTERN_API_C( OSErr )
287 BlockAllocate (ExtendedVCB * vcb,
288 UInt32 startingBlock,
289 SInt64 bytesRequested,
290 SInt64 bytesMaximum,
291 Boolean forceContiguous,
292 UInt32 * startBlock,
293 UInt32 * actualBlocks);
294
295 EXTERN_API_C( OSErr )
296 BlockDeallocate (ExtendedVCB * vcb,
297 UInt32 firstBlock,
298 UInt32 numBlocks);
299
300 EXTERN_API_C( UInt32 )
301 FileBytesToBlocks (SInt64 numerator,
302 UInt32 denominator);
303
304 /* File Extent Mapping routines*/
305 EXTERN_API_C( OSErr )
306 FlushExtentFile (ExtendedVCB * vcb);
307
308 EXTERN_API_C( SInt32 )
309 CompareExtentKeys (const HFSExtentKey * searchKey,
310 const HFSExtentKey * trialKey);
311
312 EXTERN_API_C( SInt32 )
313 CompareExtentKeysPlus (const HFSPlusExtentKey *searchKey,
314 const HFSPlusExtentKey *trialKey);
315
316 EXTERN_API_C( OSErr )
317 TruncateFileC (ExtendedVCB * vcb,
318 FCB * fcb,
319 SInt64 peof,
320 Boolean truncateToExtent);
321
322 EXTERN_API_C( OSErr )
323 ExtendFileC (ExtendedVCB * vcb,
324 FCB * fcb,
325 SInt64 bytesToAdd,
326 UInt32 blockHint,
327 UInt32 flags,
328 SInt64 * actualBytesAdded);
329
330 EXTERN_API_C( OSErr )
331 MapFileBlockC (ExtendedVCB * vcb,
332 FCB * fcb,
333 size_t numberOfBytes,
334 off_t offset,
335 daddr_t * startBlock,
336 size_t * availableBytes);
337
338 #if TARGET_API_MACOS_X
339 EXTERN_API_C( Boolean )
340 NodesAreContiguous (ExtendedVCB * vcb,
341 FCB * fcb,
342 UInt32 nodeSize);
343 #endif
344
345 /* Utility routines*/
346
347 EXTERN_API_C( OSErr )
348 VolumeWritable (ExtendedVCB * vcb);
349
350
351 /* Get the current time in UTC (GMT)*/
352 EXTERN_API_C( UInt32 )
353 GetTimeUTC (void);
354
355 EXTERN_API_C( UInt32 )
356 LocalToUTC (UInt32 localTime);
357
358 EXTERN_API_C( UInt32 )
359 UTCToLocal (UInt32 utcTime);
360
361
362 #if PRAGMA_STRUCT_ALIGN
363 #pragma options align=reset
364 #elif PRAGMA_STRUCT_PACKPUSH
365 #pragma pack(pop)
366 #elif PRAGMA_STRUCT_PACK
367 #pragma pack()
368 #endif
369
370 #ifdef PRAGMA_IMPORT_OFF
371 #pragma import off
372 #elif PRAGMA_IMPORT
373 #pragma import reset
374 #endif
375
376 #ifdef __cplusplus
377 }
378 #endif
379
380 #endif /* __APPLE_API_PRIVATE */
381 #endif /* KERNEL */
382 #endif /* __FILEMGRINTERNAL__ */
383