]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfscommon/headers/FileMgrInternal.h
24c46bc56854e210fc7283302d891eb88c7f1450
[apple/xnu.git] / bsd / hfs / hfscommon / headers / FileMgrInternal.h
1 /*
2 * Copyright (c) 2000 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-1999 by Apple Computer, Inc., all rights reserved.
30
31 File Ownership:
32
33 DRI: Don Brady
34
35 Other Contacts: Mark Day, Deric horn, Jim Luther
36
37 Technology: File Systems
38
39 Writers:
40
41 (JL) Jim Luther
42 (msd) Mark Day
43 (djb) Don Brady
44 (DSH) Deric Horn
45
46 Change History (most recent first):
47 <MOSXS> 9/12/99 ser Removed FCBs.
48 <MOSX> 9/9/99 pwd Fixed some VCB fields to be unsigned instead of signed to align
49 the definitions with the MDB/volume header and actual use [#2355889].
50 <MOSXS> 9/3/99 ser Added kUndefinedStrLen.
51 <MOSXS> 6/3/99 djb Removed unused/legacy vcb fields from ExtendedVCB.
52 <MOSXS> 11/20/98 djb Add support for UTF-8 names.
53 <MOSXS> 8/31/98 djb Added boolean flag to GetTimeLocal prototype.
54 <MOSXS> 6/30/98 djb Add NodesAreContiguous prototype (for radar #2249539).
55 <MOSXS> 6/22/98 djb Add ERR_BASE to error codes to make them negative (for MacOS X only).
56 Replace DeallocFile prototype with DeleteFile prototype.
57 <MOSXS> 6/5/98 djb Added CreateFileIDRef prototype;
58 <MOSXS> 6/3/98 djb Add MoveRenameCatalogNode prototype (replaces seperate Move and Rename).
59 <MOSXS> 4/17/98 djb Add VCB locking.
60 <MOSXS> 4/6/98 djb Removed CreateVolumeCatalogCache and DisposeVolumeCatalogCache (obsolete).
61 <MOSXS> 4/2/98 djb UpdateCatalogNode now takes parID and name as input.
62 <MOSXS> 3/31/98 djb Sync up with final HFSVolumes.h header file.
63 <MOSXS> 3/17/98 djb Fixed CreateCatalogNode interface to take kCatalogFolderNode and
64 kCatalogFileNode as type input.
65
66 <CS30> 1/29/98 DSH Added TrashVolumeDiskCache prototype for TrashAllFSCaches API
67 support.
68 <CS29> 12/10/97 DSH 2201501, Overload the NodeData valence field for over 2 Gig file
69 support.
70 <CS28> 11/18/97 DSH Conditionalize ou BlockCameFromDisk() macro for DFA
71 <CS27> 11/16/97 djb LockMappingTable is now defined in UnicodeConverterPriv.i.
72 <CS26> 11/13/97 djb Move CatalogIterator struct to CatalogPrivate.h. Include
73 UnicodeConverter.i instead of Unicode.i.
74 <CS25> 11/3/97 JL #2001483 - changed UnMountVolume's prototype.
75 <24> 10/31/97 DSH Added consistencyStatus parameter to MountCheck.
76 <CS23> 10/21/97 DSH Interfacer tweak
77 <CS22> 10/21/97 DSH Conditionalize LMGetFCBTable, LMGetFSVars for DFA to call
78 through DFAs LowMem accessors.
79 <CS21> 10/20/97 msd Add a bytesMaximum parameter to BlockAllocate; removed fcb
80 parameter.
81 <CS20> 10/19/97 msd Bug 1684586. Remove the modifyDate field from CatalogNodeDate.
82 GetCatInfo and SetCatInfo use only contentModDate.
83 <CS19> 10/16/97 djb Add LMGetFSVars and LMGetFCBTable macros, add gBlockCacheDirty
84 to FSVars, simplified HFS Stack swapping macros.
85 <CS18> 10/13/97 DSH Added InitBTreeHeader prototype
86 <CS17> 10/13/97 djb Add volumeNameEncodingHint to VCB, add textEncoding to
87 CatalogNodeData, add gTextEncodingFontName to FSVars.
88 <CS16> 10/1/97 DSH Added CheckVolumeConsistency() for 1682475.
89 <CS15> 10/1/97 djb New Catalog iterators and Catalog node cache SPI.
90 <CS14> 9/17/97 DSH Moved prototype HFSBlocksFromTotalSectors() here for DFA
91 wrapperless volume support.
92 <CS13> 9/16/97 msd Add a field to FSVarsRec to store old WriteXParam address.
93 <CS12> 9/15/97 djb Add gBootPToUTable to FSVars (used to bootstrap Unicode).
94 <CS11> 9/7/97 djb Add FlushBlockCache prototype.
95 <CS10> 9/4/97 djb Add cmParentNotFound error code and reportMissingParent bit.
96 <CS9> 9/4/97 msd Remove unused attributes calls. Rename PropertyCloseVolume to
97 AttributesCloseVolume. In CatalogNodeData, replace
98 attributeModDate with modifyDate. Remove macro LatestModDate.
99 <CS8> 8/22/97 djb Add readFromDisk flag to GetCacheBlock and BlockCameFromDisk
100 macro.
101 <CS7> 8/18/97 DSH Override ASM cache accessing routines for DFA to use DFA cache.
102 <CS6> 7/28/97 msd Add prototypes for CacheReadInPlace, RemountWrappedVolumes.
103 <CS5> 7/25/97 DSH Added GenericMRUCache Routines
104 <CS4> 7/22/97 msd In CatalogNodeData, move attributeModDate after backupDate; this
105 allows SetCatInfo to manipulate the rest of the dates in one
106 block, the same as in the parameter block.
107 <CS3> 7/21/97 djb Add more instrumentation globals (CallProfile). Reallign FSVars.
108 <CS2> 7/18/97 msd Selector for PBCreateAttribute conflicts with PBGetXCatInfo. The
109 attribute calls now have selectors in the range $65..$69.
110 <CS1> 7/16/97 DSH first checked in
111 <CS23> 7/8/97 DSH Added LockMappingTable() until its moved into the Unicode header
112 files.
113 <CS22> 7/7/97 DSH Taking out changes made in HFS <45> for greater compatability
114 with the Tempo installer.
115 <CS21> 6/27/97 msd Add PBLongRename SPI. Add prototype for
116 RenameCatalogNodeUnicode.
117 <CS20> 6/26/97 DSH Conditionalized macro LocalToUTC to not look at FSVars for DFA.
118 <CS19> 6/25/97 msd Add prototype for HFSCommunicationProc.
119 <CS18> 6/24/97 DSH Adding runtime flags to deturmine unicode usage and installation
120 status.
121 <CS17> 6/24/97 djb Add linkCount to CatalogNodeData. Add LinkCatalogNode prototype.
122 Move Private Catalog Manager prototypes to CatalogPrivate.h.
123 <CS16> 6/20/97 msd Add prototype for CopyCatalogNodeData. In CatalogNodeData,
124 replaced modifyDate with contentModDate and attributeModDate.
125 Added a LatestModDate macro.
126 <15> 6/18/97 djb Add mask to ConversionContext. Add encodingsBitmap to VCB (and
127 reallign some fields). Add gInstalledEncodings to FSVars.
128 <CS14> 6/17/97 msd The conversions between local time and UTC have the sign of the
129 offset backwards.
130 <CS13> 6/13/97 djb Removed PrepareOutputName. Changed parameters for
131 DeleteCatalogNode, MoveCatalogNode, PrepareInputName. Add
132 private catalog macros.
133 <CS12> 6/12/97 msd Export BlockAllocateAny and UpdateVCBFreeBlks.
134 <CS11> 6/12/97 msd Add a parameter block and prototype for an SPI to create very
135 large files.
136 <CS10> 6/9/97 msd Add an offsetToUTC field to FSVarsRec. Add prototypes for
137 GetTimeUTC and GetTimeLocal; add macros for LocalToUTC and
138 UTCToLocal.
139 <CS9> 6/5/97 msd Add MapLogicalToPhysical (internal routine), PBMapFilePosition
140 for external use.
141 <CS8> 6/4/97 djb More Unicode converter changes (support for non roman scripts).
142 <CS7> 6/2/97 msd Add prototype for AdjustEOF.
143 <CS6> 5/28/97 msd Add prototypes for attributes SPI, both internal routines and PB
144 calls. Add FindFileNameGlueRec and FindFileName routine.
145 Prototypes for FindFileControlBlock and AccessBTree disappeared,
146 so added again.
147 <CS5> 5/20/97 DSH Including LowMemPriv.a in DFA compiles
148 <CS4> 5/19/97 djb Add uppLockMappingTable to FSVars.
149 <CS3> 5/19/97 djb Add CreateVolumeCatalogCache and DisposeVolumeCatalogCache
150 prototypes. Remove private CatalogDataCache structure.
151 <CS2> 5/16/97 msd Use fixed-size integers for GetBlock_glue and RelBlock_glue so
152 it will build with compilers other than MPW C and SC. Add
153 prototype for FillHFSStack, UnMountVolume, and
154 MakeVCBsExtendedVCBs from VolumeRequests.c. Add prototypes for
155 CreateEmbeddedVolume and InitUnicodeConverter.
156 <CS1> 5/9/97 djb first checked in
157 <CS2> 5/7/97 djb Add summary trace data. Shrink FSVars.later to 4 longs.
158 <CS1> 4/28/97 djb first checked in
159
160 */
161 #ifndef __FILEMGRINTERNAL__
162 #define __FILEMGRINTERNAL__
163
164 #include <sys/param.h>
165 #include <sys/vnode.h>
166
167 #include "../../hfs.h"
168 #include "../../hfs_macos_defs.h"
169 #include "../../hfs_format.h"
170
171
172 #if PRAGMA_ONCE
173 #pragma once
174 #endif
175
176 #ifdef __cplusplus
177 extern "C" {
178 #endif
179
180 #if PRAGMA_IMPORT
181 #pragma import on
182 #endif
183
184 #if PRAGMA_STRUCT_ALIGN
185 #pragma options align=mac68k
186 #elif PRAGMA_STRUCT_PACKPUSH
187 #pragma pack(push, 2)
188 #elif PRAGMA_STRUCT_PACK
189 #pragma pack(2)
190 #endif
191
192 /* CatalogNodeID is used to track catalog objects */
193 typedef UInt32 HFSCatalogNodeID;
194
195 /* internal error codes*/
196
197 #if TARGET_API_MACOS_X
198 #define ERR_BASE -32767
199 #else
200 #define ERR_BASE 0
201 #endif
202
203 enum {
204 /* FXM errors*/
205 fxRangeErr = ERR_BASE + 16, /* file position beyond mapped range*/
206 fxOvFlErr = ERR_BASE + 17, /* extents file overflow*/
207 /* Unicode errors*/
208 uniTooLongErr = ERR_BASE + 24, /* Unicode string too long to convert to Str31*/
209 uniBufferTooSmallErr = ERR_BASE + 25, /* Unicode output buffer too small*/
210 uniNotMappableErr = ERR_BASE + 26, /* Unicode string can't be mapped to given script*/
211 /* BTree Manager errors*/
212 btNotFound = ERR_BASE + 32, /* record not found*/
213 btExists = ERR_BASE + 33, /* record already exists*/
214 btNoSpaceAvail = ERR_BASE + 34, /* no available space*/
215 btNoFit = ERR_BASE + 35, /* record doesn't fit in node */
216 btBadNode = ERR_BASE + 36, /* bad node detected*/
217 btBadHdr = ERR_BASE + 37, /* bad BTree header record detected*/
218 dsBadRotate = ERR_BASE + 64, /* bad BTree rotate*/
219 /* Catalog Manager errors*/
220 cmNotFound = ERR_BASE + 48, /* CNode not found*/
221 cmExists = ERR_BASE + 49, /* CNode already exists*/
222 cmNotEmpty = ERR_BASE + 50, /* directory CNode not empty (valence = 0)*/
223 cmRootCN = ERR_BASE + 51, /* invalid reference to root CNode*/
224 cmBadNews = ERR_BASE + 52, /* detected bad catalog structure*/
225 cmFThdDirErr = ERR_BASE + 53, /* thread belongs to a directory not a file*/
226 cmFThdGone = ERR_BASE + 54, /* file thread doesn't exist*/
227 cmParentNotFound = ERR_BASE + 55, /* CNode for parent ID does not exist*/
228 /* TFS internal errors*/
229 fsDSIntErr = -127 /* Internal file system error*/
230 };
231
232
233 /* internal flags*/
234
235
236 enum {
237 /* File System busy flag:*/
238 /* Bit zero of FSBusy (lomem $360) is true when the file system is running.*/
239 /* The word at $360 is cleared when the file system is exited. The*/
240 /* bits defined here are for additional flags in the FSBusy word that are*/
241 /* valid only when the file system is running.*/
242 fsBusyBit = 0, /* file system is running; other FSBusy bits are valid*/
243 fsSCSIDefer = 1, /* file system is waiting for SCSI transaction to complete*/
244 fsIntMaskDefer = 2, /* file system is waiting until the interrupt mask is lowered*/
245 /* Flag bits in HFSFlags byte:*/
246 hfsReq = 0, /* Set if request is specific to HFS*/
247 dirCN = 1, /* Set if a CNode is a directory*/
248 reportMissingParent = 4, /* tell Catalog to report missing parents (used by MakeFSSpec)*/
249 skipPMSP = 5, /* Set to skip PMSP setup (one-shot)*/
250 noPMSP = 6, /* Set to disable PMSP completely (status flag)*/
251 hfsContd = 7, /* Set if Async trap is continued*/
252 /* fsFlags values*/
253 fsNoAllocate = 0,
254 fsNoAllocateMask = 0x01, /* true when allocating memory is a very bad idea*/
255 fsNeedFCBs = 1,
256 fsNeedFCBsMask = 0x02, /* true when a local FCB couldn't be found */
257 fsNoFCBExpansion = 2,
258 fsNoFCBExpansionMask = 0x04, /* true if no FCB expansion logic is desired*/
259 /* ExtendFile option flags*/
260 /* extendFileAllBit = 0, |* allocate all requested bytes or none *|*/
261 /* extendFileAllMask = 0x0001,*/
262 /* */
263 /* extendFileContigBit = 1, |* force contiguous allocation *|*/
264 /* extendFileContigMask = 0x0002*/
265 kEFContigBit = 1, /* force contiguous allocation*/
266 kEFContigMask = 0x02,
267 kEFAllBit = 0, /* allocate all requested bytes or none*/
268 kEFAllMask = 0x01, /* TruncateFile option flags*/
269 kTFTrunExtBit = 0, /* truncate to the extent containing new PEOF*/
270 kTFTrunExtMask = 1
271 };
272
273 enum {
274 kUndefinedStrLen = 0 /* Unknown string length */
275 };
276
277 enum {
278 HFSStkLen = 1792, /* old stack size (pre HFS Plus)*/
279 kFileSystemStackSlop = 16, /* additional temporary space*/
280 kFileSystemStackSize = 16384, /* give us more breathing room*/
281 kFileSystemVersion = FOUR_CHAR_CODE('2.0A'), /* current file system version*/
282 /* 31744 = $7C00, a nice round number close to*/
283 /* (32767*1000)/1024, which is about the largest */
284 /* free space unsuspecting, decimal-K minded apps*/
285 /* might be expected to handle.*/
286 /* AlBlkLim*/
287 kMaxHFSAllocationBlocks = 31744,
288 WDRfnMin = -32767, /* lowest assigned WD RefNum*/
289 WDRfnMax = -4096, /* largest possible WDrefnum*/
290 kFirstFileRefnum = 2, /* smallest FCB refnum*/
291 kNoHint = 0
292 };
293
294
295 /* Internal LowMem pointers*/
296
297 /*\80\80 The following should really be in LowMemPriv.i*/
298
299 enum {
300 FSCallAsync = 0x0342, /* ONE BYTE FREE*/
301 NoEject = 0x034B, /* used by Eject and Offline*/
302 CacheFlag = 0x0377,
303 SysBMCPtr = 0x0378, /* System-wide bitmap cache pointer*/
304 SysCtlCPtr = 0x0380, /* System-wide control cache pointer*/
305 HFSDSErr = 0x0392, /* Final gasp - error that caused IOErr.*/
306 LMParamBlock = 0x03A4, /* LMGetParams() just gives us a copy of it*/
307 FSVarsPtr = 0x0BB8, /* lomem that points to file system variable block*/
308 CacheVars = 0x0394,
309 HFSStkPtr = 0x036E, /* Temporary location of HFS Stack pointer*/
310 FSIOErr = 0x03DE, /* last I/O error (NEXT WORD FREE)*/
311 /* file manager vectors not found in LowMemPriv.i*/
312 JUpdAltMDB = (0xED) * 4 + 0x0400, /* ($A0ED) $0400 is n/OSTable*/
313 JCkExtFS = (0xEE) * 4 + 0x0400, /* ($A0EE) $0400 is n/OSTable*/
314 JBMChk = (0xF0) * 4 + 0x0400, /* ($A0F0) $0400 is n/OSTable*/
315 JTstMod = (0xF1) * 4 + 0x0400, /* ($A0F1) $0400 is n/OSTable*/
316 JLocCRec = (0xF2) * 4 + 0x0400, /* ($A0F2) $0400 is n/OSTable*/
317 JTreeSearch = (0xF3) * 4 + 0x0400, /* ($A0F3) $0400 is n/OSTable*/
318 JMapFBlock = (0xF4) * 4 + 0x0400, /* ($A0F4) $0400 is n/OSTable*/
319 JXFSearch = (0xF5) * 4 + 0x0400, /* ($A0F5) $0400 is n/OSTable*/
320 JReadBM = (0xF6) * 4 + 0x0400 /* ($A0F6) $0400 is n/OSTable*/
321 };
322
323
324 /* Poor Man's Search Path*/
325
326 struct SearchPathHeader {
327 Ptr PMSPHook; /* Hook for PMSP modification*/
328 short PMSPIndx; /* Index to PMSP index from start of PMSP*/
329 };
330 typedef struct SearchPathHeader SearchPathHeader;
331
332 struct SearchPathEntry {
333 short spVRefNum; /* VRefNum in PMSP entry*/
334 UInt32 spDirID; /* Directory ID in PMSP entry*/
335 };
336 typedef struct SearchPathEntry SearchPathEntry;
337
338
339 enum {
340 kPoorMansSearchIndex = -2,
341 MaxDVCnt = 8, /* Leave room for 8 default VRefNums*/
342 PMSPSize = MaxDVCnt * sizeof(SearchPathEntry) + sizeof(SearchPathHeader) + 2
343 };
344
345
346
347 enum {
348 fsWDCBExtendCount = 8, /* # of WDCB's to add when we run out*/
349 /* FileIDs variables*/
350 kNumExtentsToCache = 4 /* just guessing for ExchangeFiles*/
351 };
352
353
354 enum {
355 kInvalidMRUCacheKey = -1L, /* flag to denote current MRU cache key is invalid*/
356 kDefaultNumMRUCacheBlocks = 16 /* default number of blocks in each cache*/
357 };
358
359
360 /* Universal Extent Key */
361
362 union ExtentKey {
363 HFSExtentKey hfs;
364 HFSPlusExtentKey hfsPlus;
365 };
366 typedef union ExtentKey ExtentKey;
367 /* Universal extent descriptor */
368
369 union ExtentDescriptor {
370 HFSExtentDescriptor hfs;
371 HFSPlusExtentDescriptor hfsPlus;
372 };
373 typedef union ExtentDescriptor ExtentDescriptor;
374 /* Universal extent record */
375
376 union ExtentRecord {
377 HFSExtentRecord hfs;
378 HFSPlusExtentRecord hfsPlus;
379 };
380 typedef union ExtentRecord ExtentRecord;
381 /* Universal catalog key */
382
383 union CatalogKey {
384 HFSCatalogKey hfs;
385 HFSPlusCatalogKey hfsPlus;
386 };
387 typedef union CatalogKey CatalogKey;
388 /* Universal catalog data record */
389
390 union CatalogRecord {
391 SInt16 recordType;
392 HFSCatalogFolder hfsFolder;
393 HFSCatalogFile hfsFile;
394 HFSCatalogThread hfsThread;
395 HFSPlusCatalogFolder hfsPlusFolder;
396 HFSPlusCatalogFile hfsPlusFile;
397 HFSPlusCatalogThread hfsPlusThread;
398 };
399 typedef union CatalogRecord CatalogRecord;
400
401
402 enum {
403 CMMaxCName = kHFSMaxFileNameChars
404 };
405
406
407 enum {
408 vcbMaxNam = 27, /* volumes currently have a 27 byte max name length*/
409 /* VCB flags*/
410 vcbManualEjectMask = 0x0001, /* bit 0 manual-eject bit: set if volume is in a manual-eject drive*/
411 vcbFlushCriticalInfoMask = 0x0002, /* bit 1 critical info bit: set if critical MDB information needs to flush*/
412 /* IoParam->ioVAtrb*/
413 kDefaultVolumeMask = 0x0020,
414 kFilesOpenMask = 0x0040
415 };
416
417
418 /* Catalog Node Data - universal data returned from the Catalog Manager*/
419
420
421 enum {
422 xFFFilAttrLockMask = 0x70
423 };
424
425 /* valence is overloaded for files and used as additional flags. 2201501*/
426
427 enum {
428 kLargeDataForkMask = 0x00000001,
429 kLargeRsrcForkMask = 0x00000002
430 };
431
432 /* Universal catalog name*/
433
434 union CatalogName {
435 Str31 pstr;
436 HFSUniStr255 ustr;
437 };
438 typedef union CatalogName CatalogName;
439
440 /* Unicode Conversion*/
441
442
443 enum {
444 kMacBaseEncodingCount = 50,
445 kTextEncodingUndefined = 0x00007FFF
446 };
447
448 struct ConversionContext {
449 TextToUnicodeInfo toUnicode;
450 UnicodeToTextInfo fromUnicode;
451 };
452 typedef struct ConversionContext ConversionContext;
453
454 struct CallProfile {
455 UInt16 refCount;
456 UInt16 errCount;
457 UInt32 callCount;
458 UInt32 minTime;
459 UInt32 maxTime;
460 UInt64 totalTime;
461 UInt64 startBase; /* in nanoseconds*/
462 };
463 typedef struct CallProfile CallProfile;
464
465
466 struct FSVarsRec {
467 UInt32 gDefaultBaseEncoding;
468 ItemCount gInstalledEncodings;
469 ConversionContext gConversionContext[50];
470 Ptr gBootPToUTable; /* used by boot code to find Extensions folder*/
471 StringPtr gTextEncodingFontName; /* points to font name (only used when no HFS Plus volumes have been mounted)*/
472 Boolean gUseDynamicUnicodeConverters;
473 Boolean gIsUnicodeInstalled;
474 };
475 typedef struct FSVarsRec FSVarsRec;
476
477
478
479 /*
480 * MacOS accessor routines
481 */
482 #define GetFileControlBlock(fref) ((FCB *)((fref)->v_data))
483 #define GetFileRefNumFromFCB(filePtr) ((filePtr)->h_vp)
484
485
486 EXTERN_API_C( Boolean )
487 BlockCameFromDisk (void);
488
489 /* The following macro marks a VCB as dirty by setting the upper 8 bits of the flags*/
490 EXTERN_API_C( void )
491 MarkVCBDirty (ExtendedVCB *vcb);
492
493 EXTERN_API_C( void )
494 MarkVCBClean (ExtendedVCB *vcb);
495
496 EXTERN_API_C( Boolean )
497 IsVCBDirty (ExtendedVCB *vcb);
498
499
500 #define VCB_LOCK_INIT(vcb) simple_lock_init(&vcb->vcbSimpleLock)
501 #define VCB_LOCK(vcb) simple_lock(&vcb->vcbSimpleLock)
502 #define VCB_UNLOCK(vcb) simple_unlock(&vcb->vcbSimpleLock)
503
504 #define MarkVCBDirty(vcb) { VCB_LOCK((vcb)); ((vcb)->vcbFlags |= 0xFF00); VCB_UNLOCK((vcb)); }
505 #define MarkVCBClean(vcb) { VCB_LOCK((vcb)); ((vcb)->vcbFlags &= 0x00FF); VCB_UNLOCK((vcb)); }
506 #define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
507
508
509 /* Test for error and return if error occurred*/
510 EXTERN_API_C( void )
511 ReturnIfError (OSErr result);
512
513 #define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
514 /* Test for passed condition and return if true*/
515 EXTERN_API_C( void )
516 ReturnErrorIf (Boolean condition,
517 OSErr result);
518
519 #define ReturnErrorIf(condition, error) if ( (condition) ) return( (error) );
520 /* Exit function on error*/
521 EXTERN_API_C( void )
522 ExitOnError (OSErr result);
523
524 #define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
525 /* Return the low 16 bits of a 32 bit value, pinned if too large*/
526 EXTERN_API_C( UInt16 )
527 LongToShort (UInt32 l);
528
529 #define LongToShort( l ) l <= (UInt32)0x0000FFFF ? ((UInt16) l) : ((UInt16) 0xFFFF)
530
531
532 /* Catalog Manager Routines (IPI)*/
533
534 EXTERN_API_C( OSErr )
535 CreateCatalogNode (ExtendedVCB * volume,
536 HFSCatalogNodeID parentID,
537 ConstUTF8Param name,
538 UInt32 nodeType,
539 HFSCatalogNodeID * catalogNodeID,
540 UInt32 * catalogHint);
541
542 EXTERN_API_C( OSErr )
543 DeleteCatalogNode (ExtendedVCB * volume,
544 HFSCatalogNodeID parentID,
545 ConstUTF8Param name,
546 UInt32 hint);
547
548 EXTERN_API_C( OSErr )
549 GetCatalogNode (ExtendedVCB * volume,
550 HFSCatalogNodeID parentID,
551 ConstUTF8Param name,
552 UInt32 length,
553 UInt32 hint,
554 CatalogNodeData * nodeData,
555 UInt32 * newHint);
556
557 EXTERN_API_C( OSErr )
558 GetCatalogOffspring (ExtendedVCB * volume,
559 HFSCatalogNodeID folderID,
560 UInt16 index,
561 CatalogNodeData * nodeData,
562 HFSCatalogNodeID * nodeID,
563 SInt16 * nodeType);
564
565 EXTERN_API_C( OSErr )
566 MoveRenameCatalogNode (ExtendedVCB * volume,
567 HFSCatalogNodeID srcParentID,
568 ConstUTF8Param srcName,
569 UInt32 srcHint,
570 HFSCatalogNodeID dstParentID,
571 ConstUTF8Param dstName,
572 UInt32 * newHint);
573
574 EXTERN_API_C( OSErr )
575 UpdateCatalogNode (ExtendedVCB * volume,
576 HFSCatalogNodeID parentID,
577 ConstUTF8Param name,
578 UInt32 catalogHint,
579 const CatalogNodeData * nodeData);
580
581 EXTERN_API_C( OSErr )
582 CreateFileIDRef (ExtendedVCB * volume,
583 HFSCatalogNodeID parentID,
584 ConstUTF8Param name,
585 UInt32 hint,
586 HFSCatalogNodeID * threadID);
587
588 EXTERN_API_C( OSErr )
589 ExchangeFileIDs (ExtendedVCB * volume,
590 ConstUTF8Param srcName,
591 ConstUTF8Param destName,
592 HFSCatalogNodeID srcID,
593 HFSCatalogNodeID destID,
594 UInt32 srcHint,
595 UInt32 destHint );
596
597 EXTERN_API_C( OSErr )
598 LinkCatalogNode (ExtendedVCB * volume,
599 HFSCatalogNodeID parentID,
600 ConstUTF8Param name,
601 HFSCatalogNodeID linkParentID,
602 ConstUTF8Param linkName);
603
604 EXTERN_API_C( SInt32 )
605 CompareCatalogKeys (HFSCatalogKey * searchKey,
606 HFSCatalogKey * trialKey);
607
608 EXTERN_API_C( SInt32 )
609 CompareExtendedCatalogKeys (HFSPlusCatalogKey * searchKey,
610 HFSPlusCatalogKey * trialKey);
611
612 EXTERN_API_C( OSErr )
613 InitCatalogCache (void);
614
615 EXTERN_API_C( void )
616 InvalidateCatalogCache (ExtendedVCB * volume);
617
618
619 /* GenericMRUCache Routines*/
620 EXTERN_API_C( OSErr )
621 InitMRUCache (UInt32 bufferSize,
622 UInt32 numCacheBlocks,
623 Ptr * cachePtr);
624
625 EXTERN_API_C( OSErr )
626 DisposeMRUCache (Ptr cachePtr);
627
628 EXTERN_API_C( void )
629 TrashMRUCache (Ptr cachePtr);
630
631 EXTERN_API_C( OSErr )
632 GetMRUCacheBlock (UInt32 key,
633 Ptr cachePtr,
634 Ptr * buffer);
635
636 EXTERN_API_C( void )
637 InvalidateMRUCacheBlock (Ptr cachePtr,
638 Ptr buffer);
639
640 EXTERN_API_C( void )
641 InsertMRUCacheBlock (Ptr cachePtr,
642 UInt32 key,
643 Ptr buffer);
644
645 /* BTree Manager Routines*/
646
647 typedef CALLBACK_API_C( SInt32 , KeyCompareProcPtr )(void *a, void *b);
648
649
650 EXTERN_API_C( OSErr )
651 SearchBTreeRecord (FileReference refNum,
652 const void * key,
653 UInt32 hint,
654 void * foundKey,
655 void * data,
656 UInt16 * dataSize,
657 UInt32 * newHint);
658
659 EXTERN_API_C( OSErr )
660 InsertBTreeRecord (FileReference refNum,
661 void * key,
662 void * data,
663 UInt16 dataSize,
664 UInt32 * newHint);
665
666 EXTERN_API_C( OSErr )
667 DeleteBTreeRecord (FileReference refNum,
668 void * key);
669
670 EXTERN_API_C( OSErr )
671 ReplaceBTreeRecord (FileReference refNum,
672 const void * key,
673 UInt32 hint,
674 void * newData,
675 UInt16 dataSize,
676 UInt32 * newHint);
677
678 /* From HFSVolumesInit.c*/
679 EXTERN_API_C( void )
680 InitBTreeHeader (UInt32 fileSize,
681 UInt32 clumpSize,
682 UInt16 nodeSize,
683 UInt16 recordCount,
684 UInt16 keySize,
685 UInt32 attributes,
686 UInt32 * mapNodes,
687 void * buffer);
688
689 /* Prototypes for big block cache*/
690
691 EXTERN_API_C( OSErr )
692 InitializeBlockCache (UInt32 blockSize,
693 UInt32 blockCount);
694
695 EXTERN_API_C( OSErr )
696 FlushBlockCache (void);
697
698 EXTERN_API_C( OSErr )
699 GetCacheBlock (FileReference fileRefNum,
700 UInt32 blockNumber,
701 UInt32 blockSize,
702 UInt16 options,
703 LogicalAddress * buffer,
704 Boolean * readFromDisk);
705
706 EXTERN_API_C( OSErr )
707 ReleaseCacheBlock (LogicalAddress buffer,
708 UInt16 options);
709
710 EXTERN_API_C( OSErr )
711 MarkCacheBlock (LogicalAddress buffer);
712
713 EXTERN_API_C( OSErr )
714 TrashCacheBlocks (FileReference fileRefNum);
715
716 /* Prototypes for C->Asm glue*/
717 EXTERN_API_C( OSErr )
718 GetBlock_glue (UInt16 flags,
719 UInt32 nodeNumber,
720 Ptr * nodeBuffer,
721 FileReference refNum,
722 ExtendedVCB * vcb);
723
724 EXTERN_API_C( OSErr )
725 RelBlock_glue (Ptr nodeBuffer,
726 UInt16 flags);
727
728 EXTERN_API_C( void )
729 MarkBlock_glue (Ptr nodeBuffer);
730
731 EXTERN_API_C( OSErr )
732 C_FlushCache (ExtendedVCB * vcb,
733 UInt32 flags,
734 FileReference refNum);
735
736
737 EXTERN_API_C( void ) TrashVolumeDiskCache(ExtendedVCB * vcb);
738
739 /* Prototypes for exported routines in VolumeAllocation.c*/
740 EXTERN_API_C( OSErr )
741 BlockAllocate (ExtendedVCB * vcb,
742 UInt32 startingBlock,
743 SInt64 bytesRequested,
744 SInt64 bytesMaximum,
745 Boolean forceContiguous,
746 UInt32 * startBlock,
747 UInt32 * actualBlocks);
748
749 EXTERN_API_C( OSErr )
750 BlockDeallocate (ExtendedVCB * vcb,
751 UInt32 firstBlock,
752 UInt32 numBlocks);
753
754 EXTERN_API_C( OSErr )
755 UpdateFreeCount (ExtendedVCB * vcb);
756
757
758 EXTERN_API_C( OSErr )
759 AllocateFreeSpace (ExtendedVCB * vcb,
760 UInt32 * startBlock,
761 UInt32 * actualBlocks);
762
763 EXTERN_API_C( UInt32 )
764 FileBytesToBlocks (SInt64 numerator,
765 UInt32 denominator);
766
767 EXTERN_API_C( OSErr )
768 BlockAllocateAny (ExtendedVCB * vcb,
769 UInt32 startingBlock,
770 UInt32 endingBlock,
771 UInt32 maxBlocks,
772 UInt32 * actualStartBlock,
773 UInt32 * actualNumBlocks);
774
775 EXTERN_API_C( void )
776 UpdateVCBFreeBlks (ExtendedVCB * vcb);
777
778 /* File Extent Mapping routines*/
779 EXTERN_API_C( OSErr )
780 FlushExtentFile (ExtendedVCB * vcb);
781
782 EXTERN_API_C( SInt32 )
783 CompareExtentKeys (const HFSExtentKey * searchKey,
784 const HFSExtentKey * trialKey);
785
786 EXTERN_API_C( SInt32 )
787 CompareExtentKeysPlus (const HFSPlusExtentKey *searchKey,
788 const HFSPlusExtentKey *trialKey);
789
790 EXTERN_API_C( OSErr )
791 DeleteFile (ExtendedVCB * vcb,
792 HFSCatalogNodeID parDirID,
793 ConstUTF8Param catalogName,
794 UInt32 catalogHint);
795
796 EXTERN_API_C( OSErr )
797 TruncateFileC (ExtendedVCB * vcb,
798 FCB * fcb,
799 SInt64 peof,
800 Boolean truncateToExtent);
801
802 EXTERN_API_C( OSErr )
803 ExtendFileC (ExtendedVCB * vcb,
804 FCB * fcb,
805 SInt64 bytesToAdd,
806 UInt32 flags,
807 SInt64 * actualBytesAdded);
808
809 EXTERN_API_C( OSErr )
810 MapFileBlockC (ExtendedVCB * vcb,
811 FCB * fcb,
812 size_t numberOfBytes,
813 off_t offset,
814 daddr_t * startBlock,
815 size_t * availableBytes);
816
817 #if TARGET_API_MACOS_X
818 EXTERN_API_C( Boolean )
819 NodesAreContiguous (ExtendedVCB * vcb,
820 FCB * fcb,
821 UInt32 nodeSize);
822 #endif
823 EXTERN_API_C( void )
824 AdjustEOF (FCB * sourceFCB);
825
826 /* Utility routines*/
827
828 EXTERN_API_C( void )
829 ClearMemory (void * start,
830 UInt32 length);
831
832 EXTERN_API_C( Boolean )
833 UnicodeBinaryCompare (ConstHFSUniStr255Param ustr1,
834 ConstHFSUniStr255Param ustr2);
835
836 EXTERN_API_C( Boolean )
837 PascalBinaryCompare (ConstStr31Param pstr1,
838 ConstStr31Param pstr2);
839
840 EXTERN_API_C( OSErr )
841 VolumeWritable (ExtendedVCB * vcb);
842
843
844 /* Get the current time in UTC (GMT)*/
845 EXTERN_API_C( UInt32 )
846 GetTimeUTC (void);
847
848 /* Get the current local time*/
849 EXTERN_API_C( UInt32 )
850 GetTimeLocal (Boolean forHFS);
851
852 EXTERN_API_C( UInt32 )
853 LocalToUTC (UInt32 localTime);
854
855 EXTERN_API_C( UInt32 )
856 UTCToLocal (UInt32 utcTime);
857
858
859 /* Volumes routines*/
860 EXTERN_API_C( OSErr )
861 FlushVolumeControlBlock (ExtendedVCB * vcb);
862
863 EXTERN_API_C( OSErr )
864 CheckVolumeOffLine (ExtendedVCB * vcb);
865
866 EXTERN_API_C( OSErr )
867 ValidVolumeHeader (HFSPlusVolumeHeader * volumeHeader);
868
869 EXTERN_API_C( void )
870 FillHFSStack (void);
871
872
873 EXTERN_API_C( OSErr )
874 AccessBTree (ExtendedVCB * vcb,
875 FileReference refNum,
876 UInt32 fileID,
877 UInt32 fileClumpSize,
878 void * CompareRoutine);
879
880 EXTERN_API_C( void )
881 RemountWrappedVolumes (void);
882
883 EXTERN_API_C( OSErr )
884 CheckVolumeConsistency (ExtendedVCB * vcb);
885
886 EXTERN_API_C( void )
887 HFSBlocksFromTotalSectors (UInt32 totalSectors,
888 UInt32 * blockSize,
889 UInt16 * blockCount);
890
891
892
893
894 #if PRAGMA_STRUCT_ALIGN
895 #pragma options align=reset
896 #elif PRAGMA_STRUCT_PACKPUSH
897 #pragma pack(pop)
898 #elif PRAGMA_STRUCT_PACK
899 #pragma pack()
900 #endif
901
902 #ifdef PRAGMA_IMPORT_OFF
903 #pragma import off
904 #elif PRAGMA_IMPORT
905 #pragma import reset
906 #endif
907
908 #ifdef __cplusplus
909 }
910 #endif
911
912 #endif /* __FILEMGRINTERNAL__ */
913