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