2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #ifndef __HFS_FORMAT__
29 #define __HFS_FORMAT__
31 #include <sys/types.h>
32 #include <sys/appleapiopts.h>
37 * This file describes the on-disk format for HFS and HFS Plus volumes.
38 * The HFS Plus volume format is desciibed in detail in Apple Technote 1150.
40 * http://developer.apple.com/technotes/tn/tn1150.html
48 /* some on-disk hfs structures have 68K alignment (misaligned) */
50 /* Signatures used to differentiate between HFS and HFS Plus volumes */
52 kHFSSigWord
= 0x4244, /* 'BD' in ASCII */
53 kHFSPlusSigWord
= 0x482B, /* 'H+' in ASCII */
54 kHFSXSigWord
= 0x4858, /* 'HX' in ASCII */
56 kHFSPlusVersion
= 0x0004, /* 'H+' volumes are version 4 only */
57 kHFSXVersion
= 0x0005, /* 'HX' volumes start with version 5 */
59 kHFSPlusMountVersion
= 0x31302E30, /* '10.0' for Mac OS X */
60 kHFSJMountVersion
= 0x4846534a, /* 'HFSJ' for journaled HFS+ on OS X */
61 kFSKMountVersion
= 0x46534b21 /* 'FSK!' for failed journal replay */
65 #ifdef __APPLE_API_PRIVATE
67 * Mac OS X has two special directories on HFS+ volumes for hardlinked files
68 * and hardlinked directories as well as for open-unlinked files.
70 * These directories and their contents are not exported from the filesystem
73 #define HFSPLUSMETADATAFOLDER "\xE2\x90\x80\xE2\x90\x80\xE2\x90\x80\xE2\x90\x80HFS+ Private Data"
74 #define HFSPLUS_DIR_METADATA_FOLDER ".HFS+ Private Directory Data\xd"
77 * Files in the "HFS+ Private Data" folder have one of the following prefixes
78 * followed by a decimal number (no leading zeros) for the file ID.
80 * Note: Earlier version of Mac OS X used a 32 bit random number for the link
81 * ref number instead of the file id.
83 * e.g. iNode7182000 and temp3296
85 #define HFS_INODE_PREFIX "iNode"
86 #define HFS_DELETE_PREFIX "temp"
89 * Files in the ".HFS+ Private Directory Data" folder have the following
90 * prefix followed by a decimal number (no leading zeros) for the file ID.
94 #define HFS_DIRINODE_PREFIX "dir_"
97 * Hardlink inodes save the head of the link chain in
98 * an extended attribute named FIRST_LINK_XATTR_NAME.
99 * The attribute data is the decimal value in ASCII
100 * of the cnid for the first link in the chain.
102 * This extended attribute is private (i.e. its not
103 * exported in the getxattr/listxattr POSIX APIs).
105 #define FIRST_LINK_XATTR_NAME "com.apple.system.hfs.firstlink"
106 #define FIRST_LINK_XATTR_REC_SIZE (sizeof(HFSPlusAttrData) - 2 + 12)
108 #endif /* __APPLE_API_PRIVATE */
111 * Indirect link files (hard links) have the following type/creator.
114 kHardLinkFileType
= 0x686C6E6B, /* 'hlnk' */
115 kHFSPlusCreator
= 0x6866732B /* 'hfs+' */
120 * File type and creator for symbolic links
123 kSymLinkFileType
= 0x736C6E6B, /* 'slnk' */
124 kSymLinkCreator
= 0x72686170 /* 'rhap' */
128 #ifndef _HFSUNISTR255_DEFINED_
129 #define _HFSUNISTR255_DEFINED_
130 /* Unicode strings are used for HFS Plus file and folder names */
131 struct HFSUniStr255
{
132 u_int16_t length
; /* number of unicode characters */
133 u_int16_t unicode
[255]; /* unicode characters */
134 } __attribute__((aligned(2), packed
));
135 typedef struct HFSUniStr255 HFSUniStr255
;
136 typedef const HFSUniStr255
*ConstHFSUniStr255Param
;
137 #endif /* _HFSUNISTR255_DEFINED_ */
140 kHFSMaxVolumeNameChars
= 27,
141 kHFSMaxFileNameChars
= 31,
142 kHFSPlusMaxFileNameChars
= 255
146 /* Extent overflow file data structures */
149 struct HFSExtentKey
{
150 u_int8_t keyLength
; /* length of key, excluding this field */
151 u_int8_t forkType
; /* 0 = data fork, FF = resource fork */
152 u_int32_t fileID
; /* file ID */
153 u_int16_t startBlock
; /* first file allocation block number in this extent */
154 } __attribute__((aligned(2), packed
));
155 typedef struct HFSExtentKey HFSExtentKey
;
157 /* HFS Plus Extent key */
158 struct HFSPlusExtentKey
{
159 u_int16_t keyLength
; /* length of key, excluding this field */
160 u_int8_t forkType
; /* 0 = data fork, FF = resource fork */
161 u_int8_t pad
; /* make the other fields align on 32-bit boundary */
162 u_int32_t fileID
; /* file ID */
163 u_int32_t startBlock
; /* first file allocation block number in this extent */
164 } __attribute__((aligned(2), packed
));
165 typedef struct HFSPlusExtentKey HFSPlusExtentKey
;
167 /* Number of extent descriptors per extent record */
169 kHFSExtentDensity
= 3,
170 kHFSPlusExtentDensity
= 8
173 /* HFS extent descriptor */
174 struct HFSExtentDescriptor
{
175 u_int16_t startBlock
; /* first allocation block */
176 u_int16_t blockCount
; /* number of allocation blocks */
177 } __attribute__((aligned(2), packed
));
178 typedef struct HFSExtentDescriptor HFSExtentDescriptor
;
180 /* HFS Plus extent descriptor */
181 struct HFSPlusExtentDescriptor
{
182 u_int32_t startBlock
; /* first allocation block */
183 u_int32_t blockCount
; /* number of allocation blocks */
184 } __attribute__((aligned(2), packed
));
185 typedef struct HFSPlusExtentDescriptor HFSPlusExtentDescriptor
;
187 /* HFS extent record */
188 typedef HFSExtentDescriptor HFSExtentRecord
[3];
190 /* HFS Plus extent record */
191 typedef HFSPlusExtentDescriptor HFSPlusExtentRecord
[8];
194 /* Finder information */
195 struct FndrFileInfo
{
196 u_int32_t fdType
; /* file type */
197 u_int32_t fdCreator
; /* file creator */
198 u_int16_t fdFlags
; /* Finder flags */
200 int16_t v
; /* file's location */
204 } __attribute__((aligned(2), packed
));
205 typedef struct FndrFileInfo FndrFileInfo
;
208 struct { /* folder's window rectangle */
214 unsigned short frFlags
; /* Finder flags */
216 u_int16_t v
; /* folder's location */
220 } __attribute__((aligned(2), packed
));
221 typedef struct FndrDirInfo FndrDirInfo
;
223 struct FndrOpaqueInfo
{
225 } __attribute__((aligned(2), packed
));
226 typedef struct FndrOpaqueInfo FndrOpaqueInfo
;
229 /* HFS Plus Fork data info - 80 bytes */
230 struct HFSPlusForkData
{
231 u_int64_t logicalSize
; /* fork's logical size in bytes */
232 u_int32_t clumpSize
; /* fork's clump size in bytes */
233 u_int32_t totalBlocks
; /* total blocks used by this fork */
234 HFSPlusExtentRecord extents
; /* initial set of extents */
235 } __attribute__((aligned(2), packed
));
236 typedef struct HFSPlusForkData HFSPlusForkData
;
239 /* Mac OS X has 16 bytes worth of "BSD" info.
241 * Note: Mac OS 9 implementations and applications
242 * should preserve, but not change, this information.
244 struct HFSPlusBSDInfo
{
245 u_int32_t ownerID
; /* user-id of owner or hard link chain previous link */
246 u_int32_t groupID
; /* group-id of owner or hard link chain next link */
247 u_int8_t adminFlags
; /* super-user changeable flags */
248 u_int8_t ownerFlags
; /* owner changeable flags */
249 u_int16_t fileMode
; /* file type and permission bits */
251 u_int32_t iNodeNum
; /* indirect node number (hard links only) */
252 u_int32_t linkCount
; /* links that refer to this indirect node */
253 u_int32_t rawDevice
; /* special file device (FBLK and FCHR only) */
255 } __attribute__((aligned(2), packed
));
256 typedef struct HFSPlusBSDInfo HFSPlusBSDInfo
;
259 * Hardlink "links" resolve to an inode
260 * and the actual uid/gid comes from that
263 * We repurpose the links's uid/gid fields
264 * for the hardlink link chain. The chain
265 * consists of a doubly linked list of file
269 #define hl_firstLinkID reserved1 /* Valid only if HasLinkChain flag is set (indirect nodes only) */
271 #define hl_prevLinkID bsdInfo.ownerID /* Valid only if HasLinkChain flag is set */
272 #define hl_nextLinkID bsdInfo.groupID /* Valid only if HasLinkChain flag is set */
274 #define hl_linkReference bsdInfo.special.iNodeNum
275 #define hl_linkCount bsdInfo.special.linkCount
278 /* Catalog file data structures */
281 kHFSRootParentID
= 1, /* Parent ID of the root folder */
282 kHFSRootFolderID
= 2, /* Folder ID of the root folder */
283 kHFSExtentsFileID
= 3, /* File ID of the extents file */
284 kHFSCatalogFileID
= 4, /* File ID of the catalog file */
285 kHFSBadBlockFileID
= 5, /* File ID of the bad allocation block file */
286 kHFSAllocationFileID
= 6, /* File ID of the allocation file (HFS Plus only) */
287 kHFSStartupFileID
= 7, /* File ID of the startup file (HFS Plus only) */
288 kHFSAttributesFileID
= 8, /* File ID of the attribute file (HFS Plus only) */
289 kHFSAttributeDataFileID
= 13, /* Used in Mac OS X runtime for extent based attributes */
290 /* kHFSAttributeDataFileID is never stored on disk. */
291 kHFSRepairCatalogFileID
= 14, /* Used when rebuilding Catalog B-tree */
292 kHFSBogusExtentFileID
= 15, /* Used for exchanging extents in extents file */
293 kHFSFirstUserCatalogNodeID
= 16
296 /* HFS catalog key */
297 struct HFSCatalogKey
{
298 u_int8_t keyLength
; /* key length (in bytes) */
299 u_int8_t reserved
; /* reserved (set to zero) */
300 u_int32_t parentID
; /* parent folder ID */
301 u_int8_t nodeName
[kHFSMaxFileNameChars
+ 1]; /* catalog node name */
302 } __attribute__((aligned(2), packed
));
303 typedef struct HFSCatalogKey HFSCatalogKey
;
305 /* HFS Plus catalog key */
306 struct HFSPlusCatalogKey
{
307 u_int16_t keyLength
; /* key length (in bytes) */
308 u_int32_t parentID
; /* parent folder ID */
309 HFSUniStr255 nodeName
; /* catalog node name */
310 } __attribute__((aligned(2), packed
));
311 typedef struct HFSPlusCatalogKey HFSPlusCatalogKey
;
313 /* Catalog record types */
315 /* HFS Catalog Records */
316 kHFSFolderRecord
= 0x0100, /* Folder record */
317 kHFSFileRecord
= 0x0200, /* File record */
318 kHFSFolderThreadRecord
= 0x0300, /* Folder thread record */
319 kHFSFileThreadRecord
= 0x0400, /* File thread record */
321 /* HFS Plus Catalog Records */
322 kHFSPlusFolderRecord
= 1, /* Folder record */
323 kHFSPlusFileRecord
= 2, /* File record */
324 kHFSPlusFolderThreadRecord
= 3, /* Folder thread record */
325 kHFSPlusFileThreadRecord
= 4 /* File thread record */
329 /* Catalog file record flags */
331 kHFSFileLockedBit
= 0x0000, /* file is locked and cannot be written to */
332 kHFSFileLockedMask
= 0x0001,
334 kHFSThreadExistsBit
= 0x0001, /* a file thread record exists for this file */
335 kHFSThreadExistsMask
= 0x0002,
337 kHFSHasAttributesBit
= 0x0002, /* object has extended attributes */
338 kHFSHasAttributesMask
= 0x0004,
340 kHFSHasSecurityBit
= 0x0003, /* object has security data (ACLs) */
341 kHFSHasSecurityMask
= 0x0008,
343 kHFSHasFolderCountBit
= 0x0004, /* only for HFSX, folder maintains a separate sub-folder count */
344 kHFSHasFolderCountMask
= 0x0010, /* (sum of folder records and directory hard links) */
346 kHFSHasLinkChainBit
= 0x0005, /* has hardlink chain (inode or link) */
347 kHFSHasLinkChainMask
= 0x0020,
349 kHFSHasChildLinkBit
= 0x0006, /* folder has a child that's a dir link */
350 kHFSHasChildLinkMask
= 0x0040
354 /* HFS catalog folder record - 70 bytes */
355 struct HFSCatalogFolder
{
356 int16_t recordType
; /* == kHFSFolderRecord */
357 u_int16_t flags
; /* folder flags */
358 u_int16_t valence
; /* folder valence */
359 u_int32_t folderID
; /* folder ID */
360 u_int32_t createDate
; /* date and time of creation */
361 u_int32_t modifyDate
; /* date and time of last modification */
362 u_int32_t backupDate
; /* date and time of last backup */
363 FndrDirInfo userInfo
; /* Finder information */
364 FndrOpaqueInfo finderInfo
; /* additional Finder information */
365 u_int32_t reserved
[4]; /* reserved - initialized as zero */
366 } __attribute__((aligned(2), packed
));
367 typedef struct HFSCatalogFolder HFSCatalogFolder
;
369 /* HFS Plus catalog folder record - 88 bytes */
370 struct HFSPlusCatalogFolder
{
371 int16_t recordType
; /* == kHFSPlusFolderRecord */
372 u_int16_t flags
; /* file flags */
373 u_int32_t valence
; /* folder's item count */
374 u_int32_t folderID
; /* folder ID */
375 u_int32_t createDate
; /* date and time of creation */
376 u_int32_t contentModDate
; /* date and time of last content modification */
377 u_int32_t attributeModDate
; /* date and time of last attribute modification */
378 u_int32_t accessDate
; /* date and time of last access (MacOS X only) */
379 u_int32_t backupDate
; /* date and time of last backup */
380 HFSPlusBSDInfo bsdInfo
; /* permissions (for MacOS X) */
381 FndrDirInfo userInfo
; /* Finder information */
382 FndrOpaqueInfo finderInfo
; /* additional Finder information */
383 u_int32_t textEncoding
; /* hint for name conversions */
384 u_int32_t folderCount
; /* number of enclosed folders, active when HasFolderCount is set */
385 } __attribute__((aligned(2), packed
));
386 typedef struct HFSPlusCatalogFolder HFSPlusCatalogFolder
;
388 /* HFS catalog file record - 102 bytes */
389 struct HFSCatalogFile
{
390 int16_t recordType
; /* == kHFSFileRecord */
391 u_int8_t flags
; /* file flags */
392 int8_t fileType
; /* file type (unused ?) */
393 FndrFileInfo userInfo
; /* Finder information */
394 u_int32_t fileID
; /* file ID */
395 u_int16_t dataStartBlock
; /* not used - set to zero */
396 int32_t dataLogicalSize
; /* logical EOF of data fork */
397 int32_t dataPhysicalSize
; /* physical EOF of data fork */
398 u_int16_t rsrcStartBlock
; /* not used - set to zero */
399 int32_t rsrcLogicalSize
; /* logical EOF of resource fork */
400 int32_t rsrcPhysicalSize
; /* physical EOF of resource fork */
401 u_int32_t createDate
; /* date and time of creation */
402 u_int32_t modifyDate
; /* date and time of last modification */
403 u_int32_t backupDate
; /* date and time of last backup */
404 FndrOpaqueInfo finderInfo
; /* additional Finder information */
405 u_int16_t clumpSize
; /* file clump size (not used) */
406 HFSExtentRecord dataExtents
; /* first data fork extent record */
407 HFSExtentRecord rsrcExtents
; /* first resource fork extent record */
408 u_int32_t reserved
; /* reserved - initialized as zero */
409 } __attribute__((aligned(2), packed
));
410 typedef struct HFSCatalogFile HFSCatalogFile
;
412 /* HFS Plus catalog file record - 248 bytes */
413 struct HFSPlusCatalogFile
{
414 int16_t recordType
; /* == kHFSPlusFileRecord */
415 u_int16_t flags
; /* file flags */
416 u_int32_t reserved1
; /* reserved - initialized as zero */
417 u_int32_t fileID
; /* file ID */
418 u_int32_t createDate
; /* date and time of creation */
419 u_int32_t contentModDate
; /* date and time of last content modification */
420 u_int32_t attributeModDate
; /* date and time of last attribute modification */
421 u_int32_t accessDate
; /* date and time of last access (MacOS X only) */
422 u_int32_t backupDate
; /* date and time of last backup */
423 HFSPlusBSDInfo bsdInfo
; /* permissions (for MacOS X) */
424 FndrFileInfo userInfo
; /* Finder information */
425 FndrOpaqueInfo finderInfo
; /* additional Finder information */
426 u_int32_t textEncoding
; /* hint for name conversions */
427 u_int32_t reserved2
; /* reserved - initialized as zero */
429 /* Note: these start on double long (64 bit) boundary */
430 HFSPlusForkData dataFork
; /* size and block data for data fork */
431 HFSPlusForkData resourceFork
; /* size and block data for resource fork */
432 } __attribute__((aligned(2), packed
));
433 typedef struct HFSPlusCatalogFile HFSPlusCatalogFile
;
435 /* HFS catalog thread record - 46 bytes */
436 struct HFSCatalogThread
{
437 int16_t recordType
; /* == kHFSFolderThreadRecord or kHFSFileThreadRecord */
438 int32_t reserved
[2]; /* reserved - initialized as zero */
439 u_int32_t parentID
; /* parent ID for this catalog node */
440 u_int8_t nodeName
[kHFSMaxFileNameChars
+ 1]; /* name of this catalog node */
441 } __attribute__((aligned(2), packed
));
442 typedef struct HFSCatalogThread HFSCatalogThread
;
444 /* HFS Plus catalog thread record -- 264 bytes */
445 struct HFSPlusCatalogThread
{
446 int16_t recordType
; /* == kHFSPlusFolderThreadRecord or kHFSPlusFileThreadRecord */
447 int16_t reserved
; /* reserved - initialized as zero */
448 u_int32_t parentID
; /* parent ID for this catalog node */
449 HFSUniStr255 nodeName
; /* name of this catalog node (variable length) */
450 } __attribute__((aligned(2), packed
));
451 typedef struct HFSPlusCatalogThread HFSPlusCatalogThread
;
453 #ifdef __APPLE_API_UNSTABLE
455 These are the types of records in the attribute B-tree. The values were
456 chosen so that they wouldn't conflict with the catalog record types.
459 kHFSPlusAttrInlineData
= 0x10, /* attributes whose data fits in a b-tree node */
460 kHFSPlusAttrForkData
= 0x20, /* extent based attributes (data lives in extents) */
461 kHFSPlusAttrExtents
= 0x30 /* overflow extents for large attributes */
467 For larger attributes, whose value is stored in allocation blocks.
468 If the attribute has more than 8 extents, there will be additional
469 records (of type HFSPlusAttrExtents) for this attribute.
471 struct HFSPlusAttrForkData
{
472 u_int32_t recordType
; /* == kHFSPlusAttrForkData*/
474 HFSPlusForkData theFork
; /* size and first extents of value*/
475 } __attribute__((aligned(2), packed
));
476 typedef struct HFSPlusAttrForkData HFSPlusAttrForkData
;
480 This record contains information about overflow extents for large,
481 fragmented attributes.
483 struct HFSPlusAttrExtents
{
484 u_int32_t recordType
; /* == kHFSPlusAttrExtents*/
486 HFSPlusExtentRecord extents
; /* additional extents*/
487 } __attribute__((aligned(2), packed
));
488 typedef struct HFSPlusAttrExtents HFSPlusAttrExtents
;
491 * Atrributes B-tree Data Record
493 * For small attributes, whose entire value is stored
494 * within a single B-tree record.
496 struct HFSPlusAttrData
{
497 u_int32_t recordType
; /* == kHFSPlusAttrInlineData */
498 u_int32_t reserved
[2];
499 u_int32_t attrSize
; /* size of attribute data in bytes */
500 u_int8_t attrData
[2]; /* variable length */
501 } __attribute__((aligned(2), packed
));
502 typedef struct HFSPlusAttrData HFSPlusAttrData
;
505 /* HFSPlusAttrInlineData is obsolete use HFSPlusAttrData instead */
506 struct HFSPlusAttrInlineData
{
507 u_int32_t recordType
;
509 u_int32_t logicalSize
;
510 u_int8_t userData
[2];
511 } __attribute__((aligned(2), packed
));
512 typedef struct HFSPlusAttrInlineData HFSPlusAttrInlineData
;
515 /* A generic Attribute Record*/
516 union HFSPlusAttrRecord
{
517 u_int32_t recordType
;
518 HFSPlusAttrInlineData inlineData
; /* NOT USED */
519 HFSPlusAttrData attrData
;
520 HFSPlusAttrForkData forkData
;
521 HFSPlusAttrExtents overflowExtents
;
523 typedef union HFSPlusAttrRecord HFSPlusAttrRecord
;
526 enum { kHFSMaxAttrNameLen
= 127 };
527 struct HFSPlusAttrKey
{
528 u_int16_t keyLength
; /* key length (in bytes) */
529 u_int16_t pad
; /* set to zero */
530 u_int32_t fileID
; /* file associated with attribute */
531 u_int32_t startBlock
; /* first allocation block number for extents */
532 u_int16_t attrNameLen
; /* number of unicode characters */
533 u_int16_t attrName
[kHFSMaxAttrNameLen
]; /* attribute name (Unicode) */
534 } __attribute__((aligned(2), packed
));
535 typedef struct HFSPlusAttrKey HFSPlusAttrKey
;
537 #define kHFSPlusAttrKeyMaximumLength (sizeof(HFSPlusAttrKey) - sizeof(u_int16_t))
538 #define kHFSPlusAttrKeyMinimumLength (kHFSPlusAttrKeyMaximumLength - kHFSMaxAttrNameLen*sizeof(u_int16_t))
540 #endif /* __APPLE_API_UNSTABLE */
543 /* Key and node lengths */
545 kHFSPlusExtentKeyMaximumLength
= sizeof(HFSPlusExtentKey
) - sizeof(u_int16_t
),
546 kHFSExtentKeyMaximumLength
= sizeof(HFSExtentKey
) - sizeof(u_int8_t
),
547 kHFSPlusCatalogKeyMaximumLength
= sizeof(HFSPlusCatalogKey
) - sizeof(u_int16_t
),
548 kHFSPlusCatalogKeyMinimumLength
= kHFSPlusCatalogKeyMaximumLength
- sizeof(HFSUniStr255
) + sizeof(u_int16_t
),
549 kHFSCatalogKeyMaximumLength
= sizeof(HFSCatalogKey
) - sizeof(u_int8_t
),
550 kHFSCatalogKeyMinimumLength
= kHFSCatalogKeyMaximumLength
- (kHFSMaxFileNameChars
+ 1) + sizeof(u_int8_t
),
551 kHFSPlusCatalogMinNodeSize
= 4096,
552 kHFSPlusExtentMinNodeSize
= 512,
553 kHFSPlusAttrMinNodeSize
= 4096
556 /* HFS and HFS Plus volume attribute bits */
558 /* Bits 0-6 are reserved (always cleared by MountVol call) */
559 kHFSVolumeHardwareLockBit
= 7, /* volume is locked by hardware */
560 kHFSVolumeUnmountedBit
= 8, /* volume was successfully unmounted */
561 kHFSVolumeSparedBlocksBit
= 9, /* volume has bad blocks spared */
562 kHFSVolumeNoCacheRequiredBit
= 10, /* don't cache volume blocks (i.e. RAM or ROM disk) */
563 kHFSBootVolumeInconsistentBit
= 11, /* boot volume is inconsistent (System 7.6 and later) */
564 kHFSCatalogNodeIDsReusedBit
= 12,
565 kHFSVolumeJournaledBit
= 13, /* this volume has a journal on it */
566 kHFSVolumeInconsistentBit
= 14, /* serious inconsistencies detected at runtime */
567 kHFSVolumeSoftwareLockBit
= 15, /* volume is locked by software */
569 kHFSVolumeHardwareLockMask
= 1 << kHFSVolumeHardwareLockBit
,
570 kHFSVolumeUnmountedMask
= 1 << kHFSVolumeUnmountedBit
,
571 kHFSVolumeSparedBlocksMask
= 1 << kHFSVolumeSparedBlocksBit
,
572 kHFSVolumeNoCacheRequiredMask
= 1 << kHFSVolumeNoCacheRequiredBit
,
573 kHFSBootVolumeInconsistentMask
= 1 << kHFSBootVolumeInconsistentBit
,
574 kHFSCatalogNodeIDsReusedMask
= 1 << kHFSCatalogNodeIDsReusedBit
,
575 kHFSVolumeJournaledMask
= 1 << kHFSVolumeJournaledBit
,
576 kHFSVolumeInconsistentMask
= 1 << kHFSVolumeInconsistentBit
,
577 kHFSVolumeSoftwareLockMask
= 1 << kHFSVolumeSoftwareLockBit
,
578 kHFSMDBAttributesMask
= 0x8380
582 /* HFS Master Directory Block - 162 bytes */
583 /* Stored at sector #2 (3rd sector) and second-to-last sector. */
584 struct HFSMasterDirectoryBlock
{
585 u_int16_t drSigWord
; /* == kHFSSigWord */
586 u_int32_t drCrDate
; /* date and time of volume creation */
587 u_int32_t drLsMod
; /* date and time of last modification */
588 u_int16_t drAtrb
; /* volume attributes */
589 u_int16_t drNmFls
; /* number of files in root folder */
590 u_int16_t drVBMSt
; /* first block of volume bitmap */
591 u_int16_t drAllocPtr
; /* start of next allocation search */
592 u_int16_t drNmAlBlks
; /* number of allocation blocks in volume */
593 u_int32_t drAlBlkSiz
; /* size (in bytes) of allocation blocks */
594 u_int32_t drClpSiz
; /* default clump size */
595 u_int16_t drAlBlSt
; /* first allocation block in volume */
596 u_int32_t drNxtCNID
; /* next unused catalog node ID */
597 u_int16_t drFreeBks
; /* number of unused allocation blocks */
598 u_int8_t drVN
[kHFSMaxVolumeNameChars
+ 1]; /* volume name */
599 u_int32_t drVolBkUp
; /* date and time of last backup */
600 u_int16_t drVSeqNum
; /* volume backup sequence number */
601 u_int32_t drWrCnt
; /* volume write count */
602 u_int32_t drXTClpSiz
; /* clump size for extents overflow file */
603 u_int32_t drCTClpSiz
; /* clump size for catalog file */
604 u_int16_t drNmRtDirs
; /* number of directories in root folder */
605 u_int32_t drFilCnt
; /* number of files in volume */
606 u_int32_t drDirCnt
; /* number of directories in volume */
607 u_int32_t drFndrInfo
[8]; /* information used by the Finder */
608 u_int16_t drEmbedSigWord
; /* embedded volume signature (formerly drVCSize) */
609 HFSExtentDescriptor drEmbedExtent
; /* embedded volume location and size (formerly drVBMCSize and drCtlCSize) */
610 u_int32_t drXTFlSize
; /* size of extents overflow file */
611 HFSExtentRecord drXTExtRec
; /* extent record for extents overflow file */
612 u_int32_t drCTFlSize
; /* size of catalog file */
613 HFSExtentRecord drCTExtRec
; /* extent record for catalog file */
614 } __attribute__((aligned(2), packed
));
615 typedef struct HFSMasterDirectoryBlock HFSMasterDirectoryBlock
;
618 #ifdef __APPLE_API_UNSTABLE
619 #define SET_HFS_TEXT_ENCODING(hint) \
620 (0x656e6300 | ((hint) & 0xff))
621 #define GET_HFS_TEXT_ENCODING(hint) \
622 (((hint) & 0xffffff00) == 0x656e6300 ? (hint) & 0x000000ff : 0xffffffffU)
623 #endif /* __APPLE_API_UNSTABLE */
626 /* HFS Plus Volume Header - 512 bytes */
627 /* Stored at sector #2 (3rd sector) and second-to-last sector. */
628 struct HFSPlusVolumeHeader
{
629 u_int16_t signature
; /* == kHFSPlusSigWord */
630 u_int16_t version
; /* == kHFSPlusVersion */
631 u_int32_t attributes
; /* volume attributes */
632 u_int32_t lastMountedVersion
; /* implementation version which last mounted volume */
633 u_int32_t journalInfoBlock
; /* block addr of journal info (if volume is journaled, zero otherwise) */
635 u_int32_t createDate
; /* date and time of volume creation */
636 u_int32_t modifyDate
; /* date and time of last modification */
637 u_int32_t backupDate
; /* date and time of last backup */
638 u_int32_t checkedDate
; /* date and time of last disk check */
640 u_int32_t fileCount
; /* number of files in volume */
641 u_int32_t folderCount
; /* number of directories in volume */
643 u_int32_t blockSize
; /* size (in bytes) of allocation blocks */
644 u_int32_t totalBlocks
; /* number of allocation blocks in volume (includes this header and VBM*/
645 u_int32_t freeBlocks
; /* number of unused allocation blocks */
647 u_int32_t nextAllocation
; /* start of next allocation search */
648 u_int32_t rsrcClumpSize
; /* default resource fork clump size */
649 u_int32_t dataClumpSize
; /* default data fork clump size */
650 u_int32_t nextCatalogID
; /* next unused catalog node ID */
652 u_int32_t writeCount
; /* volume write count */
653 u_int64_t encodingsBitmap
; /* which encodings have been use on this volume */
655 u_int8_t finderInfo
[32]; /* information used by the Finder */
657 HFSPlusForkData allocationFile
; /* allocation bitmap file */
658 HFSPlusForkData extentsFile
; /* extents B-tree file */
659 HFSPlusForkData catalogFile
; /* catalog B-tree file */
660 HFSPlusForkData attributesFile
; /* extended attributes B-tree file */
661 HFSPlusForkData startupFile
; /* boot file (secondary loader) */
662 } __attribute__((aligned(2), packed
));
663 typedef struct HFSPlusVolumeHeader HFSPlusVolumeHeader
;
666 /* B-tree structures */
675 u_int8_t rawData
[kMaxKeyLength
+2];
677 typedef union BTreeKey BTreeKey
;
679 /* BTNodeDescriptor -- Every B-tree node starts with these fields. */
680 struct BTNodeDescriptor
{
681 u_int32_t fLink
; /* next node at this level*/
682 u_int32_t bLink
; /* previous node at this level*/
683 int8_t kind
; /* kind of node (leaf, index, header, map)*/
684 u_int8_t height
; /* zero for header, map; child is one more than parent*/
685 u_int16_t numRecords
; /* number of records in this node*/
686 u_int16_t reserved
; /* reserved - initialized as zero */
687 } __attribute__((aligned(2), packed
));
688 typedef struct BTNodeDescriptor BTNodeDescriptor
;
690 /* Constants for BTNodeDescriptor kind */
698 /* BTHeaderRec -- The first record of a B-tree header node */
700 u_int16_t treeDepth
; /* maximum height (usually leaf nodes) */
701 u_int32_t rootNode
; /* node number of root node */
702 u_int32_t leafRecords
; /* number of leaf records in all leaf nodes */
703 u_int32_t firstLeafNode
; /* node number of first leaf node */
704 u_int32_t lastLeafNode
; /* node number of last leaf node */
705 u_int16_t nodeSize
; /* size of a node, in bytes */
706 u_int16_t maxKeyLength
; /* reserved */
707 u_int32_t totalNodes
; /* total number of nodes in tree */
708 u_int32_t freeNodes
; /* number of unused (free) nodes in tree */
709 u_int16_t reserved1
; /* unused */
710 u_int32_t clumpSize
; /* reserved */
711 u_int8_t btreeType
; /* reserved */
712 u_int8_t keyCompareType
; /* Key string Comparison Type */
713 u_int32_t attributes
; /* persistent attributes about the tree */
714 u_int32_t reserved3
[16]; /* reserved */
715 } __attribute__((aligned(2), packed
));
716 typedef struct BTHeaderRec BTHeaderRec
;
718 /* Constants for BTHeaderRec attributes */
720 kBTBadCloseMask
= 0x00000001, /* reserved */
721 kBTBigKeysMask
= 0x00000002, /* key length field is 16 bits */
722 kBTVariableIndexKeysMask
= 0x00000004 /* keys in index nodes are variable length */
726 /* Catalog Key Name Comparison Type */
728 kHFSCaseFolding
= 0xCF, /* case folding (case-insensitive) */
729 kHFSBinaryCompare
= 0xBC /* binary compare (case-sensitive) */
732 /* JournalInfoBlock - Structure that describes where our journal lives */
733 struct JournalInfoBlock
{
735 u_int32_t device_signature
[8]; // signature used to locate our device.
736 u_int64_t offset
; // byte offset to the journal on the device
737 u_int64_t size
; // size in bytes of the journal
738 u_int32_t reserved
[32];
739 } __attribute__((aligned(2), packed
));
740 typedef struct JournalInfoBlock JournalInfoBlock
;
743 kJIJournalInFSMask
= 0x00000001,
744 kJIJournalOnOtherDeviceMask
= 0x00000002,
745 kJIJournalNeedInitMask
= 0x00000004
753 #endif /* __HFS_FORMAT__ */