]> git.saurik.com Git - apple/xnu.git/blame - bsd/hfs/hfs_format.h
xnu-517.12.7.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_format.h
CommitLineData
1c79356b 1/*
55e303ae 2 * Copyright (c) 2000-2003 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
A
25#ifndef __HFSVOLUMES__
26
27#include <sys/types.h>
9bccf70c
A
28#include <sys/appleapiopts.h>
29
1c79356b
A
30/*
31 * hfs_format.c
32 *
33 * This file describes the on-disk format for HFS and HFS Plus volumes.
34 * The HFS Plus volume format is desciibed in detail in Apple Technote 1150.
35 *
36 * http://developer.apple.com/technotes/tn/tn1150.html
37 *
38 */
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* some on-disk hfs structures have 68K alignment (misaligned) */
45#pragma options align=mac68k
46
47/* Signatures used to differentiate between HFS and HFS Plus volumes */
48enum {
49 kHFSSigWord = 0x4244, /* 'BD' in ASCII */
50 kHFSPlusSigWord = 0x482B, /* 'H+' in ASCII */
55e303ae
A
51 kHFSXSigWord = 0x4858, /* 'HX' in ASCII */
52
53 kHFSPlusVersion = 0x0004, /* 'H+' volumes are version 4 only */
54 kHFSXVersion = 0x0005, /* 'HX' volumes start with version 5 */
55
b4c24cb9
A
56 kHFSPlusMountVersion = 0x31302E30, /* '10.0' for Mac OS X */
57 kHFSJMountVersion = 0x4846534a /* 'HFSJ' for journaled HFS+ on OS X */
1c79356b
A
58};
59
60
9bccf70c 61#ifdef __APPLE_API_PRIVATE
1c79356b
A
62/*
63 * Mac OS X has a special directory for linked and unlinked files (HFS Plus only).
64 * This directory and its contents are never exported from the filesystem under
65 * Mac OS X.
66 *
67 * To make this folder name sort last, it has embedded null prefix.
68 * (0xC0, 0x80 in UTF-8)
69 */
70#define HFSPLUSMETADATAFOLDER "\xC0\x80\xC0\x80\xC0\x80\xC0\x80HFS+ Private Data"
71
72/*
73 * Files in the HFS Private Data folder have one of the following prefixes
74 * followed by a decimal number (no leading zeros). For indirect nodes this
75 * number is a 32 bit random number. For unlinked (deleted) files that are
76 * still open, the number is the file ID for that file.
77 *
78 * e.g. iNode7182000 and temp3296
79 */
80#define HFS_INODE_PREFIX "iNode"
81#define HFS_DELETE_PREFIX "temp"
82
9bccf70c
A
83#endif /* __APPLE_API_PRIVATE */
84
1c79356b
A
85/*
86 * Indirect link files (hard links) have the following type/creator.
87 */
88enum {
89 kHardLinkFileType = 0x686C6E6B, /* 'hlnk' */
90 kHFSPlusCreator = 0x6866732B /* 'hfs+' */
91};
92
93
55e303ae 94#ifndef __FILES__
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;
55e303ae 102#endif /* __FILES__ */
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 */
245 u_char nodeName[kHFSMaxFileNameChars + 1]; /* catalog node name */
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,
277 kHFSThreadExistsBit = 0x0001, /* a file thread record exists for this file */
278 kHFSThreadExistsMask = 0x0002
279};
280
281
282/* HFS catalog folder record - 70 bytes */
283struct HFSCatalogFolder {
284 int16_t recordType; /* == kHFSFolderRecord */
285 u_int16_t flags; /* folder flags */
286 u_int16_t valence; /* folder valence */
287 u_int32_t folderID; /* folder ID */
288 u_int32_t createDate; /* date and time of creation */
289 u_int32_t modifyDate; /* date and time of last modification */
290 u_int32_t backupDate; /* date and time of last backup */
291 FndrDirInfo userInfo; /* Finder information */
292 FndrOpaqueInfo finderInfo; /* additional Finder information */
293 u_int32_t reserved[4]; /* reserved - initialized as zero */
294};
295typedef struct HFSCatalogFolder HFSCatalogFolder;
296
297/* HFS Plus catalog folder record - 88 bytes */
298struct HFSPlusCatalogFolder {
299 int16_t recordType; /* == kHFSPlusFolderRecord */
300 u_int16_t flags; /* file flags */
301 u_int32_t valence; /* folder's valence (limited to 2^16 in Mac OS) */
302 u_int32_t folderID; /* folder ID */
303 u_int32_t createDate; /* date and time of creation */
304 u_int32_t contentModDate; /* date and time of last content modification */
305 u_int32_t attributeModDate; /* date and time of last attribute modification */
306 u_int32_t accessDate; /* date and time of last access (MacOS X only) */
307 u_int32_t backupDate; /* date and time of last backup */
308 HFSPlusBSDInfo bsdInfo; /* permissions (for MacOS X) */
309 FndrDirInfo userInfo; /* Finder information */
310 FndrOpaqueInfo finderInfo; /* additional Finder information */
311 u_int32_t textEncoding; /* hint for name conversions */
312 u_int32_t reserved; /* reserved - initialized as zero */
313};
314typedef struct HFSPlusCatalogFolder HFSPlusCatalogFolder;
315
316/* HFS catalog file record - 102 bytes */
317struct HFSCatalogFile {
318 int16_t recordType; /* == kHFSFileRecord */
319 u_int8_t flags; /* file flags */
320 int8_t fileType; /* file type (unused ?) */
321 FndrFileInfo userInfo; /* Finder information */
322 u_int32_t fileID; /* file ID */
323 u_int16_t dataStartBlock; /* not used - set to zero */
324 int32_t dataLogicalSize; /* logical EOF of data fork */
325 int32_t dataPhysicalSize; /* physical EOF of data fork */
326 u_int16_t rsrcStartBlock; /* not used - set to zero */
327 int32_t rsrcLogicalSize; /* logical EOF of resource fork */
328 int32_t rsrcPhysicalSize; /* physical EOF of resource fork */
329 u_int32_t createDate; /* date and time of creation */
330 u_int32_t modifyDate; /* date and time of last modification */
331 u_int32_t backupDate; /* date and time of last backup */
332 FndrOpaqueInfo finderInfo; /* additional Finder information */
333 u_int16_t clumpSize; /* file clump size (not used) */
334 HFSExtentRecord dataExtents; /* first data fork extent record */
335 HFSExtentRecord rsrcExtents; /* first resource fork extent record */
336 u_int32_t reserved; /* reserved - initialized as zero */
337};
338typedef struct HFSCatalogFile HFSCatalogFile;
339
340/* HFS Plus catalog file record - 248 bytes */
341struct HFSPlusCatalogFile {
342 int16_t recordType; /* == kHFSPlusFileRecord */
343 u_int16_t flags; /* file flags */
344 u_int32_t reserved1; /* reserved - initialized as zero */
345 u_int32_t fileID; /* file ID */
346 u_int32_t createDate; /* date and time of creation */
347 u_int32_t contentModDate; /* date and time of last content modification */
348 u_int32_t attributeModDate; /* date and time of last attribute modification */
349 u_int32_t accessDate; /* date and time of last access (MacOS X only) */
350 u_int32_t backupDate; /* date and time of last backup */
351 HFSPlusBSDInfo bsdInfo; /* permissions (for MacOS X) */
352 FndrFileInfo userInfo; /* Finder information */
353 FndrOpaqueInfo finderInfo; /* additional Finder information */
354 u_int32_t textEncoding; /* hint for name conversions */
355 u_int32_t reserved2; /* reserved - initialized as zero */
356
357 /* Note: these start on double long (64 bit) boundry */
358 HFSPlusForkData dataFork; /* size and block data for data fork */
359 HFSPlusForkData resourceFork; /* size and block data for resource fork */
360};
361typedef struct HFSPlusCatalogFile HFSPlusCatalogFile;
362
363/* HFS catalog thread record - 46 bytes */
364struct HFSCatalogThread {
365 int16_t recordType; /* == kHFSFolderThreadRecord or kHFSFileThreadRecord */
366 int32_t reserved[2]; /* reserved - initialized as zero */
367 u_int32_t parentID; /* parent ID for this catalog node */
368 u_char nodeName[kHFSMaxFileNameChars + 1]; /* name of this catalog node */
369};
370typedef struct HFSCatalogThread HFSCatalogThread;
371
372/* HFS Plus catalog thread record -- 264 bytes */
373struct HFSPlusCatalogThread {
374 int16_t recordType; /* == kHFSPlusFolderThreadRecord or kHFSPlusFileThreadRecord */
375 int16_t reserved; /* reserved - initialized as zero */
376 u_int32_t parentID; /* parent ID for this catalog node */
377 HFSUniStr255 nodeName; /* name of this catalog node (variable length) */
378};
379typedef struct HFSPlusCatalogThread HFSPlusCatalogThread;
380
9bccf70c 381#ifdef __APPLE_API_UNSTABLE
1c79356b
A
382/*
383 These are the types of records in the attribute B-tree. The values were
384 chosen so that they wouldn't conflict with the catalog record types.
385*/
386enum {
387 kHFSPlusAttrInlineData = 0x10, /* if size < kAttrOverflowSize */
388 kHFSPlusAttrForkData = 0x20, /* if size >= kAttrOverflowSize */
389 kHFSPlusAttrExtents = 0x30 /* overflow extents for large attributes */
390};
391
392
393/*
394 HFSPlusAttrInlineData
395 For small attributes, whose entire value is stored within this one
396 B-tree record.
397 There would not be any other records for this attribute.
398*/
399struct HFSPlusAttrInlineData {
400 u_int32_t recordType; /* == kHFSPlusAttrInlineData*/
401 u_int32_t reserved;
402 u_int32_t logicalSize; /* size in bytes of userData*/
403 u_int8_t userData[2]; /* variable length; space allocated is a multiple of 2 bytes*/
404};
405typedef struct HFSPlusAttrInlineData HFSPlusAttrInlineData;
406
407
408/*
409 HFSPlusAttrForkData
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.
413*/
414struct HFSPlusAttrForkData {
415 u_int32_t recordType; /* == kHFSPlusAttrForkData*/
416 u_int32_t reserved;
417 HFSPlusForkData theFork; /* size and first extents of value*/
418};
419typedef struct HFSPlusAttrForkData HFSPlusAttrForkData;
420
421/*
422 HFSPlusAttrExtents
423 This record contains information about overflow extents for large,
424 fragmented attributes.
425*/
426struct HFSPlusAttrExtents {
427 u_int32_t recordType; /* == kHFSPlusAttrExtents*/
428 u_int32_t reserved;
429 HFSPlusExtentRecord extents; /* additional extents*/
430};
431typedef struct HFSPlusAttrExtents HFSPlusAttrExtents;
432
433/* A generic Attribute Record*/
434union HFSPlusAttrRecord {
435 u_int32_t recordType;
436 HFSPlusAttrInlineData inlineData;
437 HFSPlusAttrForkData forkData;
438 HFSPlusAttrExtents overflowExtents;
439};
440typedef union HFSPlusAttrRecord HFSPlusAttrRecord;
441
442/* Key and node lengths */
443enum {
444 kHFSPlusExtentKeyMaximumLength = sizeof(HFSPlusExtentKey) - sizeof(u_int16_t),
445 kHFSExtentKeyMaximumLength = sizeof(HFSExtentKey) - sizeof(u_int8_t),
446 kHFSPlusCatalogKeyMaximumLength = sizeof(HFSPlusCatalogKey) - sizeof(u_int16_t),
447 kHFSPlusCatalogKeyMinimumLength = kHFSPlusCatalogKeyMaximumLength - sizeof(HFSUniStr255) + sizeof(u_int16_t),
448 kHFSCatalogKeyMaximumLength = sizeof(HFSCatalogKey) - sizeof(u_int8_t),
449 kHFSCatalogKeyMinimumLength = kHFSCatalogKeyMaximumLength - (kHFSMaxFileNameChars + 1) + sizeof(u_int8_t),
450 kHFSPlusCatalogMinNodeSize = 4096,
451 kHFSPlusExtentMinNodeSize = 512,
452 kHFSPlusAttrMinNodeSize = 4096
453};
9bccf70c 454#endif /* __APPLE_API_UNSTABLE */
1c79356b
A
455
456/* HFS and HFS Plus volume attribute bits */
457enum {
458 /* Bits 0-6 are reserved (always cleared by MountVol call) */
459 kHFSVolumeHardwareLockBit = 7, /* volume is locked by hardware */
460 kHFSVolumeUnmountedBit = 8, /* volume was successfully unmounted */
461 kHFSVolumeSparedBlocksBit = 9, /* volume has bad blocks spared */
462 kHFSVolumeNoCacheRequiredBit = 10, /* don't cache volume blocks (i.e. RAM or ROM disk) */
463 kHFSBootVolumeInconsistentBit = 11, /* boot volume is inconsistent (System 7.6 and later) */
464 kHFSCatalogNodeIDsReusedBit = 12,
b4c24cb9 465 kHFSVolumeJournaledBit = 13, /* this volume has a journal on it */
55e303ae 466 kHFSVolumeInconsistentBit = 14, /* serious inconsistencies detected at runtime */
1c79356b
A
467 kHFSVolumeSoftwareLockBit = 15, /* volume is locked by software */
468
469 kHFSVolumeHardwareLockMask = 1 << kHFSVolumeHardwareLockBit,
470 kHFSVolumeUnmountedMask = 1 << kHFSVolumeUnmountedBit,
471 kHFSVolumeSparedBlocksMask = 1 << kHFSVolumeSparedBlocksBit,
472 kHFSVolumeNoCacheRequiredMask = 1 << kHFSVolumeNoCacheRequiredBit,
473 kHFSBootVolumeInconsistentMask = 1 << kHFSBootVolumeInconsistentBit,
474 kHFSCatalogNodeIDsReusedMask = 1 << kHFSCatalogNodeIDsReusedBit,
b4c24cb9 475 kHFSVolumeJournaledMask = 1 << kHFSVolumeJournaledBit,
55e303ae 476 kHFSVolumeInconsistentMask = 1 << kHFSVolumeInconsistentBit,
1c79356b
A
477 kHFSVolumeSoftwareLockMask = 1 << kHFSVolumeSoftwareLockBit,
478 kHFSMDBAttributesMask = 0x8380
479};
480
481
482/* HFS Master Directory Block - 162 bytes */
483/* Stored at sector #2 (3rd sector) and second-to-last sector. */
484struct HFSMasterDirectoryBlock {
485 u_int16_t drSigWord; /* == kHFSSigWord */
486 u_int32_t drCrDate; /* date and time of volume creation */
487 u_int32_t drLsMod; /* date and time of last modification */
488 u_int16_t drAtrb; /* volume attributes */
489 u_int16_t drNmFls; /* number of files in root folder */
490 u_int16_t drVBMSt; /* first block of volume bitmap */
491 u_int16_t drAllocPtr; /* start of next allocation search */
492 u_int16_t drNmAlBlks; /* number of allocation blocks in volume */
493 u_int32_t drAlBlkSiz; /* size (in bytes) of allocation blocks */
494 u_int32_t drClpSiz; /* default clump size */
495 u_int16_t drAlBlSt; /* first allocation block in volume */
496 u_int32_t drNxtCNID; /* next unused catalog node ID */
497 u_int16_t drFreeBks; /* number of unused allocation blocks */
498 u_char drVN[kHFSMaxVolumeNameChars + 1]; /* volume name */
499 u_int32_t drVolBkUp; /* date and time of last backup */
500 u_int16_t drVSeqNum; /* volume backup sequence number */
501 u_int32_t drWrCnt; /* volume write count */
502 u_int32_t drXTClpSiz; /* clump size for extents overflow file */
503 u_int32_t drCTClpSiz; /* clump size for catalog file */
504 u_int16_t drNmRtDirs; /* number of directories in root folder */
505 u_int32_t drFilCnt; /* number of files in volume */
506 u_int32_t drDirCnt; /* number of directories in volume */
507 u_int32_t drFndrInfo[8]; /* information used by the Finder */
508 u_int16_t drEmbedSigWord; /* embedded volume signature (formerly drVCSize) */
509 HFSExtentDescriptor drEmbedExtent; /* embedded volume location and size (formerly drVBMCSize and drCtlCSize) */
510 u_int32_t drXTFlSize; /* size of extents overflow file */
511 HFSExtentRecord drXTExtRec; /* extent record for extents overflow file */
512 u_int32_t drCTFlSize; /* size of catalog file */
513 HFSExtentRecord drCTExtRec; /* extent record for catalog file */
514};
515typedef struct HFSMasterDirectoryBlock HFSMasterDirectoryBlock;
516
517
55e303ae
A
518#ifdef __APPLE_API_UNSTABLE
519#define SET_HFS_TEXT_ENCODING(hint) \
520 (0x656e6300 | ((hint) & 0xff))
521#define GET_HFS_TEXT_ENCODING(hint) \
522 (((hint) & 0xffffff00) == 0x656e6300 ? (hint) & 0x000000ff : 0xffffffffU)
523#endif /* __APPLE_API_UNSTABLE */
524
525
1c79356b
A
526/* HFS Plus Volume Header - 512 bytes */
527/* Stored at sector #2 (3rd sector) and second-to-last sector. */
528struct HFSPlusVolumeHeader {
529 u_int16_t signature; /* == kHFSPlusSigWord */
530 u_int16_t version; /* == kHFSPlusVersion */
531 u_int32_t attributes; /* volume attributes */
532 u_int32_t lastMountedVersion; /* implementation version which last mounted volume */
b4c24cb9 533 u_int32_t journalInfoBlock; /* block addr of journal info (if volume is journaled, zero otherwise) */
1c79356b
A
534
535 u_int32_t createDate; /* date and time of volume creation */
536 u_int32_t modifyDate; /* date and time of last modification */
537 u_int32_t backupDate; /* date and time of last backup */
538 u_int32_t checkedDate; /* date and time of last disk check */
539
540 u_int32_t fileCount; /* number of files in volume */
541 u_int32_t folderCount; /* number of directories in volume */
542
543 u_int32_t blockSize; /* size (in bytes) of allocation blocks */
544 u_int32_t totalBlocks; /* number of allocation blocks in volume (includes this header and VBM*/
545 u_int32_t freeBlocks; /* number of unused allocation blocks */
546
547 u_int32_t nextAllocation; /* start of next allocation search */
548 u_int32_t rsrcClumpSize; /* default resource fork clump size */
549 u_int32_t dataClumpSize; /* default data fork clump size */
550 u_int32_t nextCatalogID; /* next unused catalog node ID */
551
552 u_int32_t writeCount; /* volume write count */
553 u_int64_t encodingsBitmap; /* which encodings have been use on this volume */
554
555 u_int8_t finderInfo[32]; /* information used by the Finder */
556
557 HFSPlusForkData allocationFile; /* allocation bitmap file */
558 HFSPlusForkData extentsFile; /* extents B-tree file */
559 HFSPlusForkData catalogFile; /* catalog B-tree file */
560 HFSPlusForkData attributesFile; /* extended attributes B-tree file */
561 HFSPlusForkData startupFile; /* boot file (secondary loader) */
562};
563typedef struct HFSPlusVolumeHeader HFSPlusVolumeHeader;
564
565
566/* B-tree structures */
567
568enum BTreeKeyLimits{
569 kMaxKeyLength = 520
570};
571
572union BTreeKey{
573 u_int8_t length8;
574 u_int16_t length16;
575 u_int8_t rawData [kMaxKeyLength+2];
576};
577typedef union BTreeKey BTreeKey;
578
579/* BTNodeDescriptor -- Every B-tree node starts with these fields. */
580struct BTNodeDescriptor {
581 u_int32_t fLink; /* next node at this level*/
582 u_int32_t bLink; /* previous node at this level*/
583 int8_t kind; /* kind of node (leaf, index, header, map)*/
584 u_int8_t height; /* zero for header, map; child is one more than parent*/
585 u_int16_t numRecords; /* number of records in this node*/
586 u_int16_t reserved; /* reserved - initialized as zero */
587};
588typedef struct BTNodeDescriptor BTNodeDescriptor;
589
590/* Constants for BTNodeDescriptor kind */
591enum {
592 kBTLeafNode = -1,
593 kBTIndexNode = 0,
594 kBTHeaderNode = 1,
595 kBTMapNode = 2
596};
597
598/* BTHeaderRec -- The first record of a B-tree header node */
599struct BTHeaderRec {
600 u_int16_t treeDepth; /* maximum height (usually leaf nodes) */
601 u_int32_t rootNode; /* node number of root node */
602 u_int32_t leafRecords; /* number of leaf records in all leaf nodes */
603 u_int32_t firstLeafNode; /* node number of first leaf node */
604 u_int32_t lastLeafNode; /* node number of last leaf node */
605 u_int16_t nodeSize; /* size of a node, in bytes */
606 u_int16_t maxKeyLength; /* reserved */
607 u_int32_t totalNodes; /* total number of nodes in tree */
608 u_int32_t freeNodes; /* number of unused (free) nodes in tree */
609 u_int16_t reserved1; /* unused */
610 u_int32_t clumpSize; /* reserved */
611 u_int8_t btreeType; /* reserved */
55e303ae 612 u_int8_t keyCompareType; /* Key string Comparison Type */
1c79356b
A
613 u_int32_t attributes; /* persistent attributes about the tree */
614 u_int32_t reserved3[16]; /* reserved */
615};
616typedef struct BTHeaderRec BTHeaderRec;
617
618/* Constants for BTHeaderRec attributes */
619enum {
620 kBTBadCloseMask = 0x00000001, /* reserved */
621 kBTBigKeysMask = 0x00000002, /* key length field is 16 bits */
622 kBTVariableIndexKeysMask = 0x00000004 /* keys in index nodes are variable length */
623};
624
55e303ae
A
625
626/* Catalog Key Name Comparison Type */
627enum {
628 kHFSCaseFolding = 0xCF, /* case folding (case-insensitive) */
629 kHFSBinaryCompare = 0xBC, /* binary compare (case-sensitive) */
630};
631
b4c24cb9
A
632/* JournalInfoBlock - Structure that describes where our journal lives */
633struct JournalInfoBlock {
634 u_int32_t flags;
635 u_int32_t device_signature[8]; // signature used to locate our device.
636 u_int64_t offset; // byte offset to the journal on the device
637 u_int64_t size; // size in bytes of the journal
638 u_int32_t reserved[32];
639};
640typedef struct JournalInfoBlock JournalInfoBlock;
641
642enum {
643 kJIJournalInFSMask = 0x00000001,
644 kJIJournalOnOtherDeviceMask = 0x00000002,
645 kJIJournalNeedInitMask = 0x00000004
646};
647
648
1c79356b
A
649#pragma options align=reset
650
651#ifdef __cplusplus
652}
653#endif
654
55e303ae
A
655#else
656#warning hfs_format.h is not compatible with HFSVolumes.h (include only one)
657#endif /* __HFSVOLUMES__ */
658
1c79356b 659#endif /* __HFS_FORMAT__ */