]> git.saurik.com Git - apple/xnu.git/blame - bsd/hfs/hfs_format.h
xnu-1699.24.23.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_format.h
CommitLineData
1c79356b 1/*
b0d623f7 2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28#ifndef __HFS_FORMAT__
29#define __HFS_FORMAT__
30
55e303ae 31#include <sys/types.h>
9bccf70c
A
32#include <sys/appleapiopts.h>
33
1c79356b
A
34/*
35 * hfs_format.c
36 *
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.
39 *
40 * http://developer.apple.com/technotes/tn/tn1150.html
41 *
42 */
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/* some on-disk hfs structures have 68K alignment (misaligned) */
1c79356b
A
49
50/* Signatures used to differentiate between HFS and HFS Plus volumes */
51enum {
52 kHFSSigWord = 0x4244, /* 'BD' in ASCII */
53 kHFSPlusSigWord = 0x482B, /* 'H+' in ASCII */
55e303ae
A
54 kHFSXSigWord = 0x4858, /* 'HX' in ASCII */
55
56 kHFSPlusVersion = 0x0004, /* 'H+' volumes are version 4 only */
57 kHFSXVersion = 0x0005, /* 'HX' volumes start with version 5 */
58
b4c24cb9 59 kHFSPlusMountVersion = 0x31302E30, /* '10.0' for Mac OS X */
91447636
A
60 kHFSJMountVersion = 0x4846534a, /* 'HFSJ' for journaled HFS+ on OS X */
61 kFSKMountVersion = 0x46534b21 /* 'FSK!' for failed journal replay */
1c79356b
A
62};
63
64
9bccf70c 65#ifdef __APPLE_API_PRIVATE
1c79356b 66/*
2d21ac55
A
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.
1c79356b 69 *
2d21ac55
A
70 * These directories and their contents are not exported from the filesystem
71 * under Mac OS X.
1c79356b 72 */
2d21ac55
A
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"
1c79356b
A
75
76/*
2d21ac55
A
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.
79 *
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.
1c79356b
A
82 *
83 * e.g. iNode7182000 and temp3296
84 */
85#define HFS_INODE_PREFIX "iNode"
86#define HFS_DELETE_PREFIX "temp"
87
2d21ac55
A
88/*
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.
91 *
92 * e.g. dir_555
93 */
94#define HFS_DIRINODE_PREFIX "dir_"
95
96/*
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.
101 *
102 * This extended attribute is private (i.e. its not
103 * exported in the getxattr/listxattr POSIX APIs).
104 */
105#define FIRST_LINK_XATTR_NAME "com.apple.system.hfs.firstlink"
106#define FIRST_LINK_XATTR_REC_SIZE (sizeof(HFSPlusAttrData) - 2 + 12)
107
b0d623f7
A
108/*
109 * The name space ID for generating an HFS volume UUID
110 *
111 * B3E20F39-F292-11D6-97A4-00306543ECAC
112 */
113#define HFS_UUID_NAMESPACE_ID "\xB3\xE2\x0F\x39\xF2\x92\x11\xD6\x97\xA4\x00\x30\x65\x43\xEC\xAC"
114
9bccf70c
A
115#endif /* __APPLE_API_PRIVATE */
116
1c79356b
A
117/*
118 * Indirect link files (hard links) have the following type/creator.
119 */
120enum {
121 kHardLinkFileType = 0x686C6E6B, /* 'hlnk' */
122 kHFSPlusCreator = 0x6866732B /* 'hfs+' */
123};
124
125
2d21ac55
A
126/*
127 * File type and creator for symbolic links
128 */
129enum {
130 kSymLinkFileType = 0x736C6E6B, /* 'slnk' */
131 kSymLinkCreator = 0x72686170 /* 'rhap' */
132};
133
134
91447636
A
135#ifndef _HFSUNISTR255_DEFINED_
136#define _HFSUNISTR255_DEFINED_
1c79356b
A
137/* Unicode strings are used for HFS Plus file and folder names */
138struct HFSUniStr255 {
139 u_int16_t length; /* number of unicode characters */
140 u_int16_t unicode[255]; /* unicode characters */
2d21ac55 141} __attribute__((aligned(2), packed));
1c79356b
A
142typedef struct HFSUniStr255 HFSUniStr255;
143typedef const HFSUniStr255 *ConstHFSUniStr255Param;
91447636 144#endif /* _HFSUNISTR255_DEFINED_ */
1c79356b
A
145
146enum {
147 kHFSMaxVolumeNameChars = 27,
148 kHFSMaxFileNameChars = 31,
149 kHFSPlusMaxFileNameChars = 255
150};
151
152
153/* Extent overflow file data structures */
154
155/* HFS Extent key */
156struct HFSExtentKey {
157 u_int8_t keyLength; /* length of key, excluding this field */
158 u_int8_t forkType; /* 0 = data fork, FF = resource fork */
159 u_int32_t fileID; /* file ID */
160 u_int16_t startBlock; /* first file allocation block number in this extent */
2d21ac55 161} __attribute__((aligned(2), packed));
1c79356b
A
162typedef struct HFSExtentKey HFSExtentKey;
163
164/* HFS Plus Extent key */
165struct HFSPlusExtentKey {
166 u_int16_t keyLength; /* length of key, excluding this field */
167 u_int8_t forkType; /* 0 = data fork, FF = resource fork */
168 u_int8_t pad; /* make the other fields align on 32-bit boundary */
169 u_int32_t fileID; /* file ID */
170 u_int32_t startBlock; /* first file allocation block number in this extent */
2d21ac55 171} __attribute__((aligned(2), packed));
1c79356b
A
172typedef struct HFSPlusExtentKey HFSPlusExtentKey;
173
174/* Number of extent descriptors per extent record */
175enum {
176 kHFSExtentDensity = 3,
177 kHFSPlusExtentDensity = 8
178};
179
180/* HFS extent descriptor */
181struct HFSExtentDescriptor {
182 u_int16_t startBlock; /* first allocation block */
183 u_int16_t blockCount; /* number of allocation blocks */
2d21ac55 184} __attribute__((aligned(2), packed));
1c79356b
A
185typedef struct HFSExtentDescriptor HFSExtentDescriptor;
186
187/* HFS Plus extent descriptor */
188struct HFSPlusExtentDescriptor {
189 u_int32_t startBlock; /* first allocation block */
190 u_int32_t blockCount; /* number of allocation blocks */
2d21ac55 191} __attribute__((aligned(2), packed));
1c79356b
A
192typedef struct HFSPlusExtentDescriptor HFSPlusExtentDescriptor;
193
194/* HFS extent record */
195typedef HFSExtentDescriptor HFSExtentRecord[3];
196
197/* HFS Plus extent record */
198typedef HFSPlusExtentDescriptor HFSPlusExtentRecord[8];
199
200
201/* Finder information */
202struct FndrFileInfo {
203 u_int32_t fdType; /* file type */
204 u_int32_t fdCreator; /* file creator */
205 u_int16_t fdFlags; /* Finder flags */
206 struct {
207 int16_t v; /* file's location */
208 int16_t h;
209 } fdLocation;
210 int16_t opaque;
2d21ac55 211} __attribute__((aligned(2), packed));
1c79356b
A
212typedef struct FndrFileInfo FndrFileInfo;
213
214struct FndrDirInfo {
215 struct { /* folder's window rectangle */
216 int16_t top;
217 int16_t left;
218 int16_t bottom;
219 int16_t right;
220 } frRect;
221 unsigned short frFlags; /* Finder flags */
222 struct {
223 u_int16_t v; /* folder's location */
224 u_int16_t h;
225 } frLocation;
226 int16_t opaque;
2d21ac55 227} __attribute__((aligned(2), packed));
1c79356b
A
228typedef struct FndrDirInfo FndrDirInfo;
229
230struct FndrOpaqueInfo {
231 int8_t opaque[16];
2d21ac55 232} __attribute__((aligned(2), packed));
1c79356b
A
233typedef struct FndrOpaqueInfo FndrOpaqueInfo;
234
6d2010ae
A
235struct FndrExtendedDirInfo {
236 u_int32_t point;
237 u_int32_t date_added;
238 u_int16_t extended_flags;
239 u_int16_t reserved3;
240 u_int32_t reserved4;
241} __attribute__((aligned(2), packed));
242
243struct FndrExtendedFileInfo {
244 u_int32_t reserved1;
245 u_int32_t date_added;
246 u_int16_t extended_flags;
247 u_int16_t reserved2;
248 u_int32_t reserved3;
249} __attribute__((aligned(2), packed));
1c79356b
A
250
251/* HFS Plus Fork data info - 80 bytes */
252struct HFSPlusForkData {
253 u_int64_t logicalSize; /* fork's logical size in bytes */
254 u_int32_t clumpSize; /* fork's clump size in bytes */
255 u_int32_t totalBlocks; /* total blocks used by this fork */
256 HFSPlusExtentRecord extents; /* initial set of extents */
2d21ac55 257} __attribute__((aligned(2), packed));
1c79356b
A
258typedef struct HFSPlusForkData HFSPlusForkData;
259
260
261/* Mac OS X has 16 bytes worth of "BSD" info.
262 *
263 * Note: Mac OS 9 implementations and applications
264 * should preserve, but not change, this information.
265 */
266struct HFSPlusBSDInfo {
2d21ac55
A
267 u_int32_t ownerID; /* user-id of owner or hard link chain previous link */
268 u_int32_t groupID; /* group-id of owner or hard link chain next link */
1c79356b
A
269 u_int8_t adminFlags; /* super-user changeable flags */
270 u_int8_t ownerFlags; /* owner changeable flags */
271 u_int16_t fileMode; /* file type and permission bits */
272 union {
273 u_int32_t iNodeNum; /* indirect node number (hard links only) */
274 u_int32_t linkCount; /* links that refer to this indirect node */
275 u_int32_t rawDevice; /* special file device (FBLK and FCHR only) */
276 } special;
2d21ac55 277} __attribute__((aligned(2), packed));
1c79356b
A
278typedef struct HFSPlusBSDInfo HFSPlusBSDInfo;
279
2d21ac55
A
280/*
281 * Hardlink "links" resolve to an inode
282 * and the actual uid/gid comes from that
283 * inode.
284 *
285 * We repurpose the links's uid/gid fields
286 * for the hardlink link chain. The chain
287 * consists of a doubly linked list of file
288 * ids.
289 */
290
291#define hl_firstLinkID reserved1 /* Valid only if HasLinkChain flag is set (indirect nodes only) */
292
293#define hl_prevLinkID bsdInfo.ownerID /* Valid only if HasLinkChain flag is set */
294#define hl_nextLinkID bsdInfo.groupID /* Valid only if HasLinkChain flag is set */
295
296#define hl_linkReference bsdInfo.special.iNodeNum
297#define hl_linkCount bsdInfo.special.linkCount
298
1c79356b
A
299
300/* Catalog file data structures */
301
302enum {
303 kHFSRootParentID = 1, /* Parent ID of the root folder */
304 kHFSRootFolderID = 2, /* Folder ID of the root folder */
305 kHFSExtentsFileID = 3, /* File ID of the extents file */
306 kHFSCatalogFileID = 4, /* File ID of the catalog file */
307 kHFSBadBlockFileID = 5, /* File ID of the bad allocation block file */
308 kHFSAllocationFileID = 6, /* File ID of the allocation file (HFS Plus only) */
309 kHFSStartupFileID = 7, /* File ID of the startup file (HFS Plus only) */
310 kHFSAttributesFileID = 8, /* File ID of the attribute file (HFS Plus only) */
2d21ac55
A
311 kHFSAttributeDataFileID = 13, /* Used in Mac OS X runtime for extent based attributes */
312 /* kHFSAttributeDataFileID is never stored on disk. */
55e303ae 313 kHFSRepairCatalogFileID = 14, /* Used when rebuilding Catalog B-tree */
1c79356b
A
314 kHFSBogusExtentFileID = 15, /* Used for exchanging extents in extents file */
315 kHFSFirstUserCatalogNodeID = 16
316};
317
318/* HFS catalog key */
319struct HFSCatalogKey {
320 u_int8_t keyLength; /* key length (in bytes) */
321 u_int8_t reserved; /* reserved (set to zero) */
322 u_int32_t parentID; /* parent folder ID */
91447636 323 u_int8_t nodeName[kHFSMaxFileNameChars + 1]; /* catalog node name */
2d21ac55 324} __attribute__((aligned(2), packed));
1c79356b
A
325typedef struct HFSCatalogKey HFSCatalogKey;
326
327/* HFS Plus catalog key */
328struct HFSPlusCatalogKey {
329 u_int16_t keyLength; /* key length (in bytes) */
330 u_int32_t parentID; /* parent folder ID */
331 HFSUniStr255 nodeName; /* catalog node name */
2d21ac55 332} __attribute__((aligned(2), packed));
1c79356b
A
333typedef struct HFSPlusCatalogKey HFSPlusCatalogKey;
334
335/* Catalog record types */
336enum {
337 /* HFS Catalog Records */
338 kHFSFolderRecord = 0x0100, /* Folder record */
339 kHFSFileRecord = 0x0200, /* File record */
340 kHFSFolderThreadRecord = 0x0300, /* Folder thread record */
341 kHFSFileThreadRecord = 0x0400, /* File thread record */
342
343 /* HFS Plus Catalog Records */
344 kHFSPlusFolderRecord = 1, /* Folder record */
345 kHFSPlusFileRecord = 2, /* File record */
346 kHFSPlusFolderThreadRecord = 3, /* Folder thread record */
347 kHFSPlusFileThreadRecord = 4 /* File thread record */
348};
349
350
351/* Catalog file record flags */
352enum {
353 kHFSFileLockedBit = 0x0000, /* file is locked and cannot be written to */
354 kHFSFileLockedMask = 0x0001,
91447636 355
1c79356b 356 kHFSThreadExistsBit = 0x0001, /* a file thread record exists for this file */
91447636
A
357 kHFSThreadExistsMask = 0x0002,
358
359 kHFSHasAttributesBit = 0x0002, /* object has extended attributes */
360 kHFSHasAttributesMask = 0x0004,
361
362 kHFSHasSecurityBit = 0x0003, /* object has security data (ACLs) */
2d21ac55
A
363 kHFSHasSecurityMask = 0x0008,
364
365 kHFSHasFolderCountBit = 0x0004, /* only for HFSX, folder maintains a separate sub-folder count */
366 kHFSHasFolderCountMask = 0x0010, /* (sum of folder records and directory hard links) */
367
368 kHFSHasLinkChainBit = 0x0005, /* has hardlink chain (inode or link) */
369 kHFSHasLinkChainMask = 0x0020,
370
371 kHFSHasChildLinkBit = 0x0006, /* folder has a child that's a dir link */
6d2010ae
A
372 kHFSHasChildLinkMask = 0x0040,
373
374 kHFSHasDateAddedBit = 0x0007, /* File/Folder has the date-added stored in the finder info. */
375 kHFSHasDateAddedMask = 0x0080
376
1c79356b
A
377};
378
379
380/* HFS catalog folder record - 70 bytes */
381struct HFSCatalogFolder {
382 int16_t recordType; /* == kHFSFolderRecord */
383 u_int16_t flags; /* folder flags */
384 u_int16_t valence; /* folder valence */
385 u_int32_t folderID; /* folder ID */
386 u_int32_t createDate; /* date and time of creation */
387 u_int32_t modifyDate; /* date and time of last modification */
388 u_int32_t backupDate; /* date and time of last backup */
389 FndrDirInfo userInfo; /* Finder information */
390 FndrOpaqueInfo finderInfo; /* additional Finder information */
391 u_int32_t reserved[4]; /* reserved - initialized as zero */
2d21ac55 392} __attribute__((aligned(2), packed));
1c79356b
A
393typedef struct HFSCatalogFolder HFSCatalogFolder;
394
395/* HFS Plus catalog folder record - 88 bytes */
396struct HFSPlusCatalogFolder {
397 int16_t recordType; /* == kHFSPlusFolderRecord */
398 u_int16_t flags; /* file flags */
2d21ac55 399 u_int32_t valence; /* folder's item count */
1c79356b
A
400 u_int32_t folderID; /* folder ID */
401 u_int32_t createDate; /* date and time of creation */
402 u_int32_t contentModDate; /* date and time of last content modification */
403 u_int32_t attributeModDate; /* date and time of last attribute modification */
404 u_int32_t accessDate; /* date and time of last access (MacOS X only) */
405 u_int32_t backupDate; /* date and time of last backup */
406 HFSPlusBSDInfo bsdInfo; /* permissions (for MacOS X) */
407 FndrDirInfo userInfo; /* Finder information */
408 FndrOpaqueInfo finderInfo; /* additional Finder information */
409 u_int32_t textEncoding; /* hint for name conversions */
2d21ac55
A
410 u_int32_t folderCount; /* number of enclosed folders, active when HasFolderCount is set */
411} __attribute__((aligned(2), packed));
1c79356b
A
412typedef struct HFSPlusCatalogFolder HFSPlusCatalogFolder;
413
414/* HFS catalog file record - 102 bytes */
415struct HFSCatalogFile {
416 int16_t recordType; /* == kHFSFileRecord */
417 u_int8_t flags; /* file flags */
418 int8_t fileType; /* file type (unused ?) */
419 FndrFileInfo userInfo; /* Finder information */
420 u_int32_t fileID; /* file ID */
421 u_int16_t dataStartBlock; /* not used - set to zero */
422 int32_t dataLogicalSize; /* logical EOF of data fork */
423 int32_t dataPhysicalSize; /* physical EOF of data fork */
424 u_int16_t rsrcStartBlock; /* not used - set to zero */
425 int32_t rsrcLogicalSize; /* logical EOF of resource fork */
426 int32_t rsrcPhysicalSize; /* physical EOF of resource fork */
427 u_int32_t createDate; /* date and time of creation */
428 u_int32_t modifyDate; /* date and time of last modification */
429 u_int32_t backupDate; /* date and time of last backup */
430 FndrOpaqueInfo finderInfo; /* additional Finder information */
431 u_int16_t clumpSize; /* file clump size (not used) */
432 HFSExtentRecord dataExtents; /* first data fork extent record */
433 HFSExtentRecord rsrcExtents; /* first resource fork extent record */
434 u_int32_t reserved; /* reserved - initialized as zero */
2d21ac55 435} __attribute__((aligned(2), packed));
1c79356b
A
436typedef struct HFSCatalogFile HFSCatalogFile;
437
438/* HFS Plus catalog file record - 248 bytes */
439struct HFSPlusCatalogFile {
440 int16_t recordType; /* == kHFSPlusFileRecord */
441 u_int16_t flags; /* file flags */
442 u_int32_t reserved1; /* reserved - initialized as zero */
443 u_int32_t fileID; /* file ID */
444 u_int32_t createDate; /* date and time of creation */
445 u_int32_t contentModDate; /* date and time of last content modification */
446 u_int32_t attributeModDate; /* date and time of last attribute modification */
447 u_int32_t accessDate; /* date and time of last access (MacOS X only) */
448 u_int32_t backupDate; /* date and time of last backup */
449 HFSPlusBSDInfo bsdInfo; /* permissions (for MacOS X) */
450 FndrFileInfo userInfo; /* Finder information */
451 FndrOpaqueInfo finderInfo; /* additional Finder information */
452 u_int32_t textEncoding; /* hint for name conversions */
2d21ac55 453 u_int32_t reserved2; /* reserved - initialized as zero */
1c79356b 454
2d21ac55 455 /* Note: these start on double long (64 bit) boundary */
1c79356b
A
456 HFSPlusForkData dataFork; /* size and block data for data fork */
457 HFSPlusForkData resourceFork; /* size and block data for resource fork */
2d21ac55 458} __attribute__((aligned(2), packed));
1c79356b
A
459typedef struct HFSPlusCatalogFile HFSPlusCatalogFile;
460
461/* HFS catalog thread record - 46 bytes */
462struct HFSCatalogThread {
463 int16_t recordType; /* == kHFSFolderThreadRecord or kHFSFileThreadRecord */
464 int32_t reserved[2]; /* reserved - initialized as zero */
465 u_int32_t parentID; /* parent ID for this catalog node */
91447636 466 u_int8_t nodeName[kHFSMaxFileNameChars + 1]; /* name of this catalog node */
2d21ac55 467} __attribute__((aligned(2), packed));
1c79356b
A
468typedef struct HFSCatalogThread HFSCatalogThread;
469
470/* HFS Plus catalog thread record -- 264 bytes */
471struct HFSPlusCatalogThread {
472 int16_t recordType; /* == kHFSPlusFolderThreadRecord or kHFSPlusFileThreadRecord */
473 int16_t reserved; /* reserved - initialized as zero */
474 u_int32_t parentID; /* parent ID for this catalog node */
475 HFSUniStr255 nodeName; /* name of this catalog node (variable length) */
2d21ac55 476} __attribute__((aligned(2), packed));
1c79356b
A
477typedef struct HFSPlusCatalogThread HFSPlusCatalogThread;
478
9bccf70c 479#ifdef __APPLE_API_UNSTABLE
1c79356b
A
480/*
481 These are the types of records in the attribute B-tree. The values were
482 chosen so that they wouldn't conflict with the catalog record types.
483*/
484enum {
2d21ac55
A
485 kHFSPlusAttrInlineData = 0x10, /* attributes whose data fits in a b-tree node */
486 kHFSPlusAttrForkData = 0x20, /* extent based attributes (data lives in extents) */
487 kHFSPlusAttrExtents = 0x30 /* overflow extents for large attributes */
1c79356b 488};
1c79356b
A
489
490
491/*
492 HFSPlusAttrForkData
493 For larger attributes, whose value is stored in allocation blocks.
2d21ac55 494 If the attribute has more than 8 extents, there will be additional
1c79356b
A
495 records (of type HFSPlusAttrExtents) for this attribute.
496*/
497struct HFSPlusAttrForkData {
498 u_int32_t recordType; /* == kHFSPlusAttrForkData*/
499 u_int32_t reserved;
500 HFSPlusForkData theFork; /* size and first extents of value*/
2d21ac55 501} __attribute__((aligned(2), packed));
1c79356b
A
502typedef struct HFSPlusAttrForkData HFSPlusAttrForkData;
503
504/*
505 HFSPlusAttrExtents
506 This record contains information about overflow extents for large,
507 fragmented attributes.
508*/
509struct HFSPlusAttrExtents {
510 u_int32_t recordType; /* == kHFSPlusAttrExtents*/
511 u_int32_t reserved;
512 HFSPlusExtentRecord extents; /* additional extents*/
2d21ac55 513} __attribute__((aligned(2), packed));
1c79356b
A
514typedef struct HFSPlusAttrExtents HFSPlusAttrExtents;
515
91447636
A
516/*
517 * Atrributes B-tree Data Record
518 *
519 * For small attributes, whose entire value is stored
520 * within a single B-tree record.
521 */
522struct HFSPlusAttrData {
523 u_int32_t recordType; /* == kHFSPlusAttrInlineData */
524 u_int32_t reserved[2];
525 u_int32_t attrSize; /* size of attribute data in bytes */
526 u_int8_t attrData[2]; /* variable length */
2d21ac55 527} __attribute__((aligned(2), packed));
91447636
A
528typedef struct HFSPlusAttrData HFSPlusAttrData;
529
530
531/* HFSPlusAttrInlineData is obsolete use HFSPlusAttrData instead */
532struct HFSPlusAttrInlineData {
533 u_int32_t recordType;
534 u_int32_t reserved;
535 u_int32_t logicalSize;
536 u_int8_t userData[2];
2d21ac55 537} __attribute__((aligned(2), packed));
91447636
A
538typedef struct HFSPlusAttrInlineData HFSPlusAttrInlineData;
539
540
1c79356b
A
541/* A generic Attribute Record*/
542union HFSPlusAttrRecord {
543 u_int32_t recordType;
91447636
A
544 HFSPlusAttrInlineData inlineData; /* NOT USED */
545 HFSPlusAttrData attrData;
1c79356b
A
546 HFSPlusAttrForkData forkData;
547 HFSPlusAttrExtents overflowExtents;
548};
549typedef union HFSPlusAttrRecord HFSPlusAttrRecord;
550
91447636 551/* Attribute key */
3a60a9f5 552enum { kHFSMaxAttrNameLen = 127 };
91447636
A
553struct HFSPlusAttrKey {
554 u_int16_t keyLength; /* key length (in bytes) */
555 u_int16_t pad; /* set to zero */
556 u_int32_t fileID; /* file associated with attribute */
2d21ac55 557 u_int32_t startBlock; /* first allocation block number for extents */
91447636 558 u_int16_t attrNameLen; /* number of unicode characters */
3a60a9f5 559 u_int16_t attrName[kHFSMaxAttrNameLen]; /* attribute name (Unicode) */
2d21ac55 560} __attribute__((aligned(2), packed));
91447636
A
561typedef struct HFSPlusAttrKey HFSPlusAttrKey;
562
563#define kHFSPlusAttrKeyMaximumLength (sizeof(HFSPlusAttrKey) - sizeof(u_int16_t))
3a60a9f5 564#define kHFSPlusAttrKeyMinimumLength (kHFSPlusAttrKeyMaximumLength - kHFSMaxAttrNameLen*sizeof(u_int16_t))
91447636
A
565
566#endif /* __APPLE_API_UNSTABLE */
567
568
1c79356b
A
569/* Key and node lengths */
570enum {
571 kHFSPlusExtentKeyMaximumLength = sizeof(HFSPlusExtentKey) - sizeof(u_int16_t),
572 kHFSExtentKeyMaximumLength = sizeof(HFSExtentKey) - sizeof(u_int8_t),
573 kHFSPlusCatalogKeyMaximumLength = sizeof(HFSPlusCatalogKey) - sizeof(u_int16_t),
574 kHFSPlusCatalogKeyMinimumLength = kHFSPlusCatalogKeyMaximumLength - sizeof(HFSUniStr255) + sizeof(u_int16_t),
575 kHFSCatalogKeyMaximumLength = sizeof(HFSCatalogKey) - sizeof(u_int8_t),
576 kHFSCatalogKeyMinimumLength = kHFSCatalogKeyMaximumLength - (kHFSMaxFileNameChars + 1) + sizeof(u_int8_t),
577 kHFSPlusCatalogMinNodeSize = 4096,
578 kHFSPlusExtentMinNodeSize = 512,
579 kHFSPlusAttrMinNodeSize = 4096
580};
1c79356b
A
581
582/* HFS and HFS Plus volume attribute bits */
583enum {
b0d623f7 584 /* Bits 0-6 are reserved (always cleared by MountVol call) */
1c79356b
A
585 kHFSVolumeHardwareLockBit = 7, /* volume is locked by hardware */
586 kHFSVolumeUnmountedBit = 8, /* volume was successfully unmounted */
587 kHFSVolumeSparedBlocksBit = 9, /* volume has bad blocks spared */
588 kHFSVolumeNoCacheRequiredBit = 10, /* don't cache volume blocks (i.e. RAM or ROM disk) */
589 kHFSBootVolumeInconsistentBit = 11, /* boot volume is inconsistent (System 7.6 and later) */
590 kHFSCatalogNodeIDsReusedBit = 12,
b4c24cb9 591 kHFSVolumeJournaledBit = 13, /* this volume has a journal on it */
55e303ae 592 kHFSVolumeInconsistentBit = 14, /* serious inconsistencies detected at runtime */
1c79356b 593 kHFSVolumeSoftwareLockBit = 15, /* volume is locked by software */
b0d623f7
A
594 /*
595 * HFS only has 16 bits of attributes in the MDB, but HFS Plus has 32 bits.
596 * Therefore, bits 16-31 can only be used on HFS Plus.
597 */
598 kHFSUnusedNodeFixBit = 31, /* Unused nodes in the Catalog B-tree have been zero-filled. See Radar #6947811. */
6d2010ae
A
599 kHFSContentProtectionBit = 30, /* Volume has per-file content protection */
600
1c79356b
A
601 kHFSVolumeHardwareLockMask = 1 << kHFSVolumeHardwareLockBit,
602 kHFSVolumeUnmountedMask = 1 << kHFSVolumeUnmountedBit,
603 kHFSVolumeSparedBlocksMask = 1 << kHFSVolumeSparedBlocksBit,
604 kHFSVolumeNoCacheRequiredMask = 1 << kHFSVolumeNoCacheRequiredBit,
605 kHFSBootVolumeInconsistentMask = 1 << kHFSBootVolumeInconsistentBit,
606 kHFSCatalogNodeIDsReusedMask = 1 << kHFSCatalogNodeIDsReusedBit,
b4c24cb9 607 kHFSVolumeJournaledMask = 1 << kHFSVolumeJournaledBit,
55e303ae 608 kHFSVolumeInconsistentMask = 1 << kHFSVolumeInconsistentBit,
1c79356b 609 kHFSVolumeSoftwareLockMask = 1 << kHFSVolumeSoftwareLockBit,
b0d623f7 610 kHFSUnusedNodeFixMask = 1 << kHFSUnusedNodeFixBit,
6d2010ae 611 kHFSContentProtectionMask = 1 << kHFSContentProtectionBit,
1c79356b
A
612 kHFSMDBAttributesMask = 0x8380
613};
614
b0d623f7
A
615enum {
616 kHFSUnusedNodesFixDate = 0xc5ef2480 /* March 25, 2009 */
617};
1c79356b
A
618
619/* HFS Master Directory Block - 162 bytes */
620/* Stored at sector #2 (3rd sector) and second-to-last sector. */
621struct HFSMasterDirectoryBlock {
622 u_int16_t drSigWord; /* == kHFSSigWord */
623 u_int32_t drCrDate; /* date and time of volume creation */
624 u_int32_t drLsMod; /* date and time of last modification */
625 u_int16_t drAtrb; /* volume attributes */
626 u_int16_t drNmFls; /* number of files in root folder */
627 u_int16_t drVBMSt; /* first block of volume bitmap */
628 u_int16_t drAllocPtr; /* start of next allocation search */
629 u_int16_t drNmAlBlks; /* number of allocation blocks in volume */
630 u_int32_t drAlBlkSiz; /* size (in bytes) of allocation blocks */
631 u_int32_t drClpSiz; /* default clump size */
632 u_int16_t drAlBlSt; /* first allocation block in volume */
633 u_int32_t drNxtCNID; /* next unused catalog node ID */
634 u_int16_t drFreeBks; /* number of unused allocation blocks */
91447636 635 u_int8_t drVN[kHFSMaxVolumeNameChars + 1]; /* volume name */
1c79356b
A
636 u_int32_t drVolBkUp; /* date and time of last backup */
637 u_int16_t drVSeqNum; /* volume backup sequence number */
638 u_int32_t drWrCnt; /* volume write count */
639 u_int32_t drXTClpSiz; /* clump size for extents overflow file */
640 u_int32_t drCTClpSiz; /* clump size for catalog file */
641 u_int16_t drNmRtDirs; /* number of directories in root folder */
642 u_int32_t drFilCnt; /* number of files in volume */
643 u_int32_t drDirCnt; /* number of directories in volume */
644 u_int32_t drFndrInfo[8]; /* information used by the Finder */
645 u_int16_t drEmbedSigWord; /* embedded volume signature (formerly drVCSize) */
646 HFSExtentDescriptor drEmbedExtent; /* embedded volume location and size (formerly drVBMCSize and drCtlCSize) */
647 u_int32_t drXTFlSize; /* size of extents overflow file */
648 HFSExtentRecord drXTExtRec; /* extent record for extents overflow file */
649 u_int32_t drCTFlSize; /* size of catalog file */
650 HFSExtentRecord drCTExtRec; /* extent record for catalog file */
2d21ac55 651} __attribute__((aligned(2), packed));
1c79356b
A
652typedef struct HFSMasterDirectoryBlock HFSMasterDirectoryBlock;
653
654
55e303ae
A
655#ifdef __APPLE_API_UNSTABLE
656#define SET_HFS_TEXT_ENCODING(hint) \
657 (0x656e6300 | ((hint) & 0xff))
658#define GET_HFS_TEXT_ENCODING(hint) \
659 (((hint) & 0xffffff00) == 0x656e6300 ? (hint) & 0x000000ff : 0xffffffffU)
660#endif /* __APPLE_API_UNSTABLE */
661
662
1c79356b
A
663/* HFS Plus Volume Header - 512 bytes */
664/* Stored at sector #2 (3rd sector) and second-to-last sector. */
665struct HFSPlusVolumeHeader {
666 u_int16_t signature; /* == kHFSPlusSigWord */
667 u_int16_t version; /* == kHFSPlusVersion */
668 u_int32_t attributes; /* volume attributes */
669 u_int32_t lastMountedVersion; /* implementation version which last mounted volume */
b4c24cb9 670 u_int32_t journalInfoBlock; /* block addr of journal info (if volume is journaled, zero otherwise) */
1c79356b
A
671
672 u_int32_t createDate; /* date and time of volume creation */
673 u_int32_t modifyDate; /* date and time of last modification */
674 u_int32_t backupDate; /* date and time of last backup */
675 u_int32_t checkedDate; /* date and time of last disk check */
676
677 u_int32_t fileCount; /* number of files in volume */
678 u_int32_t folderCount; /* number of directories in volume */
679
680 u_int32_t blockSize; /* size (in bytes) of allocation blocks */
681 u_int32_t totalBlocks; /* number of allocation blocks in volume (includes this header and VBM*/
682 u_int32_t freeBlocks; /* number of unused allocation blocks */
683
684 u_int32_t nextAllocation; /* start of next allocation search */
685 u_int32_t rsrcClumpSize; /* default resource fork clump size */
686 u_int32_t dataClumpSize; /* default data fork clump size */
687 u_int32_t nextCatalogID; /* next unused catalog node ID */
688
689 u_int32_t writeCount; /* volume write count */
690 u_int64_t encodingsBitmap; /* which encodings have been use on this volume */
691
692 u_int8_t finderInfo[32]; /* information used by the Finder */
693
694 HFSPlusForkData allocationFile; /* allocation bitmap file */
695 HFSPlusForkData extentsFile; /* extents B-tree file */
696 HFSPlusForkData catalogFile; /* catalog B-tree file */
697 HFSPlusForkData attributesFile; /* extended attributes B-tree file */
698 HFSPlusForkData startupFile; /* boot file (secondary loader) */
2d21ac55 699} __attribute__((aligned(2), packed));
1c79356b
A
700typedef struct HFSPlusVolumeHeader HFSPlusVolumeHeader;
701
702
703/* B-tree structures */
704
705enum BTreeKeyLimits{
706 kMaxKeyLength = 520
707};
708
709union BTreeKey{
710 u_int8_t length8;
711 u_int16_t length16;
712 u_int8_t rawData [kMaxKeyLength+2];
713};
714typedef union BTreeKey BTreeKey;
715
716/* BTNodeDescriptor -- Every B-tree node starts with these fields. */
717struct BTNodeDescriptor {
718 u_int32_t fLink; /* next node at this level*/
719 u_int32_t bLink; /* previous node at this level*/
720 int8_t kind; /* kind of node (leaf, index, header, map)*/
721 u_int8_t height; /* zero for header, map; child is one more than parent*/
722 u_int16_t numRecords; /* number of records in this node*/
723 u_int16_t reserved; /* reserved - initialized as zero */
2d21ac55 724} __attribute__((aligned(2), packed));
1c79356b
A
725typedef struct BTNodeDescriptor BTNodeDescriptor;
726
727/* Constants for BTNodeDescriptor kind */
728enum {
729 kBTLeafNode = -1,
730 kBTIndexNode = 0,
731 kBTHeaderNode = 1,
732 kBTMapNode = 2
733};
734
735/* BTHeaderRec -- The first record of a B-tree header node */
736struct BTHeaderRec {
737 u_int16_t treeDepth; /* maximum height (usually leaf nodes) */
738 u_int32_t rootNode; /* node number of root node */
739 u_int32_t leafRecords; /* number of leaf records in all leaf nodes */
740 u_int32_t firstLeafNode; /* node number of first leaf node */
741 u_int32_t lastLeafNode; /* node number of last leaf node */
742 u_int16_t nodeSize; /* size of a node, in bytes */
743 u_int16_t maxKeyLength; /* reserved */
744 u_int32_t totalNodes; /* total number of nodes in tree */
745 u_int32_t freeNodes; /* number of unused (free) nodes in tree */
746 u_int16_t reserved1; /* unused */
747 u_int32_t clumpSize; /* reserved */
748 u_int8_t btreeType; /* reserved */
55e303ae 749 u_int8_t keyCompareType; /* Key string Comparison Type */
1c79356b
A
750 u_int32_t attributes; /* persistent attributes about the tree */
751 u_int32_t reserved3[16]; /* reserved */
2d21ac55 752} __attribute__((aligned(2), packed));
1c79356b
A
753typedef struct BTHeaderRec BTHeaderRec;
754
755/* Constants for BTHeaderRec attributes */
756enum {
757 kBTBadCloseMask = 0x00000001, /* reserved */
758 kBTBigKeysMask = 0x00000002, /* key length field is 16 bits */
759 kBTVariableIndexKeysMask = 0x00000004 /* keys in index nodes are variable length */
760};
761
55e303ae
A
762
763/* Catalog Key Name Comparison Type */
764enum {
765 kHFSCaseFolding = 0xCF, /* case folding (case-insensitive) */
91447636 766 kHFSBinaryCompare = 0xBC /* binary compare (case-sensitive) */
55e303ae
A
767};
768
b0d623f7
A
769#include <uuid/uuid.h>
770
b4c24cb9 771/* JournalInfoBlock - Structure that describes where our journal lives */
b0d623f7
A
772
773// the original size of the reserved field in the JournalInfoBlock was
774// 32*sizeof(u_int32_t). To keep the total size of the structure the
775// same we subtract the size of new fields (currently: ext_jnl_uuid and
776// machine_uuid). If you add additional fields, place them before the
777// reserved field and subtract their size in this macro.
778//
779#define JIB_RESERVED_SIZE ((32*sizeof(u_int32_t)) - sizeof(uuid_string_t) - 48)
780
b4c24cb9
A
781struct JournalInfoBlock {
782 u_int32_t flags;
783 u_int32_t device_signature[8]; // signature used to locate our device.
784 u_int64_t offset; // byte offset to the journal on the device
785 u_int64_t size; // size in bytes of the journal
b0d623f7
A
786 uuid_string_t ext_jnl_uuid;
787 char machine_serial_num[48];
788 char reserved[JIB_RESERVED_SIZE];
2d21ac55 789} __attribute__((aligned(2), packed));
b4c24cb9
A
790typedef struct JournalInfoBlock JournalInfoBlock;
791
792enum {
793 kJIJournalInFSMask = 0x00000001,
794 kJIJournalOnOtherDeviceMask = 0x00000002,
795 kJIJournalNeedInitMask = 0x00000004
796};
797
b0d623f7
A
798//
799// This the content type uuid for "external journal" GPT
800// partitions. Each instance of a partition also has a
801// uuid that uniquely identifies that instance.
802//
803#define EXTJNL_CONTENT_TYPE_UUID "4A6F7572-6E61-11AA-AA11-00306543ECAC"
804
b4c24cb9 805
1c79356b
A
806#ifdef __cplusplus
807}
808#endif
809
810#endif /* __HFS_FORMAT__ */