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