]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfscommon/headers/FileMgrInternal.h
370dca4e9652463bc502a45abf3ee6c4d876e604
[apple/xnu.git] / bsd / hfs / hfscommon / headers / FileMgrInternal.h
1 /*
2 * Copyright (c) 2000-2001 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/param.h>
36 #include <sys/vnode.h>
37
38 #include "../../hfs.h"
39 #include "../../hfs_macos_defs.h"
40 #include "../../hfs_format.h"
41
42
43 #if PRAGMA_ONCE
44 #pragma once
45 #endif
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 #if PRAGMA_IMPORT
52 #pragma import on
53 #endif
54
55 #if PRAGMA_STRUCT_ALIGN
56 #pragma options align=mac68k
57 #elif PRAGMA_STRUCT_PACKPUSH
58 #pragma pack(push, 2)
59 #elif PRAGMA_STRUCT_PACK
60 #pragma pack(2)
61 #endif
62
63 /* CatalogNodeID is used to track catalog objects */
64 typedef UInt32 HFSCatalogNodeID;
65
66 /* internal error codes*/
67
68 #if TARGET_API_MACOS_X
69 #define ERR_BASE -32767
70 #else
71 #define ERR_BASE 0
72 #endif
73
74 enum {
75 /* FXM errors*/
76 fxRangeErr = ERR_BASE + 16, /* file position beyond mapped range*/
77 fxOvFlErr = ERR_BASE + 17, /* extents file overflow*/
78 /* Unicode errors*/
79 uniTooLongErr = ERR_BASE + 24, /* Unicode string too long to convert to Str31*/
80 uniBufferTooSmallErr = ERR_BASE + 25, /* Unicode output buffer too small*/
81 uniNotMappableErr = ERR_BASE + 26, /* Unicode string can't be mapped to given script*/
82 /* BTree Manager errors*/
83 btNotFound = ERR_BASE + 32, /* record not found*/
84 btExists = ERR_BASE + 33, /* record already exists*/
85 btNoSpaceAvail = ERR_BASE + 34, /* no available space*/
86 btNoFit = ERR_BASE + 35, /* record doesn't fit in node */
87 btBadNode = ERR_BASE + 36, /* bad node detected*/
88 btBadHdr = ERR_BASE + 37, /* bad BTree header record detected*/
89 dsBadRotate = ERR_BASE + 64, /* bad BTree rotate*/
90 /* Catalog Manager errors*/
91 cmNotFound = ERR_BASE + 48, /* CNode not found*/
92 cmExists = ERR_BASE + 49, /* CNode already exists*/
93 cmNotEmpty = ERR_BASE + 50, /* directory CNode not empty (valence = 0)*/
94 cmRootCN = ERR_BASE + 51, /* invalid reference to root CNode*/
95 cmBadNews = ERR_BASE + 52, /* detected bad catalog structure*/
96 cmFThdDirErr = ERR_BASE + 53, /* thread belongs to a directory not a file*/
97 cmFThdGone = ERR_BASE + 54, /* file thread doesn't exist*/
98 cmParentNotFound = ERR_BASE + 55, /* CNode for parent ID does not exist*/
99 /* TFS internal errors*/
100 fsDSIntErr = -127 /* Internal file system error*/
101 };
102
103
104 /* internal flags*/
105
106 enum {
107 kEFContigBit = 1, /* force contiguous allocation*/
108 kEFContigMask = 0x02,
109 kEFAllBit = 0, /* allocate all requested bytes or none*/
110 kEFAllMask = 0x01, /* TruncateFile option flags*/
111 kTFTrunExtBit = 0, /* truncate to the extent containing new PEOF*/
112 kTFTrunExtMask = 1
113 };
114
115 enum {
116 kUndefinedStrLen = 0, /* Unknown string length */
117 kNoHint = 0,
118
119 /* FileIDs variables*/
120 kNumExtentsToCache = 4 /* just guessing for ExchangeFiles*/
121 };
122
123
124 enum {
125 kInvalidMRUCacheKey = -1L, /* flag to denote current MRU cache key is invalid*/
126 kDefaultNumMRUCacheBlocks = 16 /* default number of blocks in each cache*/
127 };
128
129
130 /* Universal Extent Key */
131
132 union ExtentKey {
133 HFSExtentKey hfs;
134 HFSPlusExtentKey hfsPlus;
135 };
136 typedef union ExtentKey ExtentKey;
137 /* Universal extent descriptor */
138
139 union ExtentDescriptor {
140 HFSExtentDescriptor hfs;
141 HFSPlusExtentDescriptor hfsPlus;
142 };
143 typedef union ExtentDescriptor ExtentDescriptor;
144 /* Universal extent record */
145
146 union ExtentRecord {
147 HFSExtentRecord hfs;
148 HFSPlusExtentRecord hfsPlus;
149 };
150 typedef union ExtentRecord ExtentRecord;
151 /* Universal catalog key */
152
153 union CatalogKey {
154 HFSCatalogKey hfs;
155 HFSPlusCatalogKey hfsPlus;
156 };
157 typedef union CatalogKey CatalogKey;
158 /* Universal catalog data record */
159
160 union CatalogRecord {
161 SInt16 recordType;
162 HFSCatalogFolder hfsFolder;
163 HFSCatalogFile hfsFile;
164 HFSCatalogThread hfsThread;
165 HFSPlusCatalogFolder hfsPlusFolder;
166 HFSPlusCatalogFile hfsPlusFile;
167 HFSPlusCatalogThread hfsPlusThread;
168 };
169 typedef union CatalogRecord CatalogRecord;
170
171
172 enum {
173 CMMaxCName = kHFSMaxFileNameChars
174 };
175
176
177 enum {
178 vcbMaxNam = 27, /* volumes currently have a 27 byte max name length*/
179 /* VCB flags*/
180 vcbManualEjectMask = 0x0001, /* bit 0 manual-eject bit: set if volume is in a manual-eject drive*/
181 vcbFlushCriticalInfoMask = 0x0002, /* bit 1 critical info bit: set if critical MDB information needs to flush*/
182 /* IoParam->ioVAtrb*/
183 kDefaultVolumeMask = 0x0020,
184 kFilesOpenMask = 0x0040
185 };
186
187
188 /* Universal catalog name*/
189
190 union CatalogName {
191 Str31 pstr;
192 HFSUniStr255 ustr;
193 };
194 typedef union CatalogName CatalogName;
195
196
197 /*
198 * MacOS accessor routines
199 */
200 #define GetFileControlBlock(fref) ((FCB *)((fref)->v_data))
201 #define GetFileRefNumFromFCB(filePtr) ((filePtr)->h_vp)
202
203
204 /* The following macro marks a VCB as dirty by setting the upper 8 bits of the flags*/
205 EXTERN_API_C( void )
206 MarkVCBDirty (ExtendedVCB *vcb);
207
208 EXTERN_API_C( void )
209 MarkVCBClean (ExtendedVCB *vcb);
210
211 EXTERN_API_C( Boolean )
212 IsVCBDirty (ExtendedVCB *vcb);
213
214
215 #define VCB_LOCK_INIT(vcb) simple_lock_init(&vcb->vcbSimpleLock)
216 #define VCB_LOCK(vcb) simple_lock(&vcb->vcbSimpleLock)
217 #define VCB_UNLOCK(vcb) simple_unlock(&vcb->vcbSimpleLock)
218
219 #define MarkVCBDirty(vcb) { VCB_LOCK((vcb)); ((vcb)->vcbFlags |= 0xFF00); VCB_UNLOCK((vcb)); }
220 #define MarkVCBClean(vcb) { VCB_LOCK((vcb)); ((vcb)->vcbFlags &= 0x00FF); VCB_UNLOCK((vcb)); }
221 #define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
222
223
224 /* Test for error and return if error occurred*/
225 EXTERN_API_C( void )
226 ReturnIfError (OSErr result);
227
228 #define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
229 /* Test for passed condition and return if true*/
230 EXTERN_API_C( void )
231 ReturnErrorIf (Boolean condition,
232 OSErr result);
233
234 #define ReturnErrorIf(condition, error) if ( (condition) ) return( (error) );
235 /* Exit function on error*/
236 EXTERN_API_C( void )
237 ExitOnError (OSErr result);
238
239 #define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
240
241
242
243 /* Catalog Manager Routines (IPI)*/
244
245 EXTERN_API_C( OSErr )
246 CreateCatalogNode (ExtendedVCB * volume,
247 HFSCatalogNodeID parentID,
248 ConstUTF8Param name,
249 UInt32 nodeType,
250 HFSCatalogNodeID * catalogNodeID,
251 UInt32 * catalogHint,
252 UInt32 teHint);
253
254 EXTERN_API_C( OSErr )
255 DeleteCatalogNode (ExtendedVCB * volume,
256 HFSCatalogNodeID parentID,
257 ConstUTF8Param name,
258 UInt32 hint);
259
260 EXTERN_API_C( OSErr )
261 GetCatalogNode (ExtendedVCB * volume,
262 HFSCatalogNodeID parentID,
263 ConstUTF8Param name,
264 UInt32 length,
265 UInt32 hint,
266 CatalogNodeData * nodeData,
267 UInt32 * newHint);
268
269 EXTERN_API_C( OSErr )
270 GetCatalogOffspring (ExtendedVCB * volume,
271 HFSCatalogNodeID folderID,
272 UInt16 index,
273 CatalogNodeData * nodeData,
274 HFSCatalogNodeID * nodeID,
275 SInt16 * nodeType);
276
277 EXTERN_API_C( OSErr )
278 MoveRenameCatalogNode (ExtendedVCB * volume,
279 HFSCatalogNodeID srcParentID,
280 ConstUTF8Param srcName,
281 UInt32 srcHint,
282 HFSCatalogNodeID dstParentID,
283 ConstUTF8Param dstName,
284 UInt32 * newHint,
285 UInt32 teHint);
286
287 EXTERN_API_C( OSErr )
288 UpdateCatalogNode (ExtendedVCB * volume,
289 HFSCatalogNodeID parentID,
290 ConstUTF8Param name,
291 UInt32 catalogHint,
292 const CatalogNodeData * nodeData);
293
294 EXTERN_API_C( OSErr )
295 CreateFileIDRef (ExtendedVCB * volume,
296 HFSCatalogNodeID parentID,
297 ConstUTF8Param name,
298 UInt32 hint,
299 HFSCatalogNodeID * threadID);
300
301 EXTERN_API_C( OSErr )
302 ExchangeFileIDs (ExtendedVCB * volume,
303 ConstUTF8Param srcName,
304 ConstUTF8Param destName,
305 HFSCatalogNodeID srcID,
306 HFSCatalogNodeID destID,
307 UInt32 srcHint,
308 UInt32 destHint );
309
310 EXTERN_API_C( OSErr )
311 LinkCatalogNode (ExtendedVCB * volume,
312 HFSCatalogNodeID parentID,
313 ConstUTF8Param name,
314 HFSCatalogNodeID linkParentID,
315 ConstUTF8Param linkName);
316
317 EXTERN_API_C( SInt32 )
318 CompareCatalogKeys (HFSCatalogKey * searchKey,
319 HFSCatalogKey * trialKey);
320
321 EXTERN_API_C( SInt32 )
322 CompareExtendedCatalogKeys (HFSPlusCatalogKey * searchKey,
323 HFSPlusCatalogKey * trialKey);
324
325 EXTERN_API_C( OSErr )
326 InitCatalogCache (void);
327
328 EXTERN_API_C( void )
329 InvalidateCatalogCache (ExtendedVCB * volume);
330
331
332 /* GenericMRUCache Routines*/
333 EXTERN_API_C( OSErr )
334 InitMRUCache (UInt32 bufferSize,
335 UInt32 numCacheBlocks,
336 Ptr * cachePtr);
337
338 EXTERN_API_C( OSErr )
339 DisposeMRUCache (Ptr cachePtr);
340
341 EXTERN_API_C( void )
342 TrashMRUCache (Ptr cachePtr);
343
344 EXTERN_API_C( OSErr )
345 GetMRUCacheBlock (UInt32 key,
346 Ptr cachePtr,
347 Ptr * buffer);
348
349 EXTERN_API_C( void )
350 InvalidateMRUCacheBlock (Ptr cachePtr,
351 Ptr buffer);
352
353 EXTERN_API_C( void )
354 InsertMRUCacheBlock (Ptr cachePtr,
355 UInt32 key,
356 Ptr buffer);
357
358 /* BTree Manager Routines*/
359
360 typedef CALLBACK_API_C( SInt32 , KeyCompareProcPtr )(void *a, void *b);
361
362
363 EXTERN_API_C( OSErr )
364 SearchBTreeRecord (FileReference refNum,
365 const void * key,
366 UInt32 hint,
367 void * foundKey,
368 void * data,
369 UInt16 * dataSize,
370 UInt32 * newHint);
371
372 EXTERN_API_C( OSErr )
373 InsertBTreeRecord (FileReference refNum,
374 void * key,
375 void * data,
376 UInt16 dataSize,
377 UInt32 * newHint);
378
379 EXTERN_API_C( OSErr )
380 DeleteBTreeRecord (FileReference refNum,
381 void * key);
382
383 EXTERN_API_C( OSErr )
384 ReplaceBTreeRecord (FileReference refNum,
385 const void * key,
386 UInt32 hint,
387 void * newData,
388 UInt16 dataSize,
389 UInt32 * newHint);
390
391 /* Prototypes for C->Asm glue*/
392 EXTERN_API_C( OSErr )
393 GetBlock_glue (UInt16 flags,
394 UInt32 nodeNumber,
395 Ptr * nodeBuffer,
396 FileReference refNum,
397 ExtendedVCB * vcb);
398
399 EXTERN_API_C( OSErr )
400 RelBlock_glue (Ptr nodeBuffer,
401 UInt16 flags);
402
403 /* Prototypes for exported routines in VolumeAllocation.c*/
404 EXTERN_API_C( OSErr )
405 BlockAllocate (ExtendedVCB * vcb,
406 UInt32 startingBlock,
407 SInt64 bytesRequested,
408 SInt64 bytesMaximum,
409 Boolean forceContiguous,
410 UInt32 * startBlock,
411 UInt32 * actualBlocks);
412
413 EXTERN_API_C( OSErr )
414 BlockDeallocate (ExtendedVCB * vcb,
415 UInt32 firstBlock,
416 UInt32 numBlocks);
417
418 EXTERN_API_C( UInt32 )
419 FileBytesToBlocks (SInt64 numerator,
420 UInt32 denominator);
421
422 /* File Extent Mapping routines*/
423 EXTERN_API_C( OSErr )
424 FlushExtentFile (ExtendedVCB * vcb);
425
426 EXTERN_API_C( SInt32 )
427 CompareExtentKeys (const HFSExtentKey * searchKey,
428 const HFSExtentKey * trialKey);
429
430 EXTERN_API_C( SInt32 )
431 CompareExtentKeysPlus (const HFSPlusExtentKey *searchKey,
432 const HFSPlusExtentKey *trialKey);
433
434 EXTERN_API_C( OSErr )
435 DeleteFile (ExtendedVCB * vcb,
436 HFSCatalogNodeID parDirID,
437 ConstUTF8Param catalogName,
438 UInt32 catalogHint);
439
440 EXTERN_API_C( OSErr )
441 TruncateFileC (ExtendedVCB * vcb,
442 FCB * fcb,
443 SInt64 peof,
444 Boolean truncateToExtent);
445
446 EXTERN_API_C( OSErr )
447 ExtendFileC (ExtendedVCB * vcb,
448 FCB * fcb,
449 SInt64 bytesToAdd,
450 UInt32 blockHint,
451 UInt32 flags,
452 SInt64 * actualBytesAdded);
453
454 EXTERN_API_C( OSErr )
455 MapFileBlockC (ExtendedVCB * vcb,
456 FCB * fcb,
457 size_t numberOfBytes,
458 off_t offset,
459 daddr_t * startBlock,
460 size_t * availableBytes);
461
462 #if TARGET_API_MACOS_X
463 EXTERN_API_C( Boolean )
464 NodesAreContiguous (ExtendedVCB * vcb,
465 FCB * fcb,
466 UInt32 nodeSize);
467 #endif
468
469 /* Utility routines*/
470
471 EXTERN_API_C( void )
472 ClearMemory (void * start,
473 UInt32 length);
474
475 EXTERN_API_C( OSErr )
476 VolumeWritable (ExtendedVCB * vcb);
477
478
479 /* Get the current time in UTC (GMT)*/
480 EXTERN_API_C( UInt32 )
481 GetTimeUTC (void);
482
483 /* Get the current local time*/
484 EXTERN_API_C( UInt32 )
485 GetTimeLocal (Boolean forHFS);
486
487 EXTERN_API_C( UInt32 )
488 LocalToUTC (UInt32 localTime);
489
490 EXTERN_API_C( UInt32 )
491 UTCToLocal (UInt32 utcTime);
492
493
494 /* Volumes routines*/
495 EXTERN_API_C( OSErr )
496 FlushVolumeControlBlock (ExtendedVCB * vcb);
497
498 EXTERN_API_C( OSErr )
499 ValidVolumeHeader (HFSPlusVolumeHeader * volumeHeader);
500
501
502 #if PRAGMA_STRUCT_ALIGN
503 #pragma options align=reset
504 #elif PRAGMA_STRUCT_PACKPUSH
505 #pragma pack(pop)
506 #elif PRAGMA_STRUCT_PACK
507 #pragma pack()
508 #endif
509
510 #ifdef PRAGMA_IMPORT_OFF
511 #pragma import off
512 #elif PRAGMA_IMPORT
513 #pragma import reset
514 #endif
515
516 #ifdef __cplusplus
517 }
518 #endif
519
520 #endif /* __FILEMGRINTERNAL__ */
521