1 |
/* |
2 |
* libhfs - library for reading and writing Macintosh HFS volumes |
3 |
* Copyright (C) 1996-1998 Robert Leslie |
4 |
* Modified for use with PearPC (c) 2004 Stefan Weyergraf |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
* |
20 |
*/ |
21 |
|
22 |
typedef signed char Char; |
23 |
typedef unsigned char UChar; |
24 |
typedef signed char SignedByte; |
25 |
typedef signed short APPLEInteger; |
26 |
typedef unsigned short UInteger; |
27 |
typedef signed long LongInt; |
28 |
typedef unsigned long ULongInt; |
29 |
typedef char Str15[16]; |
30 |
typedef char Str31[32]; |
31 |
typedef long OSType; |
32 |
|
33 |
typedef struct { |
34 |
APPLEInteger sbSig; /* device signature (should be 0x4552) */ |
35 |
APPLEInteger sbBlkSize; /* block size of the device (in bytes) */ |
36 |
LongInt sbBlkCount; /* number of blocks on the device */ |
37 |
APPLEInteger sbDevType; /* reserved */ |
38 |
APPLEInteger sbDevId; /* reserved */ |
39 |
LongInt sbData; /* reserved */ |
40 |
APPLEInteger sbDrvrCount; /* number of driver descriptor entries */ |
41 |
LongInt ddBlock; /* first driver's starting block */ |
42 |
APPLEInteger ddSize; /* size of the driver, in 512-byte blocks */ |
43 |
APPLEInteger ddType; /* driver operating system type (MacOS = 1) */ |
44 |
APPLEInteger ddPad[243]; /* additional drivers, if any */ |
45 |
} Block0; |
46 |
|
47 |
typedef struct { |
48 |
APPLEInteger pmSig; /* partition signature (0x504d or 0x5453) */ |
49 |
APPLEInteger pmSigPad; /* reserved */ |
50 |
LongInt pmMapBlkCnt; /* number of blocks in partition map */ |
51 |
LongInt pmPyPartStart; /* first physical block of partition */ |
52 |
LongInt pmPartBlkCnt; /* number of blocks in partition */ |
53 |
Char pmPartName[33]; /* partition name */ |
54 |
Char pmParType[33]; /* partition type */ |
55 |
LongInt pmLgDataStart; /* first logical block of data area */ |
56 |
LongInt pmDataCnt; /* number of blocks in data area */ |
57 |
LongInt pmPartStatus; /* partition status information */ |
58 |
LongInt pmLgBootStart; /* first logical block of boot code */ |
59 |
LongInt pmBootSize; /* size of boot code, in bytes */ |
60 |
LongInt pmBootAddr; /* boot code load address */ |
61 |
LongInt pmBootAddr2; /* reserved */ |
62 |
LongInt pmBootEntry; /* boot code entry point */ |
63 |
LongInt pmBootEntry2; /* reserved */ |
64 |
LongInt pmBootCksum; /* boot code checksum */ |
65 |
Char pmProcessor[17];/* processor type */ |
66 |
APPLEInteger pmPad[188]; /* reserved */ |
67 |
} ApplePartition; |
68 |
|
69 |
typedef struct { |
70 |
APPLEInteger bbID; /* boot blocks signature */ |
71 |
LongInt bbEntry; /* entry point to boot code */ |
72 |
APPLEInteger bbVersion; /* boot blocks version number */ |
73 |
APPLEInteger bbPageFlags; /* used internally */ |
74 |
Str15 bbSysName; /* System filename */ |
75 |
Str15 bbShellName; /* Finder filename */ |
76 |
Str15 bbDbg1Name; /* debugger filename */ |
77 |
Str15 bbDbg2Name; /* debugger filename */ |
78 |
Str15 bbScreenName; /* name of startup screen */ |
79 |
Str15 bbHelloName; /* name of startup program */ |
80 |
Str15 bbScrapName; /* name of system scrap file */ |
81 |
APPLEInteger bbCntFCBs; /* number of FCBs to allocate */ |
82 |
APPLEInteger bbCntEvts; /* number of event queue elements */ |
83 |
LongInt bb128KSHeap; /* system heap size on 128K Mac */ |
84 |
LongInt bb256KSHeap; /* used internally */ |
85 |
LongInt bbSysHeapSize; /* system heap size on all machines */ |
86 |
APPLEInteger filler; /* reserved */ |
87 |
LongInt bbSysHeapExtra; /* additional system heap space */ |
88 |
LongInt bbSysHeapFract; /* fraction of RAM for system heap */ |
89 |
} BootBlkHdr; |
90 |
|
91 |
typedef struct { |
92 |
UInteger xdrStABN; /* first allocation block */ |
93 |
UInteger xdrNumABlks; /* number of allocation blocks */ |
94 |
} ExtDescriptor; |
95 |
|
96 |
typedef ExtDescriptor ExtDataRec[3]; |
97 |
|
98 |
typedef struct { |
99 |
SignedByte xkrKeyLen; /* key length */ |
100 |
SignedByte xkrFkType; /* fork type (0x00/0xff == data/resource */ |
101 |
ULongInt xkrFNum; /* file number */ |
102 |
UInteger xkrFABN; /* starting file allocation block */ |
103 |
} ExtKeyRec; |
104 |
|
105 |
typedef struct { |
106 |
SignedByte ckrKeyLen; /* key length */ |
107 |
SignedByte ckrResrv1; /* reserved */ |
108 |
ULongInt ckrParID; /* parent directory ID */ |
109 |
Str31 ckrCName; /* catalog node name */ |
110 |
} CatKeyRec; |
111 |
|
112 |
typedef struct { |
113 |
APPLEInteger v; /* vertical coordinate */ |
114 |
APPLEInteger h; /* horizontal coordinate */ |
115 |
} Point; |
116 |
|
117 |
typedef struct { |
118 |
APPLEInteger top; /* top edge of rectangle */ |
119 |
APPLEInteger left; /* left edge */ |
120 |
APPLEInteger bottom; /* bottom edge */ |
121 |
APPLEInteger right; /* right edge */ |
122 |
} Rect; |
123 |
|
124 |
typedef struct { |
125 |
Rect frRect; /* folder's rectangle */ |
126 |
APPLEInteger frFlags; /* flags */ |
127 |
Point frLocation; /* folder's location */ |
128 |
APPLEInteger frView; /* folder's view */ |
129 |
} DInfo; |
130 |
|
131 |
typedef struct { |
132 |
Point frScroll; /* scroll position */ |
133 |
LongInt frOpenChain; /* directory ID chain of open folders */ |
134 |
APPLEInteger frUnused; /* reserved */ |
135 |
APPLEInteger frComment; /* comment ID */ |
136 |
LongInt frPutAway; /* directory ID */ |
137 |
} DXInfo; |
138 |
|
139 |
typedef struct { |
140 |
OSType fdType; /* file type */ |
141 |
OSType fdCreator; /* file's creator */ |
142 |
APPLEInteger fdFlags; /* flags */ |
143 |
Point fdLocation; /* file's location */ |
144 |
APPLEInteger fdFldr; /* file's window */ |
145 |
} FInfo; |
146 |
|
147 |
typedef struct { |
148 |
APPLEInteger fdIconID; /* icon ID */ |
149 |
APPLEInteger fdUnused[4]; /* reserved */ |
150 |
APPLEInteger fdComment; /* comment ID */ |
151 |
LongInt fdPutAway; /* home directory ID */ |
152 |
} FXInfo; |
153 |
|
154 |
typedef struct { |
155 |
APPLEInteger drSigWord; /* volume signature (0x4244 for HFS) */ |
156 |
LongInt drCrDate; /* date and time of volume creation */ |
157 |
LongInt drLsMod; /* date and time of last modification */ |
158 |
APPLEInteger drAtrb; /* volume attributes */ |
159 |
UInteger drNmFls; /* number of files in root directory */ |
160 |
UInteger drVBMSt; /* first block of volume bit map (always 3) */ |
161 |
UInteger drAllocPtr; /* start of next allocation search */ |
162 |
UInteger drNmAlBlks; /* number of allocation blocks in volume */ |
163 |
ULongInt drAlBlkSiz; /* size (in bytes) of allocation blocks */ |
164 |
ULongInt drClpSiz; /* default clump size */ |
165 |
UInteger drAlBlSt; /* first allocation block in volume */ |
166 |
LongInt drNxtCNID; /* next unused catalog node ID (dir/file ID) */ |
167 |
UInteger drFreeBks; /* number of unused allocation blocks */ |
168 |
char drVN[28]; /* volume name (1-27 chars) */ |
169 |
LongInt drVolBkUp; /* date and time of last backup */ |
170 |
APPLEInteger drVSeqNum; /* volume backup sequence number */ |
171 |
ULongInt drWrCnt; /* volume write count */ |
172 |
ULongInt drXTClpSiz; /* clump size for extents overflow file */ |
173 |
ULongInt drCTClpSiz; /* clump size for catalog file */ |
174 |
UInteger drNmRtDirs; /* number of directories in root directory */ |
175 |
ULongInt drFilCnt; /* number of files in volume */ |
176 |
ULongInt drDirCnt; /* number of directories in volume */ |
177 |
LongInt drFndrInfo[8]; /* information used by the Finder */ |
178 |
UInteger drEmbedSigWord; /* type of embedded volume */ |
179 |
ExtDescriptor drEmbedExtent; /* location of embedded volume */ |
180 |
ULongInt drXTFlSize; /* size (in bytes) of extents overflow file */ |
181 |
ExtDataRec drXTExtRec; /* first extent record for extents file */ |
182 |
ULongInt drCTFlSize; /* size (in bytes) of catalog file */ |
183 |
ExtDataRec drCTExtRec; /* first extent record for catalog file */ |
184 |
} MDB; |
185 |
|
186 |
typedef enum { |
187 |
cdrDirRec = 1, |
188 |
cdrFilRec = 2, |
189 |
cdrThdRec = 3, |
190 |
cdrFThdRec = 4 |
191 |
} CatDataType; |
192 |
|
193 |
typedef struct { |
194 |
SignedByte cdrType; /* record type */ |
195 |
SignedByte cdrResrv2; /* reserved */ |
196 |
union { |
197 |
struct { /* cdrDirRec */ |
198 |
APPLEInteger dirFlags; /* directory flags */ |
199 |
UInteger dirVal; /* directory valence */ |
200 |
ULongInt dirDirID; /* directory ID */ |
201 |
LongInt dirCrDat; /* date and time of creation */ |
202 |
LongInt dirMdDat; /* date and time of last modification */ |
203 |
LongInt dirBkDat; /* date and time of last backup */ |
204 |
DInfo dirUsrInfo; /* Finder information */ |
205 |
DXInfo dirFndrInfo; /* additional Finder information */ |
206 |
LongInt dirResrv[4]; /* reserved */ |
207 |
} dir; |
208 |
struct { /* cdrFilRec */ |
209 |
SignedByte |
210 |
filFlags; /* file flags */ |
211 |
SignedByte |
212 |
filTyp; /* file type */ |
213 |
FInfo filUsrWds; /* Finder information */ |
214 |
ULongInt filFlNum; /* file ID */ |
215 |
UInteger filStBlk; /* first alloc block of data fork */ |
216 |
ULongInt filLgLen; /* logical EOF of data fork */ |
217 |
ULongInt filPyLen; /* physical EOF of data fork */ |
218 |
UInteger filRStBlk; /* first alloc block of resource fork */ |
219 |
ULongInt filRLgLen; /* logical EOF of resource fork */ |
220 |
ULongInt filRPyLen; /* physical EOF of resource fork */ |
221 |
LongInt filCrDat; /* date and time of creation */ |
222 |
LongInt filMdDat; /* date and time of last modification */ |
223 |
LongInt filBkDat; /* date and time of last backup */ |
224 |
FXInfo filFndrInfo; /* additional Finder information */ |
225 |
UInteger filClpSize; /* file clump size */ |
226 |
ExtDataRec |
227 |
filExtRec; /* first data fork extent record */ |
228 |
ExtDataRec |
229 |
filRExtRec; /* first resource fork extent record */ |
230 |
LongInt filResrv; /* reserved */ |
231 |
} fil; |
232 |
struct { /* cdrThdRec */ |
233 |
LongInt thdResrv[2]; /* reserved */ |
234 |
ULongInt thdParID; /* parent ID for this directory */ |
235 |
Str31 thdCName; /* name of this directory */ |
236 |
} dthd; |
237 |
struct { /* cdrFThdRec */ |
238 |
LongInt fthdResrv[2]; /* reserved */ |
239 |
ULongInt fthdParID; /* parent ID for this file */ |
240 |
Str31 fthdCName; /* name of this file */ |
241 |
} fthd; |
242 |
} u; |
243 |
} CatDataRec; |
244 |
|
245 |
typedef struct { |
246 |
ULongInt ndFLink; /* forward link */ |
247 |
ULongInt ndBLink; /* backward link */ |
248 |
SignedByte ndType; /* node type */ |
249 |
SignedByte ndNHeight; /* node level */ |
250 |
UInteger ndNRecs; /* number of records in node */ |
251 |
APPLEInteger ndResv2; /* reserved */ |
252 |
} NodeDescriptor; |
253 |
|
254 |
enum { |
255 |
ndIndxNode = (SignedByte) 0x00, |
256 |
ndHdrNode = (SignedByte) 0x01, |
257 |
ndMapNode = (SignedByte) 0x02, |
258 |
ndLeafNode = (SignedByte) 0xff |
259 |
}; |
260 |
|
261 |
typedef struct { |
262 |
UInteger bthDepth; /* current depth of tree */ |
263 |
ULongInt bthRoot; /* number of root node */ |
264 |
ULongInt bthNRecs; /* number of leaf records in tree */ |
265 |
ULongInt bthFNode; /* number of first leaf node */ |
266 |
ULongInt bthLNode; /* number of last leaf node */ |
267 |
UInteger bthNodeSize; /* size of a node */ |
268 |
UInteger bthKeyLen; /* maximum length of a key */ |
269 |
ULongInt bthNNodes; /* total number of nodes in tree */ |
270 |
ULongInt bthFree; /* number of free nodes */ |
271 |
SignedByte bthResv[76]; /* reserved */ |
272 |
} BTHdrRec; |