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