]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfscommon/headers/FileMgrInternal.h
ed67a4cf1f8bc09d7de09aaf1d0a2be154519b8a
[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
392 /* Prototypes for exported routines in VolumeAllocation.c*/
393 EXTERN_API_C( OSErr )
394 BlockAllocate (ExtendedVCB * vcb,
395 UInt32 startingBlock,
396 SInt64 bytesRequested,
397 SInt64 bytesMaximum,
398 Boolean forceContiguous,
399 UInt32 * startBlock,
400 UInt32 * actualBlocks);
401
402 EXTERN_API_C( OSErr )
403 BlockDeallocate (ExtendedVCB * vcb,
404 UInt32 firstBlock,
405 UInt32 numBlocks);
406
407 EXTERN_API_C( UInt32 )
408 FileBytesToBlocks (SInt64 numerator,
409 UInt32 denominator);
410
411 /* File Extent Mapping routines*/
412 EXTERN_API_C( OSErr )
413 FlushExtentFile (ExtendedVCB * vcb);
414
415 EXTERN_API_C( SInt32 )
416 CompareExtentKeys (const HFSExtentKey * searchKey,
417 const HFSExtentKey * trialKey);
418
419 EXTERN_API_C( SInt32 )
420 CompareExtentKeysPlus (const HFSPlusExtentKey *searchKey,
421 const HFSPlusExtentKey *trialKey);
422
423 EXTERN_API_C( OSErr )
424 DeleteFile (ExtendedVCB * vcb,
425 HFSCatalogNodeID parDirID,
426 ConstUTF8Param catalogName,
427 UInt32 catalogHint);
428
429 EXTERN_API_C( OSErr )
430 TruncateFileC (ExtendedVCB * vcb,
431 FCB * fcb,
432 SInt64 peof,
433 Boolean truncateToExtent);
434
435 EXTERN_API_C( OSErr )
436 ExtendFileC (ExtendedVCB * vcb,
437 FCB * fcb,
438 SInt64 bytesToAdd,
439 UInt32 blockHint,
440 UInt32 flags,
441 SInt64 * actualBytesAdded);
442
443 EXTERN_API_C( OSErr )
444 MapFileBlockC (ExtendedVCB * vcb,
445 FCB * fcb,
446 size_t numberOfBytes,
447 off_t offset,
448 daddr_t * startBlock,
449 size_t * availableBytes);
450
451 #if TARGET_API_MACOS_X
452 EXTERN_API_C( Boolean )
453 NodesAreContiguous (ExtendedVCB * vcb,
454 FCB * fcb,
455 UInt32 nodeSize);
456 #endif
457
458 /* Utility routines*/
459
460 EXTERN_API_C( void )
461 ClearMemory (void * start,
462 UInt32 length);
463
464 EXTERN_API_C( OSErr )
465 VolumeWritable (ExtendedVCB * vcb);
466
467
468 /* Get the current time in UTC (GMT)*/
469 EXTERN_API_C( UInt32 )
470 GetTimeUTC (void);
471
472 /* Get the current local time*/
473 EXTERN_API_C( UInt32 )
474 GetTimeLocal (Boolean forHFS);
475
476 EXTERN_API_C( UInt32 )
477 LocalToUTC (UInt32 localTime);
478
479 EXTERN_API_C( UInt32 )
480 UTCToLocal (UInt32 utcTime);
481
482
483 /* Volumes routines*/
484 EXTERN_API_C( OSErr )
485 FlushVolumeControlBlock (ExtendedVCB * vcb);
486
487 EXTERN_API_C( OSErr )
488 ValidVolumeHeader (HFSPlusVolumeHeader * volumeHeader);
489
490
491 #if PRAGMA_STRUCT_ALIGN
492 #pragma options align=reset
493 #elif PRAGMA_STRUCT_PACKPUSH
494 #pragma pack(pop)
495 #elif PRAGMA_STRUCT_PACK
496 #pragma pack()
497 #endif
498
499 #ifdef PRAGMA_IMPORT_OFF
500 #pragma import off
501 #elif PRAGMA_IMPORT
502 #pragma import reset
503 #endif
504
505 #ifdef __cplusplus
506 }
507 #endif
508
509 #endif /* __FILEMGRINTERNAL__ */
510