]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfscommon/headers/FileMgrInternal.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / bsd / hfs / hfscommon / headers / FileMgrInternal.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 File: FilesInternal.h
25
26 Contains: IPI for File Manager (HFS Plus)
27
28 Version: HFS Plus 1.0
29
30 Copyright: © 1996-2001 by Apple Computer, Inc., all rights reserved.
31
32 */
33 #ifndef __FILEMGRINTERNAL__
34 #define __FILEMGRINTERNAL__
35
36 #include <sys/appleapiopts.h>
37
38 #ifdef KERNEL
39 #ifdef __APPLE_API_PRIVATE
40
41 #include <sys/param.h>
42 #include <sys/vnode.h>
43
44 #include "../../hfs.h"
45 #include "../../hfs_macos_defs.h"
46 #include "../../hfs_format.h"
47 #include "../../hfs_cnode.h"
48
49
50 #if PRAGMA_ONCE
51 #pragma once
52 #endif
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 #if PRAGMA_IMPORT
59 #pragma import on
60 #endif
61
62 #if PRAGMA_STRUCT_ALIGN
63 #pragma options align=mac68k
64 #elif PRAGMA_STRUCT_PACKPUSH
65 #pragma pack(push, 2)
66 #elif PRAGMA_STRUCT_PACK
67 #pragma pack(2)
68 #endif
69
70 /* CatalogNodeID is used to track catalog objects */
71 typedef UInt32 HFSCatalogNodeID;
72
73 /* internal error codes*/
74
75 #if TARGET_API_MACOS_X
76 #define ERR_BASE -32767
77 #else
78 #define ERR_BASE 0
79 #endif
80
81 enum {
82 /* FXM errors*/
83 fxRangeErr = ERR_BASE + 16, /* file position beyond mapped range*/
84 fxOvFlErr = ERR_BASE + 17, /* extents file overflow*/
85 /* Unicode errors*/
86 uniTooLongErr = ERR_BASE + 24, /* Unicode string too long to convert to Str31*/
87 uniBufferTooSmallErr = ERR_BASE + 25, /* Unicode output buffer too small*/
88 uniNotMappableErr = ERR_BASE + 26, /* Unicode string can't be mapped to given script*/
89 /* BTree Manager errors*/
90 btNotFound = ERR_BASE + 32, /* record not found*/
91 btExists = ERR_BASE + 33, /* record already exists*/
92 btNoSpaceAvail = ERR_BASE + 34, /* no available space*/
93 btNoFit = ERR_BASE + 35, /* record doesn't fit in node */
94 btBadNode = ERR_BASE + 36, /* bad node detected*/
95 btBadHdr = ERR_BASE + 37, /* bad BTree header record detected*/
96 dsBadRotate = ERR_BASE + 64, /* bad BTree rotate*/
97 /* Catalog Manager errors*/
98 cmNotFound = ERR_BASE + 48, /* CNode not found*/
99 cmExists = ERR_BASE + 49, /* CNode already exists*/
100 cmNotEmpty = ERR_BASE + 50, /* directory CNode not empty (valence = 0)*/
101 cmRootCN = ERR_BASE + 51, /* invalid reference to root CNode*/
102 cmBadNews = ERR_BASE + 52, /* detected bad catalog structure*/
103 cmFThdDirErr = ERR_BASE + 53, /* thread belongs to a directory not a file*/
104 cmFThdGone = ERR_BASE + 54, /* file thread doesn't exist*/
105 cmParentNotFound = ERR_BASE + 55, /* CNode for parent ID does not exist*/
106 /* TFS internal errors*/
107 fsDSIntErr = -127 /* Internal file system error*/
108 };
109
110
111 /* internal flags*/
112
113 enum {
114 kEFAllMask = 0x01, /* allocate all requested bytes or none */
115 kEFContigMask = 0x02, /* force contiguous allocation */
116 kEFReserveMask = 0x04, /* keep block reserve */
117 kEFDeferMask = 0x08, /* defer file block allocations */
118 kEFNoClumpMask = 0x10, /* don't round up to clump size */
119 kEFMetadataMask = 0x20, /* metadata allocation */
120
121 kTFTrunExtBit = 0, /* truncate to the extent containing new PEOF*/
122 kTFTrunExtMask = 1
123 };
124
125 enum {
126 kUndefinedStrLen = 0, /* Unknown string length */
127 kNoHint = 0,
128
129 /* FileIDs variables*/
130 kNumExtentsToCache = 4 /* just guessing for ExchangeFiles*/
131 };
132
133
134 /* Universal Extent Key */
135
136 union ExtentKey {
137 HFSExtentKey hfs;
138 HFSPlusExtentKey hfsPlus;
139 };
140 typedef union ExtentKey ExtentKey;
141 /* Universal extent descriptor */
142
143 union ExtentDescriptor {
144 HFSExtentDescriptor hfs;
145 HFSPlusExtentDescriptor hfsPlus;
146 };
147 typedef union ExtentDescriptor ExtentDescriptor;
148 /* Universal extent record */
149
150 union ExtentRecord {
151 HFSExtentRecord hfs;
152 HFSPlusExtentRecord hfsPlus;
153 };
154 typedef union ExtentRecord ExtentRecord;
155
156
157 enum {
158 CMMaxCName = kHFSMaxFileNameChars
159 };
160
161
162
163 /* Universal catalog name*/
164
165 union CatalogName {
166 Str31 pstr;
167 HFSUniStr255 ustr;
168 };
169 typedef union CatalogName CatalogName;
170
171
172 /*
173 * MacOS accessor routines
174 */
175 #define GetFileControlBlock(fref) VTOF((fref))
176 #define GetFileRefNumFromFCB(fcb) FTOV((fcb))
177
178
179 /* The following macro marks a VCB as dirty by setting the upper 8 bits of the flags*/
180 EXTERN_API_C( void )
181 MarkVCBDirty (ExtendedVCB *vcb);
182
183 EXTERN_API_C( void )
184 MarkVCBClean (ExtendedVCB *vcb);
185
186 EXTERN_API_C( Boolean )
187 IsVCBDirty (ExtendedVCB *vcb);
188
189
190 #define MarkVCBDirty(vcb) { ((vcb)->vcbFlags |= 0xFF00); }
191 #define MarkVCBClean(vcb) { ((vcb)->vcbFlags &= 0x00FF); }
192 #define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
193
194
195 /* Test for error and return if error occurred*/
196 EXTERN_API_C( void )
197 ReturnIfError (OSErr result);
198
199 #define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
200
201 /* Exit function on error*/
202 EXTERN_API_C( void )
203 ExitOnError (OSErr result);
204
205 #define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
206
207
208
209 /* Catalog Manager Routines (IPI)*/
210
211 EXTERN_API_C( OSErr )
212 ExchangeFileIDs (ExtendedVCB * volume,
213 ConstUTF8Param srcName,
214 ConstUTF8Param destName,
215 HFSCatalogNodeID srcID,
216 HFSCatalogNodeID destID,
217 UInt32 srcHint,
218 UInt32 destHint );
219
220
221 /* BTree Manager Routines*/
222
223 typedef CALLBACK_API_C( SInt32 , KeyCompareProcPtr )(void *a, void *b);
224
225
226 EXTERN_API_C( OSErr )
227 SearchBTreeRecord (FileReference refNum,
228 const void * key,
229 UInt32 hint,
230 void * foundKey,
231 void * data,
232 UInt16 * dataSize,
233 UInt32 * newHint);
234
235 EXTERN_API_C( OSErr )
236 ReplaceBTreeRecord (FileReference refNum,
237 const void * key,
238 UInt32 hint,
239 void * newData,
240 UInt16 dataSize,
241 UInt32 * newHint);
242
243
244 /* Prototypes for exported routines in VolumeAllocation.c*/
245 EXTERN_API_C( OSErr )
246 BlockAllocate (ExtendedVCB * vcb,
247 UInt32 startingBlock,
248 UInt32 minBlocks,
249 UInt32 maxBlocks,
250 Boolean forceContiguous,
251 Boolean useMetaZone,
252 UInt32 * startBlock,
253 UInt32 * actualBlocks);
254
255 EXTERN_API_C( OSErr )
256 BlockDeallocate (ExtendedVCB * vcb,
257 UInt32 firstBlock,
258 UInt32 numBlocks);
259
260 EXTERN_API_C( OSErr )
261 BlockMarkAllocated(ExtendedVCB *vcb, UInt32 startingBlock, UInt32 numBlocks);
262
263 EXTERN_API_C( OSErr )
264 BlockMarkFree( ExtendedVCB *vcb, UInt32 startingBlock, UInt32 numBlocks);
265
266 EXTERN_API_C( UInt32 )
267 MetaZoneFreeBlocks(ExtendedVCB *vcb);
268
269 /* File Extent Mapping routines*/
270 EXTERN_API_C( OSErr )
271 FlushExtentFile (ExtendedVCB * vcb);
272
273 EXTERN_API_C( SInt32 )
274 CompareExtentKeys (const HFSExtentKey * searchKey,
275 const HFSExtentKey * trialKey);
276
277 EXTERN_API_C( SInt32 )
278 CompareExtentKeysPlus (const HFSPlusExtentKey *searchKey,
279 const HFSPlusExtentKey *trialKey);
280
281 EXTERN_API_C( OSErr )
282 TruncateFileC (ExtendedVCB * vcb,
283 FCB * fcb,
284 SInt64 peof,
285 Boolean truncateToExtent);
286
287 EXTERN_API_C( OSErr )
288 ExtendFileC (ExtendedVCB * vcb,
289 FCB * fcb,
290 SInt64 bytesToAdd,
291 UInt32 blockHint,
292 UInt32 flags,
293 SInt64 * actualBytesAdded);
294
295 EXTERN_API_C( OSErr )
296 MapFileBlockC (ExtendedVCB * vcb,
297 FCB * fcb,
298 size_t numberOfBytes,
299 off_t offset,
300 daddr64_t * startBlock,
301 size_t * availableBytes);
302
303 OSErr HeadTruncateFile(ExtendedVCB *vcb, FCB *fcb, UInt32 headblks);
304
305 EXTERN_API_C( int )
306 AddFileExtent (ExtendedVCB *vcb, FCB *fcb, UInt32 startBlock, UInt32 blockCount);
307
308 #if TARGET_API_MACOS_X
309 EXTERN_API_C( Boolean )
310 NodesAreContiguous (ExtendedVCB * vcb,
311 FCB * fcb,
312 UInt32 nodeSize);
313 #endif
314
315
316
317 /* Get the current time in UTC (GMT)*/
318 EXTERN_API_C( UInt32 )
319 GetTimeUTC (void);
320
321 EXTERN_API_C( UInt32 )
322 LocalToUTC (UInt32 localTime);
323
324 EXTERN_API_C( UInt32 )
325 UTCToLocal (UInt32 utcTime);
326
327
328 #if PRAGMA_STRUCT_ALIGN
329 #pragma options align=reset
330 #elif PRAGMA_STRUCT_PACKPUSH
331 #pragma pack(pop)
332 #elif PRAGMA_STRUCT_PACK
333 #pragma pack()
334 #endif
335
336 #ifdef PRAGMA_IMPORT_OFF
337 #pragma import off
338 #elif PRAGMA_IMPORT
339 #pragma import reset
340 #endif
341
342 #ifdef __cplusplus
343 }
344 #endif
345
346 #endif /* __APPLE_API_PRIVATE */
347 #endif /* KERNEL */
348 #endif /* __FILEMGRINTERNAL__ */
349