]>
Commit | Line | Data |
---|---|---|
1c79356b A |
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 | #ifndef __HFS_FORMAT__ | |
23 | #define __HFS_FORMAT__ | |
24 | ||
9bccf70c A |
25 | #include <sys/appleapiopts.h> |
26 | ||
1c79356b A |
27 | /* |
28 | * hfs_format.c | |
29 | * | |
30 | * This file describes the on-disk format for HFS and HFS Plus volumes. | |
31 | * The HFS Plus volume format is desciibed in detail in Apple Technote 1150. | |
32 | * | |
33 | * http://developer.apple.com/technotes/tn/tn1150.html | |
34 | * | |
35 | */ | |
36 | ||
37 | #ifdef __cplusplus | |
38 | extern "C" { | |
39 | #endif | |
40 | ||
41 | /* some on-disk hfs structures have 68K alignment (misaligned) */ | |
42 | #pragma options align=mac68k | |
43 | ||
44 | /* Signatures used to differentiate between HFS and HFS Plus volumes */ | |
45 | enum { | |
46 | kHFSSigWord = 0x4244, /* 'BD' in ASCII */ | |
47 | kHFSPlusSigWord = 0x482B, /* 'H+' in ASCII */ | |
48 | kHFSPlusVersion = 0x0004, /* will change as format changes */ | |
49 | /* version 4 shipped with Mac OS 8.1 */ | |
50 | kHFSPlusMountVersion = 0x31302E30 /* '10.0' for Mac OS X */ | |
51 | }; | |
52 | ||
53 | ||
9bccf70c | 54 | #ifdef __APPLE_API_PRIVATE |
1c79356b A |
55 | /* |
56 | * Mac OS X has a special directory for linked and unlinked files (HFS Plus only). | |
57 | * This directory and its contents are never exported from the filesystem under | |
58 | * Mac OS X. | |
59 | * | |
60 | * To make this folder name sort last, it has embedded null prefix. | |
61 | * (0xC0, 0x80 in UTF-8) | |
62 | */ | |
63 | #define HFSPLUSMETADATAFOLDER "\xC0\x80\xC0\x80\xC0\x80\xC0\x80HFS+ Private Data" | |
64 | ||
65 | /* | |
66 | * Files in the HFS Private Data folder have one of the following prefixes | |
67 | * followed by a decimal number (no leading zeros). For indirect nodes this | |
68 | * number is a 32 bit random number. For unlinked (deleted) files that are | |
69 | * still open, the number is the file ID for that file. | |
70 | * | |
71 | * e.g. iNode7182000 and temp3296 | |
72 | */ | |
73 | #define HFS_INODE_PREFIX "iNode" | |
74 | #define HFS_DELETE_PREFIX "temp" | |
75 | ||
9bccf70c A |
76 | #endif /* __APPLE_API_PRIVATE */ |
77 | ||
1c79356b A |
78 | /* |
79 | * Indirect link files (hard links) have the following type/creator. | |
80 | */ | |
81 | enum { | |
82 | kHardLinkFileType = 0x686C6E6B, /* 'hlnk' */ | |
83 | kHFSPlusCreator = 0x6866732B /* 'hfs+' */ | |
84 | }; | |
85 | ||
86 | ||
87 | /* Unicode strings are used for HFS Plus file and folder names */ | |
88 | struct HFSUniStr255 { | |
89 | u_int16_t length; /* number of unicode characters */ | |
90 | u_int16_t unicode[255]; /* unicode characters */ | |
91 | }; | |
92 | typedef struct HFSUniStr255 HFSUniStr255; | |
93 | typedef const HFSUniStr255 *ConstHFSUniStr255Param; | |
94 | ||
95 | enum { | |
96 | kHFSMaxVolumeNameChars = 27, | |
97 | kHFSMaxFileNameChars = 31, | |
98 | kHFSPlusMaxFileNameChars = 255 | |
99 | }; | |
100 | ||
101 | ||
102 | /* Extent overflow file data structures */ | |
103 | ||
104 | /* HFS Extent key */ | |
105 | struct HFSExtentKey { | |
106 | u_int8_t keyLength; /* length of key, excluding this field */ | |
107 | u_int8_t forkType; /* 0 = data fork, FF = resource fork */ | |
108 | u_int32_t fileID; /* file ID */ | |
109 | u_int16_t startBlock; /* first file allocation block number in this extent */ | |
110 | }; | |
111 | typedef struct HFSExtentKey HFSExtentKey; | |
112 | ||
113 | /* HFS Plus Extent key */ | |
114 | struct HFSPlusExtentKey { | |
115 | u_int16_t keyLength; /* length of key, excluding this field */ | |
116 | u_int8_t forkType; /* 0 = data fork, FF = resource fork */ | |
117 | u_int8_t pad; /* make the other fields align on 32-bit boundary */ | |
118 | u_int32_t fileID; /* file ID */ | |
119 | u_int32_t startBlock; /* first file allocation block number in this extent */ | |
120 | }; | |
121 | typedef struct HFSPlusExtentKey HFSPlusExtentKey; | |
122 | ||
123 | /* Number of extent descriptors per extent record */ | |
124 | enum { | |
125 | kHFSExtentDensity = 3, | |
126 | kHFSPlusExtentDensity = 8 | |
127 | }; | |
128 | ||
129 | /* HFS extent descriptor */ | |
130 | struct HFSExtentDescriptor { | |
131 | u_int16_t startBlock; /* first allocation block */ | |
132 | u_int16_t blockCount; /* number of allocation blocks */ | |
133 | }; | |
134 | typedef struct HFSExtentDescriptor HFSExtentDescriptor; | |
135 | ||
136 | /* HFS Plus extent descriptor */ | |
137 | struct HFSPlusExtentDescriptor { | |
138 | u_int32_t startBlock; /* first allocation block */ | |
139 | u_int32_t blockCount; /* number of allocation blocks */ | |
140 | }; | |
141 | typedef struct HFSPlusExtentDescriptor HFSPlusExtentDescriptor; | |
142 | ||
143 | /* HFS extent record */ | |
144 | typedef HFSExtentDescriptor HFSExtentRecord[3]; | |
145 | ||
146 | /* HFS Plus extent record */ | |
147 | typedef HFSPlusExtentDescriptor HFSPlusExtentRecord[8]; | |
148 | ||
149 | ||
150 | /* Finder information */ | |
151 | struct FndrFileInfo { | |
152 | u_int32_t fdType; /* file type */ | |
153 | u_int32_t fdCreator; /* file creator */ | |
154 | u_int16_t fdFlags; /* Finder flags */ | |
155 | struct { | |
156 | int16_t v; /* file's location */ | |
157 | int16_t h; | |
158 | } fdLocation; | |
159 | int16_t opaque; | |
160 | }; | |
161 | typedef struct FndrFileInfo FndrFileInfo; | |
162 | ||
163 | struct FndrDirInfo { | |
164 | struct { /* folder's window rectangle */ | |
165 | int16_t top; | |
166 | int16_t left; | |
167 | int16_t bottom; | |
168 | int16_t right; | |
169 | } frRect; | |
170 | unsigned short frFlags; /* Finder flags */ | |
171 | struct { | |
172 | u_int16_t v; /* folder's location */ | |
173 | u_int16_t h; | |
174 | } frLocation; | |
175 | int16_t opaque; | |
176 | }; | |
177 | typedef struct FndrDirInfo FndrDirInfo; | |
178 | ||
179 | struct FndrOpaqueInfo { | |
180 | int8_t opaque[16]; | |
181 | }; | |
182 | typedef struct FndrOpaqueInfo FndrOpaqueInfo; | |
183 | ||
184 | ||
185 | /* HFS Plus Fork data info - 80 bytes */ | |
186 | struct HFSPlusForkData { | |
187 | u_int64_t logicalSize; /* fork's logical size in bytes */ | |
188 | u_int32_t clumpSize; /* fork's clump size in bytes */ | |
189 | u_int32_t totalBlocks; /* total blocks used by this fork */ | |
190 | HFSPlusExtentRecord extents; /* initial set of extents */ | |
191 | }; | |
192 | typedef struct HFSPlusForkData HFSPlusForkData; | |
193 | ||
194 | ||
195 | /* Mac OS X has 16 bytes worth of "BSD" info. | |
196 | * | |
197 | * Note: Mac OS 9 implementations and applications | |
198 | * should preserve, but not change, this information. | |
199 | */ | |
200 | struct HFSPlusBSDInfo { | |
201 | u_int32_t ownerID; /* user or group ID of file/folder owner */ | |
202 | u_int32_t groupID; /* additional user of group ID */ | |
203 | u_int8_t adminFlags; /* super-user changeable flags */ | |
204 | u_int8_t ownerFlags; /* owner changeable flags */ | |
205 | u_int16_t fileMode; /* file type and permission bits */ | |
206 | union { | |
207 | u_int32_t iNodeNum; /* indirect node number (hard links only) */ | |
208 | u_int32_t linkCount; /* links that refer to this indirect node */ | |
209 | u_int32_t rawDevice; /* special file device (FBLK and FCHR only) */ | |
210 | } special; | |
211 | }; | |
212 | typedef struct HFSPlusBSDInfo HFSPlusBSDInfo; | |
213 | ||
214 | ||
215 | /* Catalog file data structures */ | |
216 | ||
217 | enum { | |
218 | kHFSRootParentID = 1, /* Parent ID of the root folder */ | |
219 | kHFSRootFolderID = 2, /* Folder ID of the root folder */ | |
220 | kHFSExtentsFileID = 3, /* File ID of the extents file */ | |
221 | kHFSCatalogFileID = 4, /* File ID of the catalog file */ | |
222 | kHFSBadBlockFileID = 5, /* File ID of the bad allocation block file */ | |
223 | kHFSAllocationFileID = 6, /* File ID of the allocation file (HFS Plus only) */ | |
224 | kHFSStartupFileID = 7, /* File ID of the startup file (HFS Plus only) */ | |
225 | kHFSAttributesFileID = 8, /* File ID of the attribute file (HFS Plus only) */ | |
226 | kHFSBogusExtentFileID = 15, /* Used for exchanging extents in extents file */ | |
227 | kHFSFirstUserCatalogNodeID = 16 | |
228 | }; | |
229 | ||
230 | /* HFS catalog key */ | |
231 | struct HFSCatalogKey { | |
232 | u_int8_t keyLength; /* key length (in bytes) */ | |
233 | u_int8_t reserved; /* reserved (set to zero) */ | |
234 | u_int32_t parentID; /* parent folder ID */ | |
235 | u_char nodeName[kHFSMaxFileNameChars + 1]; /* catalog node name */ | |
236 | }; | |
237 | typedef struct HFSCatalogKey HFSCatalogKey; | |
238 | ||
239 | /* HFS Plus catalog key */ | |
240 | struct HFSPlusCatalogKey { | |
241 | u_int16_t keyLength; /* key length (in bytes) */ | |
242 | u_int32_t parentID; /* parent folder ID */ | |
243 | HFSUniStr255 nodeName; /* catalog node name */ | |
244 | }; | |
245 | typedef struct HFSPlusCatalogKey HFSPlusCatalogKey; | |
246 | ||
247 | /* Catalog record types */ | |
248 | enum { | |
249 | /* HFS Catalog Records */ | |
250 | kHFSFolderRecord = 0x0100, /* Folder record */ | |
251 | kHFSFileRecord = 0x0200, /* File record */ | |
252 | kHFSFolderThreadRecord = 0x0300, /* Folder thread record */ | |
253 | kHFSFileThreadRecord = 0x0400, /* File thread record */ | |
254 | ||
255 | /* HFS Plus Catalog Records */ | |
256 | kHFSPlusFolderRecord = 1, /* Folder record */ | |
257 | kHFSPlusFileRecord = 2, /* File record */ | |
258 | kHFSPlusFolderThreadRecord = 3, /* Folder thread record */ | |
259 | kHFSPlusFileThreadRecord = 4 /* File thread record */ | |
260 | }; | |
261 | ||
262 | ||
263 | /* Catalog file record flags */ | |
264 | enum { | |
265 | kHFSFileLockedBit = 0x0000, /* file is locked and cannot be written to */ | |
266 | kHFSFileLockedMask = 0x0001, | |
267 | kHFSThreadExistsBit = 0x0001, /* a file thread record exists for this file */ | |
268 | kHFSThreadExistsMask = 0x0002 | |
269 | }; | |
270 | ||
271 | ||
272 | /* HFS catalog folder record - 70 bytes */ | |
273 | struct HFSCatalogFolder { | |
274 | int16_t recordType; /* == kHFSFolderRecord */ | |
275 | u_int16_t flags; /* folder flags */ | |
276 | u_int16_t valence; /* folder valence */ | |
277 | u_int32_t folderID; /* folder ID */ | |
278 | u_int32_t createDate; /* date and time of creation */ | |
279 | u_int32_t modifyDate; /* date and time of last modification */ | |
280 | u_int32_t backupDate; /* date and time of last backup */ | |
281 | FndrDirInfo userInfo; /* Finder information */ | |
282 | FndrOpaqueInfo finderInfo; /* additional Finder information */ | |
283 | u_int32_t reserved[4]; /* reserved - initialized as zero */ | |
284 | }; | |
285 | typedef struct HFSCatalogFolder HFSCatalogFolder; | |
286 | ||
287 | /* HFS Plus catalog folder record - 88 bytes */ | |
288 | struct HFSPlusCatalogFolder { | |
289 | int16_t recordType; /* == kHFSPlusFolderRecord */ | |
290 | u_int16_t flags; /* file flags */ | |
291 | u_int32_t valence; /* folder's valence (limited to 2^16 in Mac OS) */ | |
292 | u_int32_t folderID; /* folder ID */ | |
293 | u_int32_t createDate; /* date and time of creation */ | |
294 | u_int32_t contentModDate; /* date and time of last content modification */ | |
295 | u_int32_t attributeModDate; /* date and time of last attribute modification */ | |
296 | u_int32_t accessDate; /* date and time of last access (MacOS X only) */ | |
297 | u_int32_t backupDate; /* date and time of last backup */ | |
298 | HFSPlusBSDInfo bsdInfo; /* permissions (for MacOS X) */ | |
299 | FndrDirInfo userInfo; /* Finder information */ | |
300 | FndrOpaqueInfo finderInfo; /* additional Finder information */ | |
301 | u_int32_t textEncoding; /* hint for name conversions */ | |
302 | u_int32_t reserved; /* reserved - initialized as zero */ | |
303 | }; | |
304 | typedef struct HFSPlusCatalogFolder HFSPlusCatalogFolder; | |
305 | ||
306 | /* HFS catalog file record - 102 bytes */ | |
307 | struct HFSCatalogFile { | |
308 | int16_t recordType; /* == kHFSFileRecord */ | |
309 | u_int8_t flags; /* file flags */ | |
310 | int8_t fileType; /* file type (unused ?) */ | |
311 | FndrFileInfo userInfo; /* Finder information */ | |
312 | u_int32_t fileID; /* file ID */ | |
313 | u_int16_t dataStartBlock; /* not used - set to zero */ | |
314 | int32_t dataLogicalSize; /* logical EOF of data fork */ | |
315 | int32_t dataPhysicalSize; /* physical EOF of data fork */ | |
316 | u_int16_t rsrcStartBlock; /* not used - set to zero */ | |
317 | int32_t rsrcLogicalSize; /* logical EOF of resource fork */ | |
318 | int32_t rsrcPhysicalSize; /* physical EOF of resource fork */ | |
319 | u_int32_t createDate; /* date and time of creation */ | |
320 | u_int32_t modifyDate; /* date and time of last modification */ | |
321 | u_int32_t backupDate; /* date and time of last backup */ | |
322 | FndrOpaqueInfo finderInfo; /* additional Finder information */ | |
323 | u_int16_t clumpSize; /* file clump size (not used) */ | |
324 | HFSExtentRecord dataExtents; /* first data fork extent record */ | |
325 | HFSExtentRecord rsrcExtents; /* first resource fork extent record */ | |
326 | u_int32_t reserved; /* reserved - initialized as zero */ | |
327 | }; | |
328 | typedef struct HFSCatalogFile HFSCatalogFile; | |
329 | ||
330 | /* HFS Plus catalog file record - 248 bytes */ | |
331 | struct HFSPlusCatalogFile { | |
332 | int16_t recordType; /* == kHFSPlusFileRecord */ | |
333 | u_int16_t flags; /* file flags */ | |
334 | u_int32_t reserved1; /* reserved - initialized as zero */ | |
335 | u_int32_t fileID; /* file ID */ | |
336 | u_int32_t createDate; /* date and time of creation */ | |
337 | u_int32_t contentModDate; /* date and time of last content modification */ | |
338 | u_int32_t attributeModDate; /* date and time of last attribute modification */ | |
339 | u_int32_t accessDate; /* date and time of last access (MacOS X only) */ | |
340 | u_int32_t backupDate; /* date and time of last backup */ | |
341 | HFSPlusBSDInfo bsdInfo; /* permissions (for MacOS X) */ | |
342 | FndrFileInfo userInfo; /* Finder information */ | |
343 | FndrOpaqueInfo finderInfo; /* additional Finder information */ | |
344 | u_int32_t textEncoding; /* hint for name conversions */ | |
345 | u_int32_t reserved2; /* reserved - initialized as zero */ | |
346 | ||
347 | /* Note: these start on double long (64 bit) boundry */ | |
348 | HFSPlusForkData dataFork; /* size and block data for data fork */ | |
349 | HFSPlusForkData resourceFork; /* size and block data for resource fork */ | |
350 | }; | |
351 | typedef struct HFSPlusCatalogFile HFSPlusCatalogFile; | |
352 | ||
353 | /* HFS catalog thread record - 46 bytes */ | |
354 | struct HFSCatalogThread { | |
355 | int16_t recordType; /* == kHFSFolderThreadRecord or kHFSFileThreadRecord */ | |
356 | int32_t reserved[2]; /* reserved - initialized as zero */ | |
357 | u_int32_t parentID; /* parent ID for this catalog node */ | |
358 | u_char nodeName[kHFSMaxFileNameChars + 1]; /* name of this catalog node */ | |
359 | }; | |
360 | typedef struct HFSCatalogThread HFSCatalogThread; | |
361 | ||
362 | /* HFS Plus catalog thread record -- 264 bytes */ | |
363 | struct HFSPlusCatalogThread { | |
364 | int16_t recordType; /* == kHFSPlusFolderThreadRecord or kHFSPlusFileThreadRecord */ | |
365 | int16_t reserved; /* reserved - initialized as zero */ | |
366 | u_int32_t parentID; /* parent ID for this catalog node */ | |
367 | HFSUniStr255 nodeName; /* name of this catalog node (variable length) */ | |
368 | }; | |
369 | typedef struct HFSPlusCatalogThread HFSPlusCatalogThread; | |
370 | ||
9bccf70c | 371 | #ifdef __APPLE_API_UNSTABLE |
1c79356b A |
372 | /* |
373 | These are the types of records in the attribute B-tree. The values were | |
374 | chosen so that they wouldn't conflict with the catalog record types. | |
375 | */ | |
376 | enum { | |
377 | kHFSPlusAttrInlineData = 0x10, /* if size < kAttrOverflowSize */ | |
378 | kHFSPlusAttrForkData = 0x20, /* if size >= kAttrOverflowSize */ | |
379 | kHFSPlusAttrExtents = 0x30 /* overflow extents for large attributes */ | |
380 | }; | |
381 | ||
382 | ||
383 | /* | |
384 | HFSPlusAttrInlineData | |
385 | For small attributes, whose entire value is stored within this one | |
386 | B-tree record. | |
387 | There would not be any other records for this attribute. | |
388 | */ | |
389 | struct HFSPlusAttrInlineData { | |
390 | u_int32_t recordType; /* == kHFSPlusAttrInlineData*/ | |
391 | u_int32_t reserved; | |
392 | u_int32_t logicalSize; /* size in bytes of userData*/ | |
393 | u_int8_t userData[2]; /* variable length; space allocated is a multiple of 2 bytes*/ | |
394 | }; | |
395 | typedef struct HFSPlusAttrInlineData HFSPlusAttrInlineData; | |
396 | ||
397 | ||
398 | /* | |
399 | HFSPlusAttrForkData | |
400 | For larger attributes, whose value is stored in allocation blocks. | |
401 | If the attribute has more than 8 extents, there will be additonal | |
402 | records (of type HFSPlusAttrExtents) for this attribute. | |
403 | */ | |
404 | struct HFSPlusAttrForkData { | |
405 | u_int32_t recordType; /* == kHFSPlusAttrForkData*/ | |
406 | u_int32_t reserved; | |
407 | HFSPlusForkData theFork; /* size and first extents of value*/ | |
408 | }; | |
409 | typedef struct HFSPlusAttrForkData HFSPlusAttrForkData; | |
410 | ||
411 | /* | |
412 | HFSPlusAttrExtents | |
413 | This record contains information about overflow extents for large, | |
414 | fragmented attributes. | |
415 | */ | |
416 | struct HFSPlusAttrExtents { | |
417 | u_int32_t recordType; /* == kHFSPlusAttrExtents*/ | |
418 | u_int32_t reserved; | |
419 | HFSPlusExtentRecord extents; /* additional extents*/ | |
420 | }; | |
421 | typedef struct HFSPlusAttrExtents HFSPlusAttrExtents; | |
422 | ||
423 | /* A generic Attribute Record*/ | |
424 | union HFSPlusAttrRecord { | |
425 | u_int32_t recordType; | |
426 | HFSPlusAttrInlineData inlineData; | |
427 | HFSPlusAttrForkData forkData; | |
428 | HFSPlusAttrExtents overflowExtents; | |
429 | }; | |
430 | typedef union HFSPlusAttrRecord HFSPlusAttrRecord; | |
431 | ||
432 | /* Key and node lengths */ | |
433 | enum { | |
434 | kHFSPlusExtentKeyMaximumLength = sizeof(HFSPlusExtentKey) - sizeof(u_int16_t), | |
435 | kHFSExtentKeyMaximumLength = sizeof(HFSExtentKey) - sizeof(u_int8_t), | |
436 | kHFSPlusCatalogKeyMaximumLength = sizeof(HFSPlusCatalogKey) - sizeof(u_int16_t), | |
437 | kHFSPlusCatalogKeyMinimumLength = kHFSPlusCatalogKeyMaximumLength - sizeof(HFSUniStr255) + sizeof(u_int16_t), | |
438 | kHFSCatalogKeyMaximumLength = sizeof(HFSCatalogKey) - sizeof(u_int8_t), | |
439 | kHFSCatalogKeyMinimumLength = kHFSCatalogKeyMaximumLength - (kHFSMaxFileNameChars + 1) + sizeof(u_int8_t), | |
440 | kHFSPlusCatalogMinNodeSize = 4096, | |
441 | kHFSPlusExtentMinNodeSize = 512, | |
442 | kHFSPlusAttrMinNodeSize = 4096 | |
443 | }; | |
9bccf70c | 444 | #endif /* __APPLE_API_UNSTABLE */ |
1c79356b A |
445 | |
446 | /* HFS and HFS Plus volume attribute bits */ | |
447 | enum { | |
448 | /* Bits 0-6 are reserved (always cleared by MountVol call) */ | |
449 | kHFSVolumeHardwareLockBit = 7, /* volume is locked by hardware */ | |
450 | kHFSVolumeUnmountedBit = 8, /* volume was successfully unmounted */ | |
451 | kHFSVolumeSparedBlocksBit = 9, /* volume has bad blocks spared */ | |
452 | kHFSVolumeNoCacheRequiredBit = 10, /* don't cache volume blocks (i.e. RAM or ROM disk) */ | |
453 | kHFSBootVolumeInconsistentBit = 11, /* boot volume is inconsistent (System 7.6 and later) */ | |
454 | kHFSCatalogNodeIDsReusedBit = 12, | |
455 | /* Bits 13-14 are reserved for future use */ | |
456 | kHFSVolumeSoftwareLockBit = 15, /* volume is locked by software */ | |
457 | ||
458 | kHFSVolumeHardwareLockMask = 1 << kHFSVolumeHardwareLockBit, | |
459 | kHFSVolumeUnmountedMask = 1 << kHFSVolumeUnmountedBit, | |
460 | kHFSVolumeSparedBlocksMask = 1 << kHFSVolumeSparedBlocksBit, | |
461 | kHFSVolumeNoCacheRequiredMask = 1 << kHFSVolumeNoCacheRequiredBit, | |
462 | kHFSBootVolumeInconsistentMask = 1 << kHFSBootVolumeInconsistentBit, | |
463 | kHFSCatalogNodeIDsReusedMask = 1 << kHFSCatalogNodeIDsReusedBit, | |
464 | kHFSVolumeSoftwareLockMask = 1 << kHFSVolumeSoftwareLockBit, | |
465 | kHFSMDBAttributesMask = 0x8380 | |
466 | }; | |
467 | ||
468 | ||
469 | /* HFS Master Directory Block - 162 bytes */ | |
470 | /* Stored at sector #2 (3rd sector) and second-to-last sector. */ | |
471 | struct HFSMasterDirectoryBlock { | |
472 | u_int16_t drSigWord; /* == kHFSSigWord */ | |
473 | u_int32_t drCrDate; /* date and time of volume creation */ | |
474 | u_int32_t drLsMod; /* date and time of last modification */ | |
475 | u_int16_t drAtrb; /* volume attributes */ | |
476 | u_int16_t drNmFls; /* number of files in root folder */ | |
477 | u_int16_t drVBMSt; /* first block of volume bitmap */ | |
478 | u_int16_t drAllocPtr; /* start of next allocation search */ | |
479 | u_int16_t drNmAlBlks; /* number of allocation blocks in volume */ | |
480 | u_int32_t drAlBlkSiz; /* size (in bytes) of allocation blocks */ | |
481 | u_int32_t drClpSiz; /* default clump size */ | |
482 | u_int16_t drAlBlSt; /* first allocation block in volume */ | |
483 | u_int32_t drNxtCNID; /* next unused catalog node ID */ | |
484 | u_int16_t drFreeBks; /* number of unused allocation blocks */ | |
485 | u_char drVN[kHFSMaxVolumeNameChars + 1]; /* volume name */ | |
486 | u_int32_t drVolBkUp; /* date and time of last backup */ | |
487 | u_int16_t drVSeqNum; /* volume backup sequence number */ | |
488 | u_int32_t drWrCnt; /* volume write count */ | |
489 | u_int32_t drXTClpSiz; /* clump size for extents overflow file */ | |
490 | u_int32_t drCTClpSiz; /* clump size for catalog file */ | |
491 | u_int16_t drNmRtDirs; /* number of directories in root folder */ | |
492 | u_int32_t drFilCnt; /* number of files in volume */ | |
493 | u_int32_t drDirCnt; /* number of directories in volume */ | |
494 | u_int32_t drFndrInfo[8]; /* information used by the Finder */ | |
495 | u_int16_t drEmbedSigWord; /* embedded volume signature (formerly drVCSize) */ | |
496 | HFSExtentDescriptor drEmbedExtent; /* embedded volume location and size (formerly drVBMCSize and drCtlCSize) */ | |
497 | u_int32_t drXTFlSize; /* size of extents overflow file */ | |
498 | HFSExtentRecord drXTExtRec; /* extent record for extents overflow file */ | |
499 | u_int32_t drCTFlSize; /* size of catalog file */ | |
500 | HFSExtentRecord drCTExtRec; /* extent record for catalog file */ | |
501 | }; | |
502 | typedef struct HFSMasterDirectoryBlock HFSMasterDirectoryBlock; | |
503 | ||
504 | ||
505 | /* HFS Plus Volume Header - 512 bytes */ | |
506 | /* Stored at sector #2 (3rd sector) and second-to-last sector. */ | |
507 | struct HFSPlusVolumeHeader { | |
508 | u_int16_t signature; /* == kHFSPlusSigWord */ | |
509 | u_int16_t version; /* == kHFSPlusVersion */ | |
510 | u_int32_t attributes; /* volume attributes */ | |
511 | u_int32_t lastMountedVersion; /* implementation version which last mounted volume */ | |
512 | u_int32_t reserved; /* reserved - initialized as zero */ | |
513 | ||
514 | u_int32_t createDate; /* date and time of volume creation */ | |
515 | u_int32_t modifyDate; /* date and time of last modification */ | |
516 | u_int32_t backupDate; /* date and time of last backup */ | |
517 | u_int32_t checkedDate; /* date and time of last disk check */ | |
518 | ||
519 | u_int32_t fileCount; /* number of files in volume */ | |
520 | u_int32_t folderCount; /* number of directories in volume */ | |
521 | ||
522 | u_int32_t blockSize; /* size (in bytes) of allocation blocks */ | |
523 | u_int32_t totalBlocks; /* number of allocation blocks in volume (includes this header and VBM*/ | |
524 | u_int32_t freeBlocks; /* number of unused allocation blocks */ | |
525 | ||
526 | u_int32_t nextAllocation; /* start of next allocation search */ | |
527 | u_int32_t rsrcClumpSize; /* default resource fork clump size */ | |
528 | u_int32_t dataClumpSize; /* default data fork clump size */ | |
529 | u_int32_t nextCatalogID; /* next unused catalog node ID */ | |
530 | ||
531 | u_int32_t writeCount; /* volume write count */ | |
532 | u_int64_t encodingsBitmap; /* which encodings have been use on this volume */ | |
533 | ||
534 | u_int8_t finderInfo[32]; /* information used by the Finder */ | |
535 | ||
536 | HFSPlusForkData allocationFile; /* allocation bitmap file */ | |
537 | HFSPlusForkData extentsFile; /* extents B-tree file */ | |
538 | HFSPlusForkData catalogFile; /* catalog B-tree file */ | |
539 | HFSPlusForkData attributesFile; /* extended attributes B-tree file */ | |
540 | HFSPlusForkData startupFile; /* boot file (secondary loader) */ | |
541 | }; | |
542 | typedef struct HFSPlusVolumeHeader HFSPlusVolumeHeader; | |
543 | ||
544 | ||
545 | /* B-tree structures */ | |
546 | ||
547 | enum BTreeKeyLimits{ | |
548 | kMaxKeyLength = 520 | |
549 | }; | |
550 | ||
551 | union BTreeKey{ | |
552 | u_int8_t length8; | |
553 | u_int16_t length16; | |
554 | u_int8_t rawData [kMaxKeyLength+2]; | |
555 | }; | |
556 | typedef union BTreeKey BTreeKey; | |
557 | ||
558 | /* BTNodeDescriptor -- Every B-tree node starts with these fields. */ | |
559 | struct BTNodeDescriptor { | |
560 | u_int32_t fLink; /* next node at this level*/ | |
561 | u_int32_t bLink; /* previous node at this level*/ | |
562 | int8_t kind; /* kind of node (leaf, index, header, map)*/ | |
563 | u_int8_t height; /* zero for header, map; child is one more than parent*/ | |
564 | u_int16_t numRecords; /* number of records in this node*/ | |
565 | u_int16_t reserved; /* reserved - initialized as zero */ | |
566 | }; | |
567 | typedef struct BTNodeDescriptor BTNodeDescriptor; | |
568 | ||
569 | /* Constants for BTNodeDescriptor kind */ | |
570 | enum { | |
571 | kBTLeafNode = -1, | |
572 | kBTIndexNode = 0, | |
573 | kBTHeaderNode = 1, | |
574 | kBTMapNode = 2 | |
575 | }; | |
576 | ||
577 | /* BTHeaderRec -- The first record of a B-tree header node */ | |
578 | struct BTHeaderRec { | |
579 | u_int16_t treeDepth; /* maximum height (usually leaf nodes) */ | |
580 | u_int32_t rootNode; /* node number of root node */ | |
581 | u_int32_t leafRecords; /* number of leaf records in all leaf nodes */ | |
582 | u_int32_t firstLeafNode; /* node number of first leaf node */ | |
583 | u_int32_t lastLeafNode; /* node number of last leaf node */ | |
584 | u_int16_t nodeSize; /* size of a node, in bytes */ | |
585 | u_int16_t maxKeyLength; /* reserved */ | |
586 | u_int32_t totalNodes; /* total number of nodes in tree */ | |
587 | u_int32_t freeNodes; /* number of unused (free) nodes in tree */ | |
588 | u_int16_t reserved1; /* unused */ | |
589 | u_int32_t clumpSize; /* reserved */ | |
590 | u_int8_t btreeType; /* reserved */ | |
591 | u_int8_t reserved2; /* reserved */ | |
592 | u_int32_t attributes; /* persistent attributes about the tree */ | |
593 | u_int32_t reserved3[16]; /* reserved */ | |
594 | }; | |
595 | typedef struct BTHeaderRec BTHeaderRec; | |
596 | ||
597 | /* Constants for BTHeaderRec attributes */ | |
598 | enum { | |
599 | kBTBadCloseMask = 0x00000001, /* reserved */ | |
600 | kBTBigKeysMask = 0x00000002, /* key length field is 16 bits */ | |
601 | kBTVariableIndexKeysMask = 0x00000004 /* keys in index nodes are variable length */ | |
602 | }; | |
603 | ||
604 | #pragma options align=reset | |
605 | ||
606 | #ifdef __cplusplus | |
607 | } | |
608 | #endif | |
609 | ||
610 | #endif /* __HFS_FORMAT__ */ |