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