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