2 * Copyright (c) 2000-2013 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>
33 #include <hfs/hfs_unistr.h>
38 * This file describes the on-disk format for HFS and HFS Plus volumes.
39 * The HFS Plus volume format is desciibed in detail in Apple Technote 1150.
41 * http://developer.apple.com/technotes/tn/tn1150.html
43 * Note: Starting 10.9, definition of struct HFSUniStr255 exists in hfs_unitstr.h
51 /* some on-disk hfs structures have 68K alignment (misaligned) */
53 /* Signatures used to differentiate between HFS and HFS Plus volumes */
55 kHFSSigWord
= 0x4244, /* 'BD' in ASCII */
56 kHFSPlusSigWord
= 0x482B, /* 'H+' in ASCII */
57 kHFSXSigWord
= 0x4858, /* 'HX' in ASCII */
59 kHFSPlusVersion
= 0x0004, /* 'H+' volumes are version 4 only */
60 kHFSXVersion
= 0x0005, /* 'HX' volumes start with version 5 */
62 kHFSPlusMountVersion
= 0x31302E30, /* '10.0' for Mac OS X */
63 kHFSJMountVersion
= 0x4846534a, /* 'HFSJ' for journaled HFS+ on OS X */
64 kFSKMountVersion
= 0x46534b21 /* 'FSK!' for failed journal replay */
68 #ifdef __APPLE_API_PRIVATE
70 * Mac OS X has two special directories on HFS+ volumes for hardlinked files
71 * and hardlinked directories as well as for open-unlinked files.
73 * These directories and their contents are not exported from the filesystem
76 #define HFSPLUSMETADATAFOLDER "\xE2\x90\x80\xE2\x90\x80\xE2\x90\x80\xE2\x90\x80HFS+ Private Data"
77 #define HFSPLUS_DIR_METADATA_FOLDER ".HFS+ Private Directory Data\xd"
80 * Files in the "HFS+ Private Data" folder have one of the following prefixes
81 * followed by a decimal number (no leading zeros) for the file ID.
83 * Note: Earlier version of Mac OS X used a 32 bit random number for the link
84 * ref number instead of the file id.
86 * e.g. iNode7182000 and temp3296
88 #define HFS_INODE_PREFIX "iNode"
89 #define HFS_DELETE_PREFIX "temp"
92 * Files in the ".HFS+ Private Directory Data" folder have the following
93 * prefix followed by a decimal number (no leading zeros) for the file ID.
97 #define HFS_DIRINODE_PREFIX "dir_"
100 * Hardlink inodes save the head of the link chain in
101 * an extended attribute named FIRST_LINK_XATTR_NAME.
102 * The attribute data is the decimal value in ASCII
103 * of the cnid for the first link in the chain.
105 * This extended attribute is private (i.e. its not
106 * exported in the getxattr/listxattr POSIX APIs).
108 #define FIRST_LINK_XATTR_NAME "com.apple.system.hfs.firstlink"
109 #define FIRST_LINK_XATTR_REC_SIZE (sizeof(HFSPlusAttrData) - 2 + 12)
112 * The name space ID for generating an HFS volume UUID
114 * B3E20F39-F292-11D6-97A4-00306543ECAC
116 #define HFS_UUID_NAMESPACE_ID "\xB3\xE2\x0F\x39\xF2\x92\x11\xD6\x97\xA4\x00\x30\x65\x43\xEC\xAC"
118 #endif /* __APPLE_API_PRIVATE */
121 * Indirect link files (hard links) have the following type/creator.
124 kHardLinkFileType
= 0x686C6E6B, /* 'hlnk' */
125 kHFSPlusCreator
= 0x6866732B /* 'hfs+' */
130 * File type and creator for symbolic links
133 kSymLinkFileType
= 0x736C6E6B, /* 'slnk' */
134 kSymLinkCreator
= 0x72686170 /* 'rhap' */
139 kHFSMaxVolumeNameChars
= 27,
140 kHFSMaxFileNameChars
= 31,
141 kHFSPlusMaxFileNameChars
= 255
145 /* Extent overflow file data structures */
148 struct HFSExtentKey
{
149 u_int8_t keyLength
; /* length of key, excluding this field */
150 u_int8_t forkType
; /* 0 = data fork, FF = resource fork */
151 u_int32_t fileID
; /* file ID */
152 u_int16_t startBlock
; /* first file allocation block number in this extent */
153 } __attribute__((aligned(2), packed
));
154 typedef struct HFSExtentKey HFSExtentKey
;
156 /* HFS Plus Extent key */
157 struct HFSPlusExtentKey
{
158 u_int16_t keyLength
; /* length of key, excluding this field */
159 u_int8_t forkType
; /* 0 = data fork, FF = resource fork */
160 u_int8_t pad
; /* make the other fields align on 32-bit boundary */
161 u_int32_t fileID
; /* file ID */
162 u_int32_t startBlock
; /* first file allocation block number in this extent */
163 } __attribute__((aligned(2), packed
));
164 typedef struct HFSPlusExtentKey HFSPlusExtentKey
;
166 /* Number of extent descriptors per extent record */
168 kHFSExtentDensity
= 3,
169 kHFSPlusExtentDensity
= 8
172 /* HFS extent descriptor */
173 struct HFSExtentDescriptor
{
174 u_int16_t startBlock
; /* first allocation block */
175 u_int16_t blockCount
; /* number of allocation blocks */
176 } __attribute__((aligned(2), packed
));
177 typedef struct HFSExtentDescriptor HFSExtentDescriptor
;
179 /* HFS Plus extent descriptor */
180 struct HFSPlusExtentDescriptor
{
181 u_int32_t startBlock
; /* first allocation block */
182 u_int32_t blockCount
; /* number of allocation blocks */
183 } __attribute__((aligned(2), packed
));
184 typedef struct HFSPlusExtentDescriptor HFSPlusExtentDescriptor
;
186 /* HFS extent record */
187 typedef HFSExtentDescriptor HFSExtentRecord
[3];
189 /* HFS Plus extent record */
190 typedef HFSPlusExtentDescriptor HFSPlusExtentRecord
[8];
193 /* Finder information */
194 struct FndrFileInfo
{
195 u_int32_t fdType
; /* file type */
196 u_int32_t fdCreator
; /* file creator */
197 u_int16_t fdFlags
; /* Finder flags */
199 int16_t v
; /* file's location */
203 } __attribute__((aligned(2), packed
));
204 typedef struct FndrFileInfo FndrFileInfo
;
207 struct { /* folder's window rectangle */
213 unsigned short frFlags
; /* Finder flags */
215 u_int16_t v
; /* folder's location */
219 } __attribute__((aligned(2), packed
));
220 typedef struct FndrDirInfo FndrDirInfo
;
222 struct FndrOpaqueInfo
{
224 } __attribute__((aligned(2), packed
));
225 typedef struct FndrOpaqueInfo FndrOpaqueInfo
;
227 struct FndrExtendedDirInfo
{
228 u_int32_t document_id
;
229 u_int32_t date_added
;
230 u_int16_t extended_flags
;
232 u_int32_t write_gen_counter
;
233 } __attribute__((aligned(2), packed
));
235 struct FndrExtendedFileInfo
{
236 u_int32_t document_id
;
237 u_int32_t date_added
;
238 u_int16_t extended_flags
;
240 u_int32_t write_gen_counter
;
241 } __attribute__((aligned(2), packed
));
243 /* HFS Plus Fork data info - 80 bytes */
244 struct HFSPlusForkData
{
245 u_int64_t logicalSize
; /* fork's logical size in bytes */
246 u_int32_t clumpSize
; /* fork's clump size in bytes */
247 u_int32_t totalBlocks
; /* total blocks used by this fork */
248 HFSPlusExtentRecord extents
; /* initial set of extents */
249 } __attribute__((aligned(2), packed
));
250 typedef struct HFSPlusForkData HFSPlusForkData
;
253 /* Mac OS X has 16 bytes worth of "BSD" info.
255 * Note: Mac OS 9 implementations and applications
256 * should preserve, but not change, this information.
258 struct HFSPlusBSDInfo
{
259 u_int32_t ownerID
; /* user-id of owner or hard link chain previous link */
260 u_int32_t groupID
; /* group-id of owner or hard link chain next link */
261 u_int8_t adminFlags
; /* super-user changeable flags */
262 u_int8_t ownerFlags
; /* owner changeable flags */
263 u_int16_t fileMode
; /* file type and permission bits */
265 u_int32_t iNodeNum
; /* indirect node number (hard links only) */
266 u_int32_t linkCount
; /* links that refer to this indirect node */
267 u_int32_t rawDevice
; /* special file device (FBLK and FCHR only) */
269 } __attribute__((aligned(2), packed
));
270 typedef struct HFSPlusBSDInfo HFSPlusBSDInfo
;
273 * Hardlink "links" resolve to an inode
274 * and the actual uid/gid comes from that
277 * We repurpose the links's uid/gid fields
278 * for the hardlink link chain. The chain
279 * consists of a doubly linked list of file
283 #define hl_firstLinkID reserved1 /* Valid only if HasLinkChain flag is set (indirect nodes only) */
285 #define hl_prevLinkID bsdInfo.ownerID /* Valid only if HasLinkChain flag is set */
286 #define hl_nextLinkID bsdInfo.groupID /* Valid only if HasLinkChain flag is set */
288 #define hl_linkReference bsdInfo.special.iNodeNum
289 #define hl_linkCount bsdInfo.special.linkCount
292 /* Catalog file data structures */
295 kHFSRootParentID
= 1, /* Parent ID of the root folder */
296 kHFSRootFolderID
= 2, /* Folder ID of the root folder */
297 kHFSExtentsFileID
= 3, /* File ID of the extents file */
298 kHFSCatalogFileID
= 4, /* File ID of the catalog file */
299 kHFSBadBlockFileID
= 5, /* File ID of the bad allocation block file */
300 kHFSAllocationFileID
= 6, /* File ID of the allocation file (HFS Plus only) */
301 kHFSStartupFileID
= 7, /* File ID of the startup file (HFS Plus only) */
302 kHFSAttributesFileID
= 8, /* File ID of the attribute file (HFS Plus only) */
303 kHFSAttributeDataFileID
= 13, /* Used in Mac OS X runtime for extent based attributes */
304 /* kHFSAttributeDataFileID is never stored on disk. */
305 kHFSRepairCatalogFileID
= 14, /* Used when rebuilding Catalog B-tree */
306 kHFSBogusExtentFileID
= 15, /* Used for exchanging extents in extents file */
307 kHFSFirstUserCatalogNodeID
= 16
310 /* HFS catalog key */
311 struct HFSCatalogKey
{
312 u_int8_t keyLength
; /* key length (in bytes) */
313 u_int8_t reserved
; /* reserved (set to zero) */
314 u_int32_t parentID
; /* parent folder ID */
315 u_int8_t nodeName
[kHFSMaxFileNameChars
+ 1]; /* catalog node name */
316 } __attribute__((aligned(2), packed
));
317 typedef struct HFSCatalogKey HFSCatalogKey
;
319 /* HFS Plus catalog key */
320 struct HFSPlusCatalogKey
{
321 u_int16_t keyLength
; /* key length (in bytes) */
322 u_int32_t parentID
; /* parent folder ID */
323 HFSUniStr255 nodeName
; /* catalog node name */
324 } __attribute__((aligned(2), packed
));
325 typedef struct HFSPlusCatalogKey HFSPlusCatalogKey
;
327 /* Catalog record types */
329 /* HFS Catalog Records */
330 kHFSFolderRecord
= 0x0100, /* Folder record */
331 kHFSFileRecord
= 0x0200, /* File record */
332 kHFSFolderThreadRecord
= 0x0300, /* Folder thread record */
333 kHFSFileThreadRecord
= 0x0400, /* File thread record */
335 /* HFS Plus Catalog Records */
336 kHFSPlusFolderRecord
= 1, /* Folder record */
337 kHFSPlusFileRecord
= 2, /* File record */
338 kHFSPlusFolderThreadRecord
= 3, /* Folder thread record */
339 kHFSPlusFileThreadRecord
= 4 /* File thread record */
343 /* Catalog file record flags */
345 kHFSFileLockedBit
= 0x0000, /* file is locked and cannot be written to */
346 kHFSFileLockedMask
= 0x0001,
348 kHFSThreadExistsBit
= 0x0001, /* a file thread record exists for this file */
349 kHFSThreadExistsMask
= 0x0002,
351 kHFSHasAttributesBit
= 0x0002, /* object has extended attributes */
352 kHFSHasAttributesMask
= 0x0004,
354 kHFSHasSecurityBit
= 0x0003, /* object has security data (ACLs) */
355 kHFSHasSecurityMask
= 0x0008,
357 kHFSHasFolderCountBit
= 0x0004, /* only for HFSX, folder maintains a separate sub-folder count */
358 kHFSHasFolderCountMask
= 0x0010, /* (sum of folder records and directory hard links) */
360 kHFSHasLinkChainBit
= 0x0005, /* has hardlink chain (inode or link) */
361 kHFSHasLinkChainMask
= 0x0020,
363 kHFSHasChildLinkBit
= 0x0006, /* folder has a child that's a dir link */
364 kHFSHasChildLinkMask
= 0x0040,
366 kHFSHasDateAddedBit
= 0x0007, /* File/Folder has the date-added stored in the finder info. */
367 kHFSHasDateAddedMask
= 0x0080,
369 kHFSFastDevPinnedBit
= 0x0008, /* this file has been pinned to the fast-device by the hot-file code on cooperative fusion */
370 kHFSFastDevPinnedMask
= 0x0100,
372 kHFSDoNotFastDevPinBit
= 0x0009, /* this file can not be pinned to the fast-device */
373 kHFSDoNotFastDevPinMask
= 0x0200,
375 kHFSFastDevCandidateBit
= 0x000a, /* this item is a potential candidate for fast-dev pinning (as are any of its descendents */
376 kHFSFastDevCandidateMask
= 0x0400,
378 kHFSAutoCandidateBit
= 0x000b, /* this item was automatically marked as a fast-dev candidate by the kernel */
379 kHFSAutoCandidateMask
= 0x0800
381 // There are only 4 flag bits remaining: 0x1000, 0x2000, 0x4000, 0x8000
386 /* HFS catalog folder record - 70 bytes */
387 struct HFSCatalogFolder
{
388 int16_t recordType
; /* == kHFSFolderRecord */
389 u_int16_t flags
; /* folder flags */
390 u_int16_t valence
; /* folder valence */
391 u_int32_t folderID
; /* folder ID */
392 u_int32_t createDate
; /* date and time of creation */
393 u_int32_t modifyDate
; /* date and time of last modification */
394 u_int32_t backupDate
; /* date and time of last backup */
395 FndrDirInfo userInfo
; /* Finder information */
396 FndrOpaqueInfo finderInfo
; /* additional Finder information */
397 u_int32_t reserved
[4]; /* reserved - initialized as zero */
398 } __attribute__((aligned(2), packed
));
399 typedef struct HFSCatalogFolder HFSCatalogFolder
;
401 /* HFS Plus catalog folder record - 88 bytes */
402 struct HFSPlusCatalogFolder
{
403 int16_t recordType
; /* == kHFSPlusFolderRecord */
404 u_int16_t flags
; /* file flags */
405 u_int32_t valence
; /* folder's item count */
406 u_int32_t folderID
; /* folder ID */
407 u_int32_t createDate
; /* date and time of creation */
408 u_int32_t contentModDate
; /* date and time of last content modification */
409 u_int32_t attributeModDate
; /* date and time of last attribute modification */
410 u_int32_t accessDate
; /* date and time of last access (MacOS X only) */
411 u_int32_t backupDate
; /* date and time of last backup */
412 HFSPlusBSDInfo bsdInfo
; /* permissions (for MacOS X) */
413 FndrDirInfo userInfo
; /* Finder information */
414 FndrOpaqueInfo finderInfo
; /* additional Finder information */
415 u_int32_t textEncoding
; /* hint for name conversions */
416 u_int32_t folderCount
; /* number of enclosed folders, active when HasFolderCount is set */
417 } __attribute__((aligned(2), packed
));
418 typedef struct HFSPlusCatalogFolder HFSPlusCatalogFolder
;
420 /* HFS catalog file record - 102 bytes */
421 struct HFSCatalogFile
{
422 int16_t recordType
; /* == kHFSFileRecord */
423 u_int8_t flags
; /* file flags */
424 int8_t fileType
; /* file type (unused ?) */
425 FndrFileInfo userInfo
; /* Finder information */
426 u_int32_t fileID
; /* file ID */
427 u_int16_t dataStartBlock
; /* not used - set to zero */
428 int32_t dataLogicalSize
; /* logical EOF of data fork */
429 int32_t dataPhysicalSize
; /* physical EOF of data fork */
430 u_int16_t rsrcStartBlock
; /* not used - set to zero */
431 int32_t rsrcLogicalSize
; /* logical EOF of resource fork */
432 int32_t rsrcPhysicalSize
; /* physical EOF of resource fork */
433 u_int32_t createDate
; /* date and time of creation */
434 u_int32_t modifyDate
; /* date and time of last modification */
435 u_int32_t backupDate
; /* date and time of last backup */
436 FndrOpaqueInfo finderInfo
; /* additional Finder information */
437 u_int16_t clumpSize
; /* file clump size (not used) */
438 HFSExtentRecord dataExtents
; /* first data fork extent record */
439 HFSExtentRecord rsrcExtents
; /* first resource fork extent record */
440 u_int32_t reserved
; /* reserved - initialized as zero */
441 } __attribute__((aligned(2), packed
));
442 typedef struct HFSCatalogFile HFSCatalogFile
;
444 /* HFS Plus catalog file record - 248 bytes */
445 struct HFSPlusCatalogFile
{
446 int16_t recordType
; /* == kHFSPlusFileRecord */
447 u_int16_t flags
; /* file flags */
448 u_int32_t reserved1
; /* reserved - initialized as zero */
449 u_int32_t fileID
; /* file ID */
450 u_int32_t createDate
; /* date and time of creation */
451 u_int32_t contentModDate
; /* date and time of last content modification */
452 u_int32_t attributeModDate
; /* date and time of last attribute modification */
453 u_int32_t accessDate
; /* date and time of last access (MacOS X only) */
454 u_int32_t backupDate
; /* date and time of last backup */
455 HFSPlusBSDInfo bsdInfo
; /* permissions (for MacOS X) */
456 FndrFileInfo userInfo
; /* Finder information */
457 FndrOpaqueInfo finderInfo
; /* additional Finder information */
458 u_int32_t textEncoding
; /* hint for name conversions */
459 u_int32_t reserved2
; /* reserved - initialized as zero */
461 /* Note: these start on double long (64 bit) boundary */
462 HFSPlusForkData dataFork
; /* size and block data for data fork */
463 HFSPlusForkData resourceFork
; /* size and block data for resource fork */
464 } __attribute__((aligned(2), packed
));
465 typedef struct HFSPlusCatalogFile HFSPlusCatalogFile
;
467 /* HFS catalog thread record - 46 bytes */
468 struct HFSCatalogThread
{
469 int16_t recordType
; /* == kHFSFolderThreadRecord or kHFSFileThreadRecord */
470 int32_t reserved
[2]; /* reserved - initialized as zero */
471 u_int32_t parentID
; /* parent ID for this catalog node */
472 u_int8_t nodeName
[kHFSMaxFileNameChars
+ 1]; /* name of this catalog node */
473 } __attribute__((aligned(2), packed
));
474 typedef struct HFSCatalogThread HFSCatalogThread
;
476 /* HFS Plus catalog thread record -- 264 bytes */
477 struct HFSPlusCatalogThread
{
478 int16_t recordType
; /* == kHFSPlusFolderThreadRecord or kHFSPlusFileThreadRecord */
479 int16_t reserved
; /* reserved - initialized as zero */
480 u_int32_t parentID
; /* parent ID for this catalog node */
481 HFSUniStr255 nodeName
; /* name of this catalog node (variable length) */
482 } __attribute__((aligned(2), packed
));
483 typedef struct HFSPlusCatalogThread HFSPlusCatalogThread
;
485 #ifdef __APPLE_API_UNSTABLE
487 * These are the types of records in the attribute B-tree. The values were
488 * chosen so that they wouldn't conflict with the catalog record types.
491 kHFSPlusAttrInlineData
= 0x10, /* attributes whose data fits in a b-tree node */
492 kHFSPlusAttrForkData
= 0x20, /* extent based attributes (data lives in extents) */
493 kHFSPlusAttrExtents
= 0x30 /* overflow extents for large attributes */
498 * HFSPlusAttrForkData
499 * For larger attributes, whose value is stored in allocation blocks.
500 * If the attribute has more than 8 extents, there will be additional
501 * records (of type HFSPlusAttrExtents) for this attribute.
503 struct HFSPlusAttrForkData
{
504 u_int32_t recordType
; /* == kHFSPlusAttrForkData*/
506 HFSPlusForkData theFork
; /* size and first extents of value*/
507 } __attribute__((aligned(2), packed
));
508 typedef struct HFSPlusAttrForkData HFSPlusAttrForkData
;
512 * This record contains information about overflow extents for large,
513 * fragmented attributes.
515 struct HFSPlusAttrExtents
{
516 u_int32_t recordType
; /* == kHFSPlusAttrExtents*/
518 HFSPlusExtentRecord extents
; /* additional extents*/
519 } __attribute__((aligned(2), packed
));
520 typedef struct HFSPlusAttrExtents HFSPlusAttrExtents
;
523 * Atrributes B-tree Data Record
525 * For small attributes, whose entire value is stored
526 * within a single B-tree record.
528 struct HFSPlusAttrData
{
529 u_int32_t recordType
; /* == kHFSPlusAttrInlineData */
530 u_int32_t reserved
[2];
531 u_int32_t attrSize
; /* size of attribute data in bytes */
532 u_int8_t attrData
[2]; /* variable length */
533 } __attribute__((aligned(2), packed
));
534 typedef struct HFSPlusAttrData HFSPlusAttrData
;
537 /* HFSPlusAttrInlineData is obsolete use HFSPlusAttrData instead */
538 struct HFSPlusAttrInlineData
{
539 u_int32_t recordType
;
541 u_int32_t logicalSize
;
542 u_int8_t userData
[2];
543 } __attribute__((aligned(2), packed
));
544 typedef struct HFSPlusAttrInlineData HFSPlusAttrInlineData
;
547 /* A generic Attribute Record */
548 union HFSPlusAttrRecord
{
549 u_int32_t recordType
;
550 HFSPlusAttrInlineData inlineData
; /* NOT USED */
551 HFSPlusAttrData attrData
;
552 HFSPlusAttrForkData forkData
;
553 HFSPlusAttrExtents overflowExtents
;
555 typedef union HFSPlusAttrRecord HFSPlusAttrRecord
;
558 enum { kHFSMaxAttrNameLen
= 127 };
559 struct HFSPlusAttrKey
{
560 u_int16_t keyLength
; /* key length (in bytes) */
561 u_int16_t pad
; /* set to zero */
562 u_int32_t fileID
; /* file associated with attribute */
563 u_int32_t startBlock
; /* first allocation block number for extents */
564 u_int16_t attrNameLen
; /* number of unicode characters */
565 u_int16_t attrName
[kHFSMaxAttrNameLen
]; /* attribute name (Unicode) */
566 } __attribute__((aligned(2), packed
));
567 typedef struct HFSPlusAttrKey HFSPlusAttrKey
;
569 #define kHFSPlusAttrKeyMaximumLength (sizeof(HFSPlusAttrKey) - sizeof(u_int16_t))
570 #define kHFSPlusAttrKeyMinimumLength (kHFSPlusAttrKeyMaximumLength - kHFSMaxAttrNameLen*sizeof(u_int16_t))
572 #endif /* __APPLE_API_UNSTABLE */
575 /* Key and node lengths */
577 kHFSPlusExtentKeyMaximumLength
= sizeof(HFSPlusExtentKey
) - sizeof(u_int16_t
),
578 kHFSExtentKeyMaximumLength
= sizeof(HFSExtentKey
) - sizeof(u_int8_t
),
579 kHFSPlusCatalogKeyMaximumLength
= sizeof(HFSPlusCatalogKey
) - sizeof(u_int16_t
),
580 kHFSPlusCatalogKeyMinimumLength
= kHFSPlusCatalogKeyMaximumLength
- sizeof(HFSUniStr255
) + sizeof(u_int16_t
),
581 kHFSCatalogKeyMaximumLength
= sizeof(HFSCatalogKey
) - sizeof(u_int8_t
),
582 kHFSCatalogKeyMinimumLength
= kHFSCatalogKeyMaximumLength
- (kHFSMaxFileNameChars
+ 1) + sizeof(u_int8_t
),
583 kHFSPlusCatalogMinNodeSize
= 4096,
584 kHFSPlusExtentMinNodeSize
= 512,
585 kHFSPlusAttrMinNodeSize
= 4096
588 /* HFS and HFS Plus volume attribute bits */
590 /* Bits 0-6 are reserved (always cleared by MountVol call) */
591 kHFSVolumeHardwareLockBit
= 7, /* volume is locked by hardware */
592 kHFSVolumeUnmountedBit
= 8, /* volume was successfully unmounted */
593 kHFSVolumeSparedBlocksBit
= 9, /* volume has bad blocks spared */
594 kHFSVolumeNoCacheRequiredBit
= 10, /* don't cache volume blocks (i.e. RAM or ROM disk) */
595 kHFSBootVolumeInconsistentBit
= 11, /* boot volume is inconsistent (System 7.6 and later) */
596 kHFSCatalogNodeIDsReusedBit
= 12,
597 kHFSVolumeJournaledBit
= 13, /* this volume has a journal on it */
598 kHFSVolumeInconsistentBit
= 14, /* serious inconsistencies detected at runtime */
599 kHFSVolumeSoftwareLockBit
= 15, /* volume is locked by software */
601 * HFS only has 16 bits of attributes in the MDB, but HFS Plus has 32 bits.
602 * Therefore, bits 16-31 can only be used on HFS Plus.
604 kHFSUnusedNodeFixBit
= 31, /* Unused nodes in the Catalog B-tree have been zero-filled. See Radar #6947811. */
605 kHFSContentProtectionBit
= 30, /* Volume has per-file content protection */
607 /*** Keep these in sync with the bits above ! ****/
608 kHFSVolumeHardwareLockMask
= 0x00000080,
609 kHFSVolumeUnmountedMask
= 0x00000100,
610 kHFSVolumeSparedBlocksMask
= 0x00000200,
611 kHFSVolumeNoCacheRequiredMask
= 0x00000400,
612 kHFSBootVolumeInconsistentMask
= 0x00000800,
613 kHFSCatalogNodeIDsReusedMask
= 0x00001000,
614 kHFSVolumeJournaledMask
= 0x00002000,
615 kHFSVolumeInconsistentMask
= 0x00004000,
616 kHFSVolumeSoftwareLockMask
= 0x00008000,
618 /* Bits 16-31 are allocated from high to low */
620 kHFSContentProtectionMask
= 0x40000000,
621 kHFSUnusedNodeFixMask
= 0x80000000,
623 kHFSMDBAttributesMask
= 0x8380
627 kHFSUnusedNodesFixDate
= 0xc5ef2480 /* March 25, 2009 */
630 /* HFS Master Directory Block - 162 bytes */
631 /* Stored at sector #2 (3rd sector) and second-to-last sector. */
632 struct HFSMasterDirectoryBlock
{
633 u_int16_t drSigWord
; /* == kHFSSigWord */
634 u_int32_t drCrDate
; /* date and time of volume creation */
635 u_int32_t drLsMod
; /* date and time of last modification */
636 u_int16_t drAtrb
; /* volume attributes */
637 u_int16_t drNmFls
; /* number of files in root folder */
638 u_int16_t drVBMSt
; /* first block of volume bitmap */
639 u_int16_t drAllocPtr
; /* start of next allocation search */
640 u_int16_t drNmAlBlks
; /* number of allocation blocks in volume */
641 u_int32_t drAlBlkSiz
; /* size (in bytes) of allocation blocks */
642 u_int32_t drClpSiz
; /* default clump size */
643 u_int16_t drAlBlSt
; /* first allocation block in volume */
644 u_int32_t drNxtCNID
; /* next unused catalog node ID */
645 u_int16_t drFreeBks
; /* number of unused allocation blocks */
646 u_int8_t drVN
[kHFSMaxVolumeNameChars
+ 1]; /* volume name */
647 u_int32_t drVolBkUp
; /* date and time of last backup */
648 u_int16_t drVSeqNum
; /* volume backup sequence number */
649 u_int32_t drWrCnt
; /* volume write count */
650 u_int32_t drXTClpSiz
; /* clump size for extents overflow file */
651 u_int32_t drCTClpSiz
; /* clump size for catalog file */
652 u_int16_t drNmRtDirs
; /* number of directories in root folder */
653 u_int32_t drFilCnt
; /* number of files in volume */
654 u_int32_t drDirCnt
; /* number of directories in volume */
655 u_int32_t drFndrInfo
[8]; /* information used by the Finder */
656 u_int16_t drEmbedSigWord
; /* embedded volume signature (formerly drVCSize) */
657 HFSExtentDescriptor drEmbedExtent
; /* embedded volume location and size (formerly drVBMCSize and drCtlCSize) */
658 u_int32_t drXTFlSize
; /* size of extents overflow file */
659 HFSExtentRecord drXTExtRec
; /* extent record for extents overflow file */
660 u_int32_t drCTFlSize
; /* size of catalog file */
661 HFSExtentRecord drCTExtRec
; /* extent record for catalog file */
662 } __attribute__((aligned(2), packed
));
663 typedef struct HFSMasterDirectoryBlock HFSMasterDirectoryBlock
;
666 #ifdef __APPLE_API_UNSTABLE
667 #define SET_HFS_TEXT_ENCODING(hint) \
668 (0x656e6300 | ((hint) & 0xff))
669 #define GET_HFS_TEXT_ENCODING(hint) \
670 (((hint) & 0xffffff00) == 0x656e6300 ? (hint) & 0x000000ff : 0xffffffffU)
671 #endif /* __APPLE_API_UNSTABLE */
674 /* HFS Plus Volume Header - 512 bytes */
675 /* Stored at sector #2 (3rd sector) and second-to-last sector. */
676 struct HFSPlusVolumeHeader
{
677 u_int16_t signature
; /* == kHFSPlusSigWord */
678 u_int16_t version
; /* == kHFSPlusVersion */
679 u_int32_t attributes
; /* volume attributes */
680 u_int32_t lastMountedVersion
; /* implementation version which last mounted volume */
681 u_int32_t journalInfoBlock
; /* block addr of journal info (if volume is journaled, zero otherwise) */
683 u_int32_t createDate
; /* date and time of volume creation */
684 u_int32_t modifyDate
; /* date and time of last modification */
685 u_int32_t backupDate
; /* date and time of last backup */
686 u_int32_t checkedDate
; /* date and time of last disk check */
688 u_int32_t fileCount
; /* number of files in volume */
689 u_int32_t folderCount
; /* number of directories in volume */
691 u_int32_t blockSize
; /* size (in bytes) of allocation blocks */
692 u_int32_t totalBlocks
; /* number of allocation blocks in volume (includes this header and VBM*/
693 u_int32_t freeBlocks
; /* number of unused allocation blocks */
695 u_int32_t nextAllocation
; /* start of next allocation search */
696 u_int32_t rsrcClumpSize
; /* default resource fork clump size */
697 u_int32_t dataClumpSize
; /* default data fork clump size */
698 u_int32_t nextCatalogID
; /* next unused catalog node ID */
700 u_int32_t writeCount
; /* volume write count */
701 u_int64_t encodingsBitmap
; /* which encodings have been use on this volume */
703 u_int8_t finderInfo
[32]; /* information used by the Finder */
705 HFSPlusForkData allocationFile
; /* allocation bitmap file */
706 HFSPlusForkData extentsFile
; /* extents B-tree file */
707 HFSPlusForkData catalogFile
; /* catalog B-tree file */
708 HFSPlusForkData attributesFile
; /* extended attributes B-tree file */
709 HFSPlusForkData startupFile
; /* boot file (secondary loader) */
710 } __attribute__((aligned(2), packed
));
711 typedef struct HFSPlusVolumeHeader HFSPlusVolumeHeader
;
714 /* B-tree structures */
723 u_int8_t rawData
[kMaxKeyLength
+2];
725 typedef union BTreeKey BTreeKey
;
727 /* BTNodeDescriptor -- Every B-tree node starts with these fields. */
728 struct BTNodeDescriptor
{
729 u_int32_t fLink
; /* next node at this level*/
730 u_int32_t bLink
; /* previous node at this level*/
731 int8_t kind
; /* kind of node (leaf, index, header, map)*/
732 u_int8_t height
; /* zero for header, map; child is one more than parent*/
733 u_int16_t numRecords
; /* number of records in this node*/
734 u_int16_t reserved
; /* reserved - initialized as zero */
735 } __attribute__((aligned(2), packed
));
736 typedef struct BTNodeDescriptor BTNodeDescriptor
;
738 /* Constants for BTNodeDescriptor kind */
746 /* BTHeaderRec -- The first record of a B-tree header node */
748 u_int16_t treeDepth
; /* maximum height (usually leaf nodes) */
749 u_int32_t rootNode
; /* node number of root node */
750 u_int32_t leafRecords
; /* number of leaf records in all leaf nodes */
751 u_int32_t firstLeafNode
; /* node number of first leaf node */
752 u_int32_t lastLeafNode
; /* node number of last leaf node */
753 u_int16_t nodeSize
; /* size of a node, in bytes */
754 u_int16_t maxKeyLength
; /* reserved */
755 u_int32_t totalNodes
; /* total number of nodes in tree */
756 u_int32_t freeNodes
; /* number of unused (free) nodes in tree */
757 u_int16_t reserved1
; /* unused */
758 u_int32_t clumpSize
; /* reserved */
759 u_int8_t btreeType
; /* reserved */
760 u_int8_t keyCompareType
; /* Key string Comparison Type */
761 u_int32_t attributes
; /* persistent attributes about the tree */
762 u_int32_t reserved3
[16]; /* reserved */
763 } __attribute__((aligned(2), packed
));
764 typedef struct BTHeaderRec BTHeaderRec
;
766 /* Constants for BTHeaderRec attributes */
768 kBTBadCloseMask
= 0x00000001, /* reserved */
769 kBTBigKeysMask
= 0x00000002, /* key length field is 16 bits */
770 kBTVariableIndexKeysMask
= 0x00000004 /* keys in index nodes are variable length */
774 /* Catalog Key Name Comparison Type */
776 kHFSCaseFolding
= 0xCF, /* case folding (case-insensitive) */
777 kHFSBinaryCompare
= 0xBC /* binary compare (case-sensitive) */
780 #include <uuid/uuid.h>
782 /* JournalInfoBlock - Structure that describes where our journal lives */
784 // the original size of the reserved field in the JournalInfoBlock was
785 // 32*sizeof(u_int32_t). To keep the total size of the structure the
786 // same we subtract the size of new fields (currently: ext_jnl_uuid and
787 // machine_uuid). If you add additional fields, place them before the
788 // reserved field and subtract their size in this macro.
790 #define JIB_RESERVED_SIZE ((32*sizeof(u_int32_t)) - sizeof(uuid_string_t) - 48)
792 struct JournalInfoBlock
{
794 u_int32_t device_signature
[8]; // signature used to locate our device.
795 u_int64_t offset
; // byte offset to the journal on the device
796 u_int64_t size
; // size in bytes of the journal
797 uuid_string_t ext_jnl_uuid
;
798 char machine_serial_num
[48];
799 char reserved
[JIB_RESERVED_SIZE
];
800 } __attribute__((aligned(2), packed
));
801 typedef struct JournalInfoBlock JournalInfoBlock
;
804 kJIJournalInFSMask
= 0x00000001,
805 kJIJournalOnOtherDeviceMask
= 0x00000002,
806 kJIJournalNeedInitMask
= 0x00000004
810 // This the content type uuid for "external journal" GPT
811 // partitions. Each instance of a partition also has a
812 // uuid that uniquely identifies that instance.
814 #define EXTJNL_CONTENT_TYPE_UUID "4A6F7572-6E61-11AA-AA11-00306543ECAC"
821 #endif /* __HFS_FORMAT__ */