2 * libhfsp - library for reading and writing Macintosh HFS+ volumes
4 * This file includes definitions for the structures found on
5 * HFS+ Volumes. The structures are further wrapped by struct
6 * found in libhfsp.h. fucntions on those enhanced structures
7 * are found in files mentioned in comments below.
9 * Copyright (C) 2000 Klaus Halfmann <khalfmann@libra.de>
10 * Original code 1996-1998 by Robert Leslie <rob@mars.rog>
11 * other work 2000 from Brad Boyer (flar@pants.nu)
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
28 * $Id: hfsp.h,v 1.17 2000/10/20 06:16:52 hasi Exp $
31 #define HFSP_BLOCKSZ 512 /* A sector for Apple is always 512 bytes */
32 #define HFSP_BLOCKSZ_BITS 9 /* 1<<9 == 512 */
33 #define HFSP_VOLHEAD_SIG 0x482B /* 'H+' */
35 /* HFS+ includes POSIX permissions , although marked as reserved they will be
36 * used as such. Is ignored by MacOS 8-9 but probably not by MacOS X.
45 /* A single contiguous area (fragment) of a file */
51 /* A file may contain up to 8 normale extents, all other
52 are found in some extra extent area */
53 typedef hfsp_extent hfsp_extent_rec[8];
55 /* Information for a "Fork" in a file
56 * Forks are the "usual" DATA and RSRC forks or special files
57 * (e.g. the Volume Bitmap)
60 UInt64 total_size; // logical size
61 UInt32 clump_size; // number of bytes to preallocate
63 hfsp_extent_rec extents; // initial (8) extents
67 * Always found at block 2 of the disk, a copy is stored
68 * at the second to last block of the disk.
70 typedef struct hfsp_vh {
71 UInt16 signature; // must be HFSPLUS_VOLHEAD_SIG 'H+'
72 UInt16 version; // currently 4, ignored
73 UInt32 attributes; // See bit constants below
74 UInt32 last_mount_vers;
75 // Use a registered creator code here (what do we use ?)
76 // Mac OS uses '8.10' well
79 UInt32 create_date; // local time !
80 UInt32 modify_date; // GMT (?)
81 UInt32 backup_date; // GMT (?)
82 UInt32 checked_date; // GMT (?) fsck ?
85 // not including special files but including DATA and RSRC forks
86 UInt32 folder_count; // excluding the root folder
89 // must be multiple of HFSPLUS_SECTOR_SIZE,
90 // should be a multiple of 4k for harddisk
93 // The total number of unused allocation blocks on the disk.
96 // hint wher to search for next allocation blocks
98 // default clump size for rsrc forks
100 // default clump size for data forks
102 // next unused catalog id
104 // increment on every mount (and write ?)
105 UInt64 encodings_bmp;
106 // for every encoding used on the disk a bit is set
107 // ignored but eventually must be cared for
108 Char finder_info[32];
109 hfsp_fork_raw alloc_file;
110 // stores bitmap of use/free blocks
111 hfsp_fork_raw ext_file;
112 // stores oferflow extents
113 hfsp_fork_raw cat_file;
114 // This contains the root directory
115 hfsp_fork_raw attr_file;
116 hfsp_fork_raw start_file;
117 // a special startup file may be described here (used by ?)
120 /* HFS+ volume attributes */
121 /* 0-6 reserved, may be used in memory only */
122 #define HFSPLUS_VOL_RESERVED1 0x000000FF
123 #define HFSPLUS_VOL_HARDLOCK 0x00000080 // Used in Memory by finder only
124 #define HFSPLUS_VOL_UNMNT 0x00000100
125 // clear this bit when mounting, set as last step of unmounting
126 // This is checked by (slower) ROM code
127 #define HFSPLUS_VOL_SPARE_BLK 0x00000200
128 #define HFSPLUS_VOL_NOCACHE 0x00000400
129 // in case of RAM or ROM disk (try a HFS+ Ramdisk :)
130 #define HFSPLUS_VOL_INCNSTNT 0x00000800
131 // Reverse meaning as of HFSPLUS_VOL_UNMNT
132 // This is checked by (faster) Mac OS code
134 #define HFSPLUS_VOL_RESERVED2 0x00007000
135 #define HFSPLUS_VOL_SOFTLOCK 0x00008000
136 #define HFSPLUS_VOL_RESERVED3 0xFFFF0000
138 /* HFS+ Btree node descriptor */
140 UInt32 next; /* pointer to next node of this kind, or 0 */
141 UInt32 prev; /* pointer to previous node of this kind, or 0 */
142 UInt8 kind; /* see below */
143 UInt8 height; /* root node starts with 0 */
144 UInt16 num_rec; /* number of records in this node */
145 UInt16 reserved; /* fill up to 4 byte alignment */
148 /* HFS+ Btree Node types */
149 #define HFSP_NODE_NDX 0x00
150 #define HFSP_NODE_HEAD 0x01
151 #define HFSP_NODE_MAP 0x02
152 #define HFSP_NODE_LEAF 0xFF
154 #define HFSP_CATALOG_MIN_NODE_SIZE 0x1000
155 #define HFSP_ATTRMIN_DOE_SIZE 0x1000
157 /* The record offsets are found at the end of the fork
158 * containing the Btree */
160 typedef UInt16 btree_record_offset;
164 // equal to height of btree_node_desc
166 // root node of the hierarchy
171 // node size of _all_ nodes in this fork
174 // count of all (free and used) nodes in tree
178 // ignored my MacOS used by ?
184 UInt32 reserved3[16];
187 /* BTree attributes */
188 #define HFSPLUS_BAD_CLOSE 0x01
189 // Btree was not properly closed and should be checked
190 // not used for HFS+ but reserved
191 #define HFSPLUS_TREE_BIGKEYS 0x02
192 // always set for HFS+
193 #define HFSPLUS_TREE_VAR_NDXKEY_SIZE 0x04
194 // use variable length index nodes, always set for catalog btree,
195 // always cleared for extents btree.
197 #define HFSPLUS_TREE_UNUSED 0xFFFFFFF8
199 /* Some special File ID numbers */
200 #define HFSP_POR_CNID 1 /* Parent Of the Root */
201 #define HFSP_ROOT_CNID 2 /* ROOT directory */
202 #define HFSP_EXT_CNID 3 /* EXTents B-tree */
203 #define HFSP_CAT_CNID 4 /* CATalog B-tree */
204 #define HFSP_BAD_CNID 5 /* BAD blocks file */
205 #define HFSP_ALLOC_CNID 6 /* ALLOCation file */
206 #define HFSP_START_CNID 7 /* STARTup file */
207 #define HFSP_ATTR_CNID 8 /* ATTRibutes file */
208 #define HFSP_EXCH_CNID 15 /* ExchangeFiles temp id */
209 #define HFPS_MIN_CNID 15 /* Minimum expected value */
214 UInt16 name[255]; // unicode charcters
217 /* HFS+ catalog entry key */
219 UInt16 key_length; /* excluding length */
224 /* HFS+ exnteds entry key */
226 UInt16 key_length; /* excluding length */
227 UInt8 fork_type; /* Seee below */
233 #define HFSP_EXTENT_DATA 0x00
234 #define HFSP_EXTENT_RSRC 0xFF
236 /* The key is followed by a record, an index or some other data */
238 /* The types of these records are defined as follows */
240 #define HFSP_FOLDER 0x0001 // entry fo a Folder
241 #define HFSP_FILE 0x0002 // entry for a File
242 #define HFSP_FOLDER_THREAD 0x0003
243 // Like '.' in unix, identifies the folder by its id, only
244 #define HFSP_FILE_THREAD 0x0004
245 // Im unsure if this is used by HFS+, too
247 /* HFS+ folder data (part of an hfsp_cat_entry) */
249 UInt16 flags; /* no flags defined yet */
250 UInt32 valence; /* Numer of files and folders contained in folder */
252 UInt32 create_date; // GMT
253 UInt32 content_mod_date; // GMT
254 UInt32 attribute_mod_date; // GMT
255 UInt32 access_date; // GMT
256 UInt32 backup_date; // GMT
257 hfsp_perm permissions;
260 UInt32 text_encoding;
261 // hint fo the finder what encoding to use, unused here
265 /* HFS+ file data (part of a cat_entry) */
267 UInt16 flags; /* See below */
271 UInt32 content_mod_date;
272 UInt32 attribute_mod_date;
275 hfsp_perm permissions;
278 UInt32 text_encoding;
281 hfsp_fork_raw data_fork;
282 hfsp_fork_raw res_fork;
285 /* File attribute bits */
286 #define HFSP_FILE_LOCKED 0x0001
287 #define HFSP_THREAD_EXISTS 0x0002 /* Always set in HFS+ */
289 /* HFS+ catalog thread (part of a cat_entry) */
293 hfsp_unistr255 nodeName;
297 /* A data record in the catalog tree */
301 hfsp_cat_folder folder;
303 hfsp_cat_thread thread;