2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 #ifndef __HFS_FORMAT__
31 #define __HFS_FORMAT__
33 #include <sys/types.h>
34 #include <sys/appleapiopts.h>
39 * This file describes the on-disk format for HFS and HFS Plus volumes.
40 * The HFS Plus volume format is desciibed in detail in Apple Technote 1150.
42 * http://developer.apple.com/technotes/tn/tn1150.html
50 /* some on-disk hfs structures have 68K alignment (misaligned) */
51 #pragma options align=mac68k
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 a special directory for linked and unlinked files (HFS Plus only).
71 * This directory and its contents are never exported from the filesystem under
74 * To make this folder name sort last, it has embedded null prefix.
75 * (0xC0, 0x80 in UTF-8)
77 #define HFSPLUSMETADATAFOLDER "\xC0\x80\xC0\x80\xC0\x80\xC0\x80HFS+ Private Data"
80 * Files in the HFS Private Data folder have one of the following prefixes
81 * followed by a decimal number (no leading zeros). For indirect nodes this
82 * number is a 32 bit random number. For unlinked (deleted) files that are
83 * still open, the number is the file ID for that file.
85 * e.g. iNode7182000 and temp3296
87 #define HFS_INODE_PREFIX "iNode"
88 #define HFS_DELETE_PREFIX "temp"
90 #endif /* __APPLE_API_PRIVATE */
93 * Indirect link files (hard links) have the following type/creator.
96 kHardLinkFileType
= 0x686C6E6B, /* 'hlnk' */
97 kHFSPlusCreator
= 0x6866732B /* 'hfs+' */
101 #ifndef _HFSUNISTR255_DEFINED_
102 #define _HFSUNISTR255_DEFINED_
103 /* Unicode strings are used for HFS Plus file and folder names */
104 struct HFSUniStr255
{
105 u_int16_t length
; /* number of unicode characters */
106 u_int16_t unicode
[255]; /* unicode characters */
108 typedef struct HFSUniStr255 HFSUniStr255
;
109 typedef const HFSUniStr255
*ConstHFSUniStr255Param
;
110 #endif /* _HFSUNISTR255_DEFINED_ */
113 kHFSMaxVolumeNameChars
= 27,
114 kHFSMaxFileNameChars
= 31,
115 kHFSPlusMaxFileNameChars
= 255
119 /* Extent overflow file data structures */
122 struct HFSExtentKey
{
123 u_int8_t keyLength
; /* length of key, excluding this field */
124 u_int8_t forkType
; /* 0 = data fork, FF = resource fork */
125 u_int32_t fileID
; /* file ID */
126 u_int16_t startBlock
; /* first file allocation block number in this extent */
128 typedef struct HFSExtentKey HFSExtentKey
;
130 /* HFS Plus Extent key */
131 struct HFSPlusExtentKey
{
132 u_int16_t keyLength
; /* length of key, excluding this field */
133 u_int8_t forkType
; /* 0 = data fork, FF = resource fork */
134 u_int8_t pad
; /* make the other fields align on 32-bit boundary */
135 u_int32_t fileID
; /* file ID */
136 u_int32_t startBlock
; /* first file allocation block number in this extent */
138 typedef struct HFSPlusExtentKey HFSPlusExtentKey
;
140 /* Number of extent descriptors per extent record */
142 kHFSExtentDensity
= 3,
143 kHFSPlusExtentDensity
= 8
146 /* HFS extent descriptor */
147 struct HFSExtentDescriptor
{
148 u_int16_t startBlock
; /* first allocation block */
149 u_int16_t blockCount
; /* number of allocation blocks */
151 typedef struct HFSExtentDescriptor HFSExtentDescriptor
;
153 /* HFS Plus extent descriptor */
154 struct HFSPlusExtentDescriptor
{
155 u_int32_t startBlock
; /* first allocation block */
156 u_int32_t blockCount
; /* number of allocation blocks */
158 typedef struct HFSPlusExtentDescriptor HFSPlusExtentDescriptor
;
160 /* HFS extent record */
161 typedef HFSExtentDescriptor HFSExtentRecord
[3];
163 /* HFS Plus extent record */
164 typedef HFSPlusExtentDescriptor HFSPlusExtentRecord
[8];
167 /* Finder information */
168 struct FndrFileInfo
{
169 u_int32_t fdType
; /* file type */
170 u_int32_t fdCreator
; /* file creator */
171 u_int16_t fdFlags
; /* Finder flags */
173 int16_t v
; /* file's location */
178 typedef struct FndrFileInfo FndrFileInfo
;
181 struct { /* folder's window rectangle */
187 unsigned short frFlags
; /* Finder flags */
189 u_int16_t v
; /* folder's location */
194 typedef struct FndrDirInfo FndrDirInfo
;
196 struct FndrOpaqueInfo
{
199 typedef struct FndrOpaqueInfo FndrOpaqueInfo
;
202 /* HFS Plus Fork data info - 80 bytes */
203 struct HFSPlusForkData
{
204 u_int64_t logicalSize
; /* fork's logical size in bytes */
205 u_int32_t clumpSize
; /* fork's clump size in bytes */
206 u_int32_t totalBlocks
; /* total blocks used by this fork */
207 HFSPlusExtentRecord extents
; /* initial set of extents */
209 typedef struct HFSPlusForkData HFSPlusForkData
;
212 /* Mac OS X has 16 bytes worth of "BSD" info.
214 * Note: Mac OS 9 implementations and applications
215 * should preserve, but not change, this information.
217 struct HFSPlusBSDInfo
{
218 u_int32_t ownerID
; /* user or group ID of file/folder owner */
219 u_int32_t groupID
; /* additional user of group ID */
220 u_int8_t adminFlags
; /* super-user changeable flags */
221 u_int8_t ownerFlags
; /* owner changeable flags */
222 u_int16_t fileMode
; /* file type and permission bits */
224 u_int32_t iNodeNum
; /* indirect node number (hard links only) */
225 u_int32_t linkCount
; /* links that refer to this indirect node */
226 u_int32_t rawDevice
; /* special file device (FBLK and FCHR only) */
229 typedef struct HFSPlusBSDInfo HFSPlusBSDInfo
;
232 /* Catalog file data structures */
235 kHFSRootParentID
= 1, /* Parent ID of the root folder */
236 kHFSRootFolderID
= 2, /* Folder ID of the root folder */
237 kHFSExtentsFileID
= 3, /* File ID of the extents file */
238 kHFSCatalogFileID
= 4, /* File ID of the catalog file */
239 kHFSBadBlockFileID
= 5, /* File ID of the bad allocation block file */
240 kHFSAllocationFileID
= 6, /* File ID of the allocation file (HFS Plus only) */
241 kHFSStartupFileID
= 7, /* File ID of the startup file (HFS Plus only) */
242 kHFSAttributesFileID
= 8, /* File ID of the attribute file (HFS Plus only) */
243 kHFSRepairCatalogFileID
= 14, /* Used when rebuilding Catalog B-tree */
244 kHFSBogusExtentFileID
= 15, /* Used for exchanging extents in extents file */
245 kHFSFirstUserCatalogNodeID
= 16
248 /* HFS catalog key */
249 struct HFSCatalogKey
{
250 u_int8_t keyLength
; /* key length (in bytes) */
251 u_int8_t reserved
; /* reserved (set to zero) */
252 u_int32_t parentID
; /* parent folder ID */
253 u_int8_t nodeName
[kHFSMaxFileNameChars
+ 1]; /* catalog node name */
255 typedef struct HFSCatalogKey HFSCatalogKey
;
257 /* HFS Plus catalog key */
258 struct HFSPlusCatalogKey
{
259 u_int16_t keyLength
; /* key length (in bytes) */
260 u_int32_t parentID
; /* parent folder ID */
261 HFSUniStr255 nodeName
; /* catalog node name */
263 typedef struct HFSPlusCatalogKey HFSPlusCatalogKey
;
265 /* Catalog record types */
267 /* HFS Catalog Records */
268 kHFSFolderRecord
= 0x0100, /* Folder record */
269 kHFSFileRecord
= 0x0200, /* File record */
270 kHFSFolderThreadRecord
= 0x0300, /* Folder thread record */
271 kHFSFileThreadRecord
= 0x0400, /* File thread record */
273 /* HFS Plus Catalog Records */
274 kHFSPlusFolderRecord
= 1, /* Folder record */
275 kHFSPlusFileRecord
= 2, /* File record */
276 kHFSPlusFolderThreadRecord
= 3, /* Folder thread record */
277 kHFSPlusFileThreadRecord
= 4 /* File thread record */
281 /* Catalog file record flags */
283 kHFSFileLockedBit
= 0x0000, /* file is locked and cannot be written to */
284 kHFSFileLockedMask
= 0x0001,
286 kHFSThreadExistsBit
= 0x0001, /* a file thread record exists for this file */
287 kHFSThreadExistsMask
= 0x0002,
289 kHFSHasAttributesBit
= 0x0002, /* object has extended attributes */
290 kHFSHasAttributesMask
= 0x0004,
292 kHFSHasSecurityBit
= 0x0003, /* object has security data (ACLs) */
293 kHFSHasSecurityMask
= 0x0008
297 /* HFS catalog folder record - 70 bytes */
298 struct HFSCatalogFolder
{
299 int16_t recordType
; /* == kHFSFolderRecord */
300 u_int16_t flags
; /* folder flags */
301 u_int16_t valence
; /* folder valence */
302 u_int32_t folderID
; /* folder ID */
303 u_int32_t createDate
; /* date and time of creation */
304 u_int32_t modifyDate
; /* date and time of last modification */
305 u_int32_t backupDate
; /* date and time of last backup */
306 FndrDirInfo userInfo
; /* Finder information */
307 FndrOpaqueInfo finderInfo
; /* additional Finder information */
308 u_int32_t reserved
[4]; /* reserved - initialized as zero */
310 typedef struct HFSCatalogFolder HFSCatalogFolder
;
312 /* HFS Plus catalog folder record - 88 bytes */
313 struct HFSPlusCatalogFolder
{
314 int16_t recordType
; /* == kHFSPlusFolderRecord */
315 u_int16_t flags
; /* file flags */
316 u_int32_t valence
; /* folder's valence (limited to 2^16 in Mac OS) */
317 u_int32_t folderID
; /* folder ID */
318 u_int32_t createDate
; /* date and time of creation */
319 u_int32_t contentModDate
; /* date and time of last content modification */
320 u_int32_t attributeModDate
; /* date and time of last attribute modification */
321 u_int32_t accessDate
; /* date and time of last access (MacOS X only) */
322 u_int32_t backupDate
; /* date and time of last backup */
323 HFSPlusBSDInfo bsdInfo
; /* permissions (for MacOS X) */
324 FndrDirInfo userInfo
; /* Finder information */
325 FndrOpaqueInfo finderInfo
; /* additional Finder information */
326 u_int32_t textEncoding
; /* hint for name conversions */
327 u_int32_t attrBlocks
; /* cached count of attribute data blocks */
329 typedef struct HFSPlusCatalogFolder HFSPlusCatalogFolder
;
331 /* HFS catalog file record - 102 bytes */
332 struct HFSCatalogFile
{
333 int16_t recordType
; /* == kHFSFileRecord */
334 u_int8_t flags
; /* file flags */
335 int8_t fileType
; /* file type (unused ?) */
336 FndrFileInfo userInfo
; /* Finder information */
337 u_int32_t fileID
; /* file ID */
338 u_int16_t dataStartBlock
; /* not used - set to zero */
339 int32_t dataLogicalSize
; /* logical EOF of data fork */
340 int32_t dataPhysicalSize
; /* physical EOF of data fork */
341 u_int16_t rsrcStartBlock
; /* not used - set to zero */
342 int32_t rsrcLogicalSize
; /* logical EOF of resource fork */
343 int32_t rsrcPhysicalSize
; /* physical EOF of resource fork */
344 u_int32_t createDate
; /* date and time of creation */
345 u_int32_t modifyDate
; /* date and time of last modification */
346 u_int32_t backupDate
; /* date and time of last backup */
347 FndrOpaqueInfo finderInfo
; /* additional Finder information */
348 u_int16_t clumpSize
; /* file clump size (not used) */
349 HFSExtentRecord dataExtents
; /* first data fork extent record */
350 HFSExtentRecord rsrcExtents
; /* first resource fork extent record */
351 u_int32_t reserved
; /* reserved - initialized as zero */
353 typedef struct HFSCatalogFile HFSCatalogFile
;
355 /* HFS Plus catalog file record - 248 bytes */
356 struct HFSPlusCatalogFile
{
357 int16_t recordType
; /* == kHFSPlusFileRecord */
358 u_int16_t flags
; /* file flags */
359 u_int32_t reserved1
; /* reserved - initialized as zero */
360 u_int32_t fileID
; /* file ID */
361 u_int32_t createDate
; /* date and time of creation */
362 u_int32_t contentModDate
; /* date and time of last content modification */
363 u_int32_t attributeModDate
; /* date and time of last attribute modification */
364 u_int32_t accessDate
; /* date and time of last access (MacOS X only) */
365 u_int32_t backupDate
; /* date and time of last backup */
366 HFSPlusBSDInfo bsdInfo
; /* permissions (for MacOS X) */
367 FndrFileInfo userInfo
; /* Finder information */
368 FndrOpaqueInfo finderInfo
; /* additional Finder information */
369 u_int32_t textEncoding
; /* hint for name conversions */
370 u_int32_t attrBlocks
; /* cached count of attribute data blocks */
372 /* Note: these start on double long (64 bit) boundry */
373 HFSPlusForkData dataFork
; /* size and block data for data fork */
374 HFSPlusForkData resourceFork
; /* size and block data for resource fork */
376 typedef struct HFSPlusCatalogFile HFSPlusCatalogFile
;
378 /* HFS catalog thread record - 46 bytes */
379 struct HFSCatalogThread
{
380 int16_t recordType
; /* == kHFSFolderThreadRecord or kHFSFileThreadRecord */
381 int32_t reserved
[2]; /* reserved - initialized as zero */
382 u_int32_t parentID
; /* parent ID for this catalog node */
383 u_int8_t nodeName
[kHFSMaxFileNameChars
+ 1]; /* name of this catalog node */
385 typedef struct HFSCatalogThread HFSCatalogThread
;
387 /* HFS Plus catalog thread record -- 264 bytes */
388 struct HFSPlusCatalogThread
{
389 int16_t recordType
; /* == kHFSPlusFolderThreadRecord or kHFSPlusFileThreadRecord */
390 int16_t reserved
; /* reserved - initialized as zero */
391 u_int32_t parentID
; /* parent ID for this catalog node */
392 HFSUniStr255 nodeName
; /* name of this catalog node (variable length) */
394 typedef struct HFSPlusCatalogThread HFSPlusCatalogThread
;
396 #ifdef __APPLE_API_UNSTABLE
398 These are the types of records in the attribute B-tree. The values were
399 chosen so that they wouldn't conflict with the catalog record types.
402 kHFSPlusAttrInlineData
= 0x10, /* if size < kAttrOverflowSize */
403 kHFSPlusAttrForkData
= 0x20, /* if size >= kAttrOverflowSize */
404 kHFSPlusAttrExtents
= 0x30 /* overflow extents for large attributes */
410 For larger attributes, whose value is stored in allocation blocks.
411 If the attribute has more than 8 extents, there will be additonal
412 records (of type HFSPlusAttrExtents) for this attribute.
414 struct HFSPlusAttrForkData
{
415 u_int32_t recordType
; /* == kHFSPlusAttrForkData*/
417 HFSPlusForkData theFork
; /* size and first extents of value*/
419 typedef struct HFSPlusAttrForkData HFSPlusAttrForkData
;
423 This record contains information about overflow extents for large,
424 fragmented attributes.
426 struct HFSPlusAttrExtents
{
427 u_int32_t recordType
; /* == kHFSPlusAttrExtents*/
429 HFSPlusExtentRecord extents
; /* additional extents*/
431 typedef struct HFSPlusAttrExtents HFSPlusAttrExtents
;
434 * Atrributes B-tree Data Record
436 * For small attributes, whose entire value is stored
437 * within a single B-tree record.
439 struct HFSPlusAttrData
{
440 u_int32_t recordType
; /* == kHFSPlusAttrInlineData */
441 u_int32_t reserved
[2];
442 u_int32_t attrSize
; /* size of attribute data in bytes */
443 u_int8_t attrData
[2]; /* variable length */
445 typedef struct HFSPlusAttrData HFSPlusAttrData
;
448 /* HFSPlusAttrInlineData is obsolete use HFSPlusAttrData instead */
449 struct HFSPlusAttrInlineData
{
450 u_int32_t recordType
;
452 u_int32_t logicalSize
;
453 u_int8_t userData
[2];
455 typedef struct HFSPlusAttrInlineData HFSPlusAttrInlineData
;
458 /* A generic Attribute Record*/
459 union HFSPlusAttrRecord
{
460 u_int32_t recordType
;
461 HFSPlusAttrInlineData inlineData
; /* NOT USED */
462 HFSPlusAttrData attrData
;
463 HFSPlusAttrForkData forkData
;
464 HFSPlusAttrExtents overflowExtents
;
466 typedef union HFSPlusAttrRecord HFSPlusAttrRecord
;
469 enum { kHFSMaxAttrNameLen
= 127 };
470 struct HFSPlusAttrKey
{
471 u_int16_t keyLength
; /* key length (in bytes) */
472 u_int16_t pad
; /* set to zero */
473 u_int32_t fileID
; /* file associated with attribute */
474 u_int32_t startBlock
; /* first attribue allocation block number for extents */
475 u_int16_t attrNameLen
; /* number of unicode characters */
476 u_int16_t attrName
[kHFSMaxAttrNameLen
]; /* attribute name (Unicode) */
478 typedef struct HFSPlusAttrKey HFSPlusAttrKey
;
480 #define kHFSPlusAttrKeyMaximumLength (sizeof(HFSPlusAttrKey) - sizeof(u_int16_t))
481 #define kHFSPlusAttrKeyMinimumLength (kHFSPlusAttrKeyMaximumLength - kHFSMaxAttrNameLen*sizeof(u_int16_t))
483 #endif /* __APPLE_API_UNSTABLE */
486 /* Key and node lengths */
488 kHFSPlusExtentKeyMaximumLength
= sizeof(HFSPlusExtentKey
) - sizeof(u_int16_t
),
489 kHFSExtentKeyMaximumLength
= sizeof(HFSExtentKey
) - sizeof(u_int8_t
),
490 kHFSPlusCatalogKeyMaximumLength
= sizeof(HFSPlusCatalogKey
) - sizeof(u_int16_t
),
491 kHFSPlusCatalogKeyMinimumLength
= kHFSPlusCatalogKeyMaximumLength
- sizeof(HFSUniStr255
) + sizeof(u_int16_t
),
492 kHFSCatalogKeyMaximumLength
= sizeof(HFSCatalogKey
) - sizeof(u_int8_t
),
493 kHFSCatalogKeyMinimumLength
= kHFSCatalogKeyMaximumLength
- (kHFSMaxFileNameChars
+ 1) + sizeof(u_int8_t
),
494 kHFSPlusCatalogMinNodeSize
= 4096,
495 kHFSPlusExtentMinNodeSize
= 512,
496 kHFSPlusAttrMinNodeSize
= 4096
499 /* HFS and HFS Plus volume attribute bits */
501 /* Bits 0-6 are reserved (always cleared by MountVol call) */
502 kHFSVolumeHardwareLockBit
= 7, /* volume is locked by hardware */
503 kHFSVolumeUnmountedBit
= 8, /* volume was successfully unmounted */
504 kHFSVolumeSparedBlocksBit
= 9, /* volume has bad blocks spared */
505 kHFSVolumeNoCacheRequiredBit
= 10, /* don't cache volume blocks (i.e. RAM or ROM disk) */
506 kHFSBootVolumeInconsistentBit
= 11, /* boot volume is inconsistent (System 7.6 and later) */
507 kHFSCatalogNodeIDsReusedBit
= 12,
508 kHFSVolumeJournaledBit
= 13, /* this volume has a journal on it */
509 kHFSVolumeInconsistentBit
= 14, /* serious inconsistencies detected at runtime */
510 kHFSVolumeSoftwareLockBit
= 15, /* volume is locked by software */
512 kHFSVolumeHardwareLockMask
= 1 << kHFSVolumeHardwareLockBit
,
513 kHFSVolumeUnmountedMask
= 1 << kHFSVolumeUnmountedBit
,
514 kHFSVolumeSparedBlocksMask
= 1 << kHFSVolumeSparedBlocksBit
,
515 kHFSVolumeNoCacheRequiredMask
= 1 << kHFSVolumeNoCacheRequiredBit
,
516 kHFSBootVolumeInconsistentMask
= 1 << kHFSBootVolumeInconsistentBit
,
517 kHFSCatalogNodeIDsReusedMask
= 1 << kHFSCatalogNodeIDsReusedBit
,
518 kHFSVolumeJournaledMask
= 1 << kHFSVolumeJournaledBit
,
519 kHFSVolumeInconsistentMask
= 1 << kHFSVolumeInconsistentBit
,
520 kHFSVolumeSoftwareLockMask
= 1 << kHFSVolumeSoftwareLockBit
,
521 kHFSMDBAttributesMask
= 0x8380
525 /* HFS Master Directory Block - 162 bytes */
526 /* Stored at sector #2 (3rd sector) and second-to-last sector. */
527 struct HFSMasterDirectoryBlock
{
528 u_int16_t drSigWord
; /* == kHFSSigWord */
529 u_int32_t drCrDate
; /* date and time of volume creation */
530 u_int32_t drLsMod
; /* date and time of last modification */
531 u_int16_t drAtrb
; /* volume attributes */
532 u_int16_t drNmFls
; /* number of files in root folder */
533 u_int16_t drVBMSt
; /* first block of volume bitmap */
534 u_int16_t drAllocPtr
; /* start of next allocation search */
535 u_int16_t drNmAlBlks
; /* number of allocation blocks in volume */
536 u_int32_t drAlBlkSiz
; /* size (in bytes) of allocation blocks */
537 u_int32_t drClpSiz
; /* default clump size */
538 u_int16_t drAlBlSt
; /* first allocation block in volume */
539 u_int32_t drNxtCNID
; /* next unused catalog node ID */
540 u_int16_t drFreeBks
; /* number of unused allocation blocks */
541 u_int8_t drVN
[kHFSMaxVolumeNameChars
+ 1]; /* volume name */
542 u_int32_t drVolBkUp
; /* date and time of last backup */
543 u_int16_t drVSeqNum
; /* volume backup sequence number */
544 u_int32_t drWrCnt
; /* volume write count */
545 u_int32_t drXTClpSiz
; /* clump size for extents overflow file */
546 u_int32_t drCTClpSiz
; /* clump size for catalog file */
547 u_int16_t drNmRtDirs
; /* number of directories in root folder */
548 u_int32_t drFilCnt
; /* number of files in volume */
549 u_int32_t drDirCnt
; /* number of directories in volume */
550 u_int32_t drFndrInfo
[8]; /* information used by the Finder */
551 u_int16_t drEmbedSigWord
; /* embedded volume signature (formerly drVCSize) */
552 HFSExtentDescriptor drEmbedExtent
; /* embedded volume location and size (formerly drVBMCSize and drCtlCSize) */
553 u_int32_t drXTFlSize
; /* size of extents overflow file */
554 HFSExtentRecord drXTExtRec
; /* extent record for extents overflow file */
555 u_int32_t drCTFlSize
; /* size of catalog file */
556 HFSExtentRecord drCTExtRec
; /* extent record for catalog file */
558 typedef struct HFSMasterDirectoryBlock HFSMasterDirectoryBlock
;
561 #ifdef __APPLE_API_UNSTABLE
562 #define SET_HFS_TEXT_ENCODING(hint) \
563 (0x656e6300 | ((hint) & 0xff))
564 #define GET_HFS_TEXT_ENCODING(hint) \
565 (((hint) & 0xffffff00) == 0x656e6300 ? (hint) & 0x000000ff : 0xffffffffU)
566 #endif /* __APPLE_API_UNSTABLE */
569 /* HFS Plus Volume Header - 512 bytes */
570 /* Stored at sector #2 (3rd sector) and second-to-last sector. */
571 struct HFSPlusVolumeHeader
{
572 u_int16_t signature
; /* == kHFSPlusSigWord */
573 u_int16_t version
; /* == kHFSPlusVersion */
574 u_int32_t attributes
; /* volume attributes */
575 u_int32_t lastMountedVersion
; /* implementation version which last mounted volume */
576 u_int32_t journalInfoBlock
; /* block addr of journal info (if volume is journaled, zero otherwise) */
578 u_int32_t createDate
; /* date and time of volume creation */
579 u_int32_t modifyDate
; /* date and time of last modification */
580 u_int32_t backupDate
; /* date and time of last backup */
581 u_int32_t checkedDate
; /* date and time of last disk check */
583 u_int32_t fileCount
; /* number of files in volume */
584 u_int32_t folderCount
; /* number of directories in volume */
586 u_int32_t blockSize
; /* size (in bytes) of allocation blocks */
587 u_int32_t totalBlocks
; /* number of allocation blocks in volume (includes this header and VBM*/
588 u_int32_t freeBlocks
; /* number of unused allocation blocks */
590 u_int32_t nextAllocation
; /* start of next allocation search */
591 u_int32_t rsrcClumpSize
; /* default resource fork clump size */
592 u_int32_t dataClumpSize
; /* default data fork clump size */
593 u_int32_t nextCatalogID
; /* next unused catalog node ID */
595 u_int32_t writeCount
; /* volume write count */
596 u_int64_t encodingsBitmap
; /* which encodings have been use on this volume */
598 u_int8_t finderInfo
[32]; /* information used by the Finder */
600 HFSPlusForkData allocationFile
; /* allocation bitmap file */
601 HFSPlusForkData extentsFile
; /* extents B-tree file */
602 HFSPlusForkData catalogFile
; /* catalog B-tree file */
603 HFSPlusForkData attributesFile
; /* extended attributes B-tree file */
604 HFSPlusForkData startupFile
; /* boot file (secondary loader) */
606 typedef struct HFSPlusVolumeHeader HFSPlusVolumeHeader
;
609 /* B-tree structures */
618 u_int8_t rawData
[kMaxKeyLength
+2];
620 typedef union BTreeKey BTreeKey
;
622 /* BTNodeDescriptor -- Every B-tree node starts with these fields. */
623 struct BTNodeDescriptor
{
624 u_int32_t fLink
; /* next node at this level*/
625 u_int32_t bLink
; /* previous node at this level*/
626 int8_t kind
; /* kind of node (leaf, index, header, map)*/
627 u_int8_t height
; /* zero for header, map; child is one more than parent*/
628 u_int16_t numRecords
; /* number of records in this node*/
629 u_int16_t reserved
; /* reserved - initialized as zero */
631 typedef struct BTNodeDescriptor BTNodeDescriptor
;
633 /* Constants for BTNodeDescriptor kind */
641 /* BTHeaderRec -- The first record of a B-tree header node */
643 u_int16_t treeDepth
; /* maximum height (usually leaf nodes) */
644 u_int32_t rootNode
; /* node number of root node */
645 u_int32_t leafRecords
; /* number of leaf records in all leaf nodes */
646 u_int32_t firstLeafNode
; /* node number of first leaf node */
647 u_int32_t lastLeafNode
; /* node number of last leaf node */
648 u_int16_t nodeSize
; /* size of a node, in bytes */
649 u_int16_t maxKeyLength
; /* reserved */
650 u_int32_t totalNodes
; /* total number of nodes in tree */
651 u_int32_t freeNodes
; /* number of unused (free) nodes in tree */
652 u_int16_t reserved1
; /* unused */
653 u_int32_t clumpSize
; /* reserved */
654 u_int8_t btreeType
; /* reserved */
655 u_int8_t keyCompareType
; /* Key string Comparison Type */
656 u_int32_t attributes
; /* persistent attributes about the tree */
657 u_int32_t reserved3
[16]; /* reserved */
659 typedef struct BTHeaderRec BTHeaderRec
;
661 /* Constants for BTHeaderRec attributes */
663 kBTBadCloseMask
= 0x00000001, /* reserved */
664 kBTBigKeysMask
= 0x00000002, /* key length field is 16 bits */
665 kBTVariableIndexKeysMask
= 0x00000004 /* keys in index nodes are variable length */
669 /* Catalog Key Name Comparison Type */
671 kHFSCaseFolding
= 0xCF, /* case folding (case-insensitive) */
672 kHFSBinaryCompare
= 0xBC /* binary compare (case-sensitive) */
675 /* JournalInfoBlock - Structure that describes where our journal lives */
676 struct JournalInfoBlock
{
678 u_int32_t device_signature
[8]; // signature used to locate our device.
679 u_int64_t offset
; // byte offset to the journal on the device
680 u_int64_t size
; // size in bytes of the journal
681 u_int32_t reserved
[32];
683 typedef struct JournalInfoBlock JournalInfoBlock
;
686 kJIJournalInFSMask
= 0x00000001,
687 kJIJournalOnOtherDeviceMask
= 0x00000002,
688 kJIJournalNeedInitMask
= 0x00000004
692 #pragma options align=reset
698 #endif /* __HFS_FORMAT__ */