]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfs_format.h
xnu-792.24.17.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_format.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 #ifndef __HFS_FORMAT__
23 #define __HFS_FORMAT__
24
25 #include <sys/types.h>
26 #include <sys/appleapiopts.h>
27
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
39 extern "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 */
46 enum {
47 kHFSSigWord = 0x4244, /* 'BD' in ASCII */
48 kHFSPlusSigWord = 0x482B, /* 'H+' in ASCII */
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
54 kHFSPlusMountVersion = 0x31302E30, /* '10.0' for Mac OS X */
55 kHFSJMountVersion = 0x4846534a, /* 'HFSJ' for journaled HFS+ on OS X */
56 kFSKMountVersion = 0x46534b21 /* 'FSK!' for failed journal replay */
57 };
58
59
60 #ifdef __APPLE_API_PRIVATE
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
82 #endif /* __APPLE_API_PRIVATE */
83
84 /*
85 * Indirect link files (hard links) have the following type/creator.
86 */
87 enum {
88 kHardLinkFileType = 0x686C6E6B, /* 'hlnk' */
89 kHFSPlusCreator = 0x6866732B /* 'hfs+' */
90 };
91
92
93 #ifndef _HFSUNISTR255_DEFINED_
94 #define _HFSUNISTR255_DEFINED_
95 /* Unicode strings are used for HFS Plus file and folder names */
96 struct HFSUniStr255 {
97 u_int16_t length; /* number of unicode characters */
98 u_int16_t unicode[255]; /* unicode characters */
99 };
100 typedef struct HFSUniStr255 HFSUniStr255;
101 typedef const HFSUniStr255 *ConstHFSUniStr255Param;
102 #endif /* _HFSUNISTR255_DEFINED_ */
103
104 enum {
105 kHFSMaxVolumeNameChars = 27,
106 kHFSMaxFileNameChars = 31,
107 kHFSPlusMaxFileNameChars = 255
108 };
109
110
111 /* Extent overflow file data structures */
112
113 /* HFS Extent key */
114 struct 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 };
120 typedef struct HFSExtentKey HFSExtentKey;
121
122 /* HFS Plus Extent key */
123 struct 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 };
130 typedef struct HFSPlusExtentKey HFSPlusExtentKey;
131
132 /* Number of extent descriptors per extent record */
133 enum {
134 kHFSExtentDensity = 3,
135 kHFSPlusExtentDensity = 8
136 };
137
138 /* HFS extent descriptor */
139 struct HFSExtentDescriptor {
140 u_int16_t startBlock; /* first allocation block */
141 u_int16_t blockCount; /* number of allocation blocks */
142 };
143 typedef struct HFSExtentDescriptor HFSExtentDescriptor;
144
145 /* HFS Plus extent descriptor */
146 struct HFSPlusExtentDescriptor {
147 u_int32_t startBlock; /* first allocation block */
148 u_int32_t blockCount; /* number of allocation blocks */
149 };
150 typedef struct HFSPlusExtentDescriptor HFSPlusExtentDescriptor;
151
152 /* HFS extent record */
153 typedef HFSExtentDescriptor HFSExtentRecord[3];
154
155 /* HFS Plus extent record */
156 typedef HFSPlusExtentDescriptor HFSPlusExtentRecord[8];
157
158
159 /* Finder information */
160 struct 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 };
170 typedef struct FndrFileInfo FndrFileInfo;
171
172 struct 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 };
186 typedef struct FndrDirInfo FndrDirInfo;
187
188 struct FndrOpaqueInfo {
189 int8_t opaque[16];
190 };
191 typedef struct FndrOpaqueInfo FndrOpaqueInfo;
192
193
194 /* HFS Plus Fork data info - 80 bytes */
195 struct 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 };
201 typedef 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 */
209 struct 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 };
221 typedef struct HFSPlusBSDInfo HFSPlusBSDInfo;
222
223
224 /* Catalog file data structures */
225
226 enum {
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) */
235 kHFSRepairCatalogFileID = 14, /* Used when rebuilding Catalog B-tree */
236 kHFSBogusExtentFileID = 15, /* Used for exchanging extents in extents file */
237 kHFSFirstUserCatalogNodeID = 16
238 };
239
240 /* HFS catalog key */
241 struct 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_int8_t nodeName[kHFSMaxFileNameChars + 1]; /* catalog node name */
246 };
247 typedef struct HFSCatalogKey HFSCatalogKey;
248
249 /* HFS Plus catalog key */
250 struct 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 };
255 typedef struct HFSPlusCatalogKey HFSPlusCatalogKey;
256
257 /* Catalog record types */
258 enum {
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 */
274 enum {
275 kHFSFileLockedBit = 0x0000, /* file is locked and cannot be written to */
276 kHFSFileLockedMask = 0x0001,
277
278 kHFSThreadExistsBit = 0x0001, /* a file thread record exists for this file */
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
286 };
287
288
289 /* HFS catalog folder record - 70 bytes */
290 struct 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 };
302 typedef struct HFSCatalogFolder HFSCatalogFolder;
303
304 /* HFS Plus catalog folder record - 88 bytes */
305 struct 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 */
319 u_int32_t attrBlocks; /* cached count of attribute data blocks */
320 };
321 typedef struct HFSPlusCatalogFolder HFSPlusCatalogFolder;
322
323 /* HFS catalog file record - 102 bytes */
324 struct 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 };
345 typedef struct HFSCatalogFile HFSCatalogFile;
346
347 /* HFS Plus catalog file record - 248 bytes */
348 struct 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 */
362 u_int32_t attrBlocks; /* cached count of attribute data blocks */
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 };
368 typedef struct HFSPlusCatalogFile HFSPlusCatalogFile;
369
370 /* HFS catalog thread record - 46 bytes */
371 struct 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 */
375 u_int8_t nodeName[kHFSMaxFileNameChars + 1]; /* name of this catalog node */
376 };
377 typedef struct HFSCatalogThread HFSCatalogThread;
378
379 /* HFS Plus catalog thread record -- 264 bytes */
380 struct 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 };
386 typedef struct HFSPlusCatalogThread HFSPlusCatalogThread;
387
388 #ifdef __APPLE_API_UNSTABLE
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 */
393 enum {
394 kHFSPlusAttrInlineData = 0x10, /* if size < kAttrOverflowSize */
395 kHFSPlusAttrForkData = 0x20, /* if size >= kAttrOverflowSize */
396 kHFSPlusAttrExtents = 0x30 /* overflow extents for large attributes */
397 };
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 */
406 struct HFSPlusAttrForkData {
407 u_int32_t recordType; /* == kHFSPlusAttrForkData*/
408 u_int32_t reserved;
409 HFSPlusForkData theFork; /* size and first extents of value*/
410 };
411 typedef struct HFSPlusAttrForkData HFSPlusAttrForkData;
412
413 /*
414 HFSPlusAttrExtents
415 This record contains information about overflow extents for large,
416 fragmented attributes.
417 */
418 struct HFSPlusAttrExtents {
419 u_int32_t recordType; /* == kHFSPlusAttrExtents*/
420 u_int32_t reserved;
421 HFSPlusExtentRecord extents; /* additional extents*/
422 };
423 typedef struct HFSPlusAttrExtents HFSPlusAttrExtents;
424
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 */
431 struct 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 };
437 typedef struct HFSPlusAttrData HFSPlusAttrData;
438
439
440 /* HFSPlusAttrInlineData is obsolete use HFSPlusAttrData instead */
441 struct HFSPlusAttrInlineData {
442 u_int32_t recordType;
443 u_int32_t reserved;
444 u_int32_t logicalSize;
445 u_int8_t userData[2];
446 };
447 typedef struct HFSPlusAttrInlineData HFSPlusAttrInlineData;
448
449
450 /* A generic Attribute Record*/
451 union HFSPlusAttrRecord {
452 u_int32_t recordType;
453 HFSPlusAttrInlineData inlineData; /* NOT USED */
454 HFSPlusAttrData attrData;
455 HFSPlusAttrForkData forkData;
456 HFSPlusAttrExtents overflowExtents;
457 };
458 typedef union HFSPlusAttrRecord HFSPlusAttrRecord;
459
460 /* Attribute key */
461 enum { kHFSMaxAttrNameLen = 127 };
462 struct HFSPlusAttrKey {
463 u_int16_t keyLength; /* key length (in bytes) */
464 u_int16_t pad; /* set to zero */
465 u_int32_t fileID; /* file associated with attribute */
466 u_int32_t startBlock; /* first attribue allocation block number for extents */
467 u_int16_t attrNameLen; /* number of unicode characters */
468 u_int16_t attrName[kHFSMaxAttrNameLen]; /* attribute name (Unicode) */
469 };
470 typedef struct HFSPlusAttrKey HFSPlusAttrKey;
471
472 #define kHFSPlusAttrKeyMaximumLength (sizeof(HFSPlusAttrKey) - sizeof(u_int16_t))
473 #define kHFSPlusAttrKeyMinimumLength (kHFSPlusAttrKeyMaximumLength - kHFSMaxAttrNameLen*sizeof(u_int16_t))
474
475 #endif /* __APPLE_API_UNSTABLE */
476
477
478 /* Key and node lengths */
479 enum {
480 kHFSPlusExtentKeyMaximumLength = sizeof(HFSPlusExtentKey) - sizeof(u_int16_t),
481 kHFSExtentKeyMaximumLength = sizeof(HFSExtentKey) - sizeof(u_int8_t),
482 kHFSPlusCatalogKeyMaximumLength = sizeof(HFSPlusCatalogKey) - sizeof(u_int16_t),
483 kHFSPlusCatalogKeyMinimumLength = kHFSPlusCatalogKeyMaximumLength - sizeof(HFSUniStr255) + sizeof(u_int16_t),
484 kHFSCatalogKeyMaximumLength = sizeof(HFSCatalogKey) - sizeof(u_int8_t),
485 kHFSCatalogKeyMinimumLength = kHFSCatalogKeyMaximumLength - (kHFSMaxFileNameChars + 1) + sizeof(u_int8_t),
486 kHFSPlusCatalogMinNodeSize = 4096,
487 kHFSPlusExtentMinNodeSize = 512,
488 kHFSPlusAttrMinNodeSize = 4096
489 };
490
491 /* HFS and HFS Plus volume attribute bits */
492 enum {
493 /* Bits 0-6 are reserved (always cleared by MountVol call) */
494 kHFSVolumeHardwareLockBit = 7, /* volume is locked by hardware */
495 kHFSVolumeUnmountedBit = 8, /* volume was successfully unmounted */
496 kHFSVolumeSparedBlocksBit = 9, /* volume has bad blocks spared */
497 kHFSVolumeNoCacheRequiredBit = 10, /* don't cache volume blocks (i.e. RAM or ROM disk) */
498 kHFSBootVolumeInconsistentBit = 11, /* boot volume is inconsistent (System 7.6 and later) */
499 kHFSCatalogNodeIDsReusedBit = 12,
500 kHFSVolumeJournaledBit = 13, /* this volume has a journal on it */
501 kHFSVolumeInconsistentBit = 14, /* serious inconsistencies detected at runtime */
502 kHFSVolumeSoftwareLockBit = 15, /* volume is locked by software */
503
504 kHFSVolumeHardwareLockMask = 1 << kHFSVolumeHardwareLockBit,
505 kHFSVolumeUnmountedMask = 1 << kHFSVolumeUnmountedBit,
506 kHFSVolumeSparedBlocksMask = 1 << kHFSVolumeSparedBlocksBit,
507 kHFSVolumeNoCacheRequiredMask = 1 << kHFSVolumeNoCacheRequiredBit,
508 kHFSBootVolumeInconsistentMask = 1 << kHFSBootVolumeInconsistentBit,
509 kHFSCatalogNodeIDsReusedMask = 1 << kHFSCatalogNodeIDsReusedBit,
510 kHFSVolumeJournaledMask = 1 << kHFSVolumeJournaledBit,
511 kHFSVolumeInconsistentMask = 1 << kHFSVolumeInconsistentBit,
512 kHFSVolumeSoftwareLockMask = 1 << kHFSVolumeSoftwareLockBit,
513 kHFSMDBAttributesMask = 0x8380
514 };
515
516
517 /* HFS Master Directory Block - 162 bytes */
518 /* Stored at sector #2 (3rd sector) and second-to-last sector. */
519 struct HFSMasterDirectoryBlock {
520 u_int16_t drSigWord; /* == kHFSSigWord */
521 u_int32_t drCrDate; /* date and time of volume creation */
522 u_int32_t drLsMod; /* date and time of last modification */
523 u_int16_t drAtrb; /* volume attributes */
524 u_int16_t drNmFls; /* number of files in root folder */
525 u_int16_t drVBMSt; /* first block of volume bitmap */
526 u_int16_t drAllocPtr; /* start of next allocation search */
527 u_int16_t drNmAlBlks; /* number of allocation blocks in volume */
528 u_int32_t drAlBlkSiz; /* size (in bytes) of allocation blocks */
529 u_int32_t drClpSiz; /* default clump size */
530 u_int16_t drAlBlSt; /* first allocation block in volume */
531 u_int32_t drNxtCNID; /* next unused catalog node ID */
532 u_int16_t drFreeBks; /* number of unused allocation blocks */
533 u_int8_t drVN[kHFSMaxVolumeNameChars + 1]; /* volume name */
534 u_int32_t drVolBkUp; /* date and time of last backup */
535 u_int16_t drVSeqNum; /* volume backup sequence number */
536 u_int32_t drWrCnt; /* volume write count */
537 u_int32_t drXTClpSiz; /* clump size for extents overflow file */
538 u_int32_t drCTClpSiz; /* clump size for catalog file */
539 u_int16_t drNmRtDirs; /* number of directories in root folder */
540 u_int32_t drFilCnt; /* number of files in volume */
541 u_int32_t drDirCnt; /* number of directories in volume */
542 u_int32_t drFndrInfo[8]; /* information used by the Finder */
543 u_int16_t drEmbedSigWord; /* embedded volume signature (formerly drVCSize) */
544 HFSExtentDescriptor drEmbedExtent; /* embedded volume location and size (formerly drVBMCSize and drCtlCSize) */
545 u_int32_t drXTFlSize; /* size of extents overflow file */
546 HFSExtentRecord drXTExtRec; /* extent record for extents overflow file */
547 u_int32_t drCTFlSize; /* size of catalog file */
548 HFSExtentRecord drCTExtRec; /* extent record for catalog file */
549 };
550 typedef struct HFSMasterDirectoryBlock HFSMasterDirectoryBlock;
551
552
553 #ifdef __APPLE_API_UNSTABLE
554 #define SET_HFS_TEXT_ENCODING(hint) \
555 (0x656e6300 | ((hint) & 0xff))
556 #define GET_HFS_TEXT_ENCODING(hint) \
557 (((hint) & 0xffffff00) == 0x656e6300 ? (hint) & 0x000000ff : 0xffffffffU)
558 #endif /* __APPLE_API_UNSTABLE */
559
560
561 /* HFS Plus Volume Header - 512 bytes */
562 /* Stored at sector #2 (3rd sector) and second-to-last sector. */
563 struct HFSPlusVolumeHeader {
564 u_int16_t signature; /* == kHFSPlusSigWord */
565 u_int16_t version; /* == kHFSPlusVersion */
566 u_int32_t attributes; /* volume attributes */
567 u_int32_t lastMountedVersion; /* implementation version which last mounted volume */
568 u_int32_t journalInfoBlock; /* block addr of journal info (if volume is journaled, zero otherwise) */
569
570 u_int32_t createDate; /* date and time of volume creation */
571 u_int32_t modifyDate; /* date and time of last modification */
572 u_int32_t backupDate; /* date and time of last backup */
573 u_int32_t checkedDate; /* date and time of last disk check */
574
575 u_int32_t fileCount; /* number of files in volume */
576 u_int32_t folderCount; /* number of directories in volume */
577
578 u_int32_t blockSize; /* size (in bytes) of allocation blocks */
579 u_int32_t totalBlocks; /* number of allocation blocks in volume (includes this header and VBM*/
580 u_int32_t freeBlocks; /* number of unused allocation blocks */
581
582 u_int32_t nextAllocation; /* start of next allocation search */
583 u_int32_t rsrcClumpSize; /* default resource fork clump size */
584 u_int32_t dataClumpSize; /* default data fork clump size */
585 u_int32_t nextCatalogID; /* next unused catalog node ID */
586
587 u_int32_t writeCount; /* volume write count */
588 u_int64_t encodingsBitmap; /* which encodings have been use on this volume */
589
590 u_int8_t finderInfo[32]; /* information used by the Finder */
591
592 HFSPlusForkData allocationFile; /* allocation bitmap file */
593 HFSPlusForkData extentsFile; /* extents B-tree file */
594 HFSPlusForkData catalogFile; /* catalog B-tree file */
595 HFSPlusForkData attributesFile; /* extended attributes B-tree file */
596 HFSPlusForkData startupFile; /* boot file (secondary loader) */
597 };
598 typedef struct HFSPlusVolumeHeader HFSPlusVolumeHeader;
599
600
601 /* B-tree structures */
602
603 enum BTreeKeyLimits{
604 kMaxKeyLength = 520
605 };
606
607 union BTreeKey{
608 u_int8_t length8;
609 u_int16_t length16;
610 u_int8_t rawData [kMaxKeyLength+2];
611 };
612 typedef union BTreeKey BTreeKey;
613
614 /* BTNodeDescriptor -- Every B-tree node starts with these fields. */
615 struct BTNodeDescriptor {
616 u_int32_t fLink; /* next node at this level*/
617 u_int32_t bLink; /* previous node at this level*/
618 int8_t kind; /* kind of node (leaf, index, header, map)*/
619 u_int8_t height; /* zero for header, map; child is one more than parent*/
620 u_int16_t numRecords; /* number of records in this node*/
621 u_int16_t reserved; /* reserved - initialized as zero */
622 };
623 typedef struct BTNodeDescriptor BTNodeDescriptor;
624
625 /* Constants for BTNodeDescriptor kind */
626 enum {
627 kBTLeafNode = -1,
628 kBTIndexNode = 0,
629 kBTHeaderNode = 1,
630 kBTMapNode = 2
631 };
632
633 /* BTHeaderRec -- The first record of a B-tree header node */
634 struct BTHeaderRec {
635 u_int16_t treeDepth; /* maximum height (usually leaf nodes) */
636 u_int32_t rootNode; /* node number of root node */
637 u_int32_t leafRecords; /* number of leaf records in all leaf nodes */
638 u_int32_t firstLeafNode; /* node number of first leaf node */
639 u_int32_t lastLeafNode; /* node number of last leaf node */
640 u_int16_t nodeSize; /* size of a node, in bytes */
641 u_int16_t maxKeyLength; /* reserved */
642 u_int32_t totalNodes; /* total number of nodes in tree */
643 u_int32_t freeNodes; /* number of unused (free) nodes in tree */
644 u_int16_t reserved1; /* unused */
645 u_int32_t clumpSize; /* reserved */
646 u_int8_t btreeType; /* reserved */
647 u_int8_t keyCompareType; /* Key string Comparison Type */
648 u_int32_t attributes; /* persistent attributes about the tree */
649 u_int32_t reserved3[16]; /* reserved */
650 };
651 typedef struct BTHeaderRec BTHeaderRec;
652
653 /* Constants for BTHeaderRec attributes */
654 enum {
655 kBTBadCloseMask = 0x00000001, /* reserved */
656 kBTBigKeysMask = 0x00000002, /* key length field is 16 bits */
657 kBTVariableIndexKeysMask = 0x00000004 /* keys in index nodes are variable length */
658 };
659
660
661 /* Catalog Key Name Comparison Type */
662 enum {
663 kHFSCaseFolding = 0xCF, /* case folding (case-insensitive) */
664 kHFSBinaryCompare = 0xBC /* binary compare (case-sensitive) */
665 };
666
667 /* JournalInfoBlock - Structure that describes where our journal lives */
668 struct JournalInfoBlock {
669 u_int32_t flags;
670 u_int32_t device_signature[8]; // signature used to locate our device.
671 u_int64_t offset; // byte offset to the journal on the device
672 u_int64_t size; // size in bytes of the journal
673 u_int32_t reserved[32];
674 };
675 typedef struct JournalInfoBlock JournalInfoBlock;
676
677 enum {
678 kJIJournalInFSMask = 0x00000001,
679 kJIJournalOnOtherDeviceMask = 0x00000002,
680 kJIJournalNeedInitMask = 0x00000004
681 };
682
683
684 #pragma options align=reset
685
686 #ifdef __cplusplus
687 }
688 #endif
689
690 #endif /* __HFS_FORMAT__ */