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