-
Notifications
You must be signed in to change notification settings - Fork 1
/
hfsplus.hpp
397 lines (350 loc) · 10.6 KB
/
hfsplus.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#pragma once
#include <stdint.h>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include "fusion_map_serialization.hpp"
struct HFSUniStr255 {
uint16_t length;
uint16_t unicode[255];
};
typedef char tHFSUniStrData[255];
BOOST_FUSION_ADAPT_STRUCT(
HFSUniStr255,
(uint16_t,length)
(tHFSUniStrData,unicode))
BOOST_FUSION_ADD_SERIALIZER( HFSUniStr255 )
struct HFSPlusExtentDescriptor {
uint32_t startBlock;
uint32_t blockCount;
};
BOOST_FUSION_ADAPT_STRUCT(
HFSPlusExtentDescriptor,
(uint32_t,startBlock)
(uint32_t,blockCount))
BOOST_FUSION_ADD_SERIALIZER( HFSPlusExtentDescriptor )
typedef HFSPlusExtentDescriptor HFSPlusExtentRecord[8];
struct HFSPlusForkData {
uint64_t logicalSize;
uint32_t clumpSize;
uint32_t totalBlocks;
HFSPlusExtentRecord extents;
};
BOOST_FUSION_ADAPT_STRUCT(
HFSPlusForkData,
(uint64_t,logicalSize)
(uint32_t,clumpSize)
(uint32_t,totalBlocks)
(HFSPlusExtentRecord,extents))
BOOST_FUSION_ADD_SERIALIZER( HFSPlusForkData )
struct HFSPlusVolumeHeader {
char signature[2];
uint16_t version;
uint32_t attributes;
uint32_t lastMountedVersion;
uint32_t journalInfoBlock;
uint32_t createDate;
uint32_t modifyDate;
uint32_t backupDate;
uint32_t checkedDate;
uint32_t fileCount;
uint32_t folderCount;
uint32_t blockSize;
uint32_t totalBlocks;
uint32_t freeBlocks;
uint32_t nextAllocation;
uint32_t rsrcClumpSize;
uint32_t dataClumpSize;
uint32_t nextCatalogID;
uint32_t writeCount;
uint64_t encodingsBitmap;
uint32_t finderInfo[8];
HFSPlusForkData allocationFile;
HFSPlusForkData extentsFile;
HFSPlusForkData catalogFile;
HFSPlusForkData attributesFile;
HFSPlusForkData startupFile;
};
typedef char tHFSPlusSignature[2];
typedef uint32_t tHFSPlusFinderInfo[8];
BOOST_FUSION_ADAPT_STRUCT(
HFSPlusVolumeHeader,
(tHFSPlusSignature,signature)
(uint16_t,version)
(uint32_t,attributes)
(uint32_t,lastMountedVersion)
(uint32_t,journalInfoBlock)
(uint32_t,createDate)
(uint32_t,modifyDate)
(uint32_t,backupDate)
(uint32_t,checkedDate)
(uint32_t,fileCount)
(uint32_t,folderCount)
(uint32_t,blockSize)
(uint32_t,totalBlocks)
(uint32_t,freeBlocks)
(uint32_t,nextAllocation)
(uint32_t,rsrcClumpSize)
(uint32_t,dataClumpSize)
(uint32_t,nextCatalogID)
(uint32_t,writeCount)
(uint64_t,encodingsBitmap)
(tHFSPlusFinderInfo,finderInfo)
(HFSPlusForkData,allocationFile)
(HFSPlusForkData,extentsFile)
(HFSPlusForkData,catalogFile)
(HFSPlusForkData,attributesFile)
(HFSPlusForkData,startupFile))
BOOST_FUSION_ADD_SERIALIZER( HFSPlusVolumeHeader )
enum {
kBTInvalid = -2,
kBTLeafNode = -1,
kBTIndexNode = 0,
kBTHeaderNode = 1,
kBTMapNode = 2
};
#define BTNodeDescriptorSize 14
struct BTNodeDescriptor {
uint32_t fLink;
uint32_t bLink;
int8_t kind;
uint8_t height;
uint16_t numRecords;
uint16_t reserved;
};
BOOST_FUSION_ADAPT_STRUCT(
BTNodeDescriptor,
(uint32_t,fLink)
(uint32_t,bLink)
(int8_t, kind)
(uint8_t,height)
(uint16_t,numRecords)
(uint16_t,reserved))
BOOST_FUSION_ADD_SERIALIZER( BTNodeDescriptor )
enum {
kBTBadCloseMask = 0x00000001,
kBTBigKeysMask = 0x00000002,
kBTVariableIndexKeysMask = 0x00000004
};
enum {
kHFSRootParentID = 1,
kHFSRootFolderID = 2,
kHFSExtentsFileID = 3,
kHFSCatalogFileID = 4,
kHFSBadBlockFileID = 5,
kHFSAllocationFileID = 6,
kHFSStartupFileID = 7,
kHFSAttributesFileID = 8,
kHFSRepairCatalogFileID = 14,
kHFSBogusExtentFileID = 15,
kHFSFirstUserCatalogNodeID = 16
};
struct BTHeaderRec {
uint16_t treeDepth;
uint32_t rootNode;
uint32_t leafRecords;
uint32_t firstLeafNode;
uint32_t lastLeafNode;
uint16_t nodeSize;
uint16_t maxKeyLength;
uint32_t totalNodes;
uint32_t freeNodes;
uint16_t reserved1;
uint32_t clumpSize; // misaligned
uint8_t btreeType;
uint8_t keyCompareType;
uint32_t attributes; // long aligned again
uint32_t reserved3[16];
};
typedef uint32_t tBTHeaderRecReserved3[16];
BOOST_FUSION_ADAPT_STRUCT(
BTHeaderRec,
(uint16_t,treeDepth)
(uint32_t,rootNode)
(uint32_t,leafRecords)
(uint32_t,firstLeafNode)
(uint32_t,lastLeafNode)
(uint16_t,nodeSize)
(uint16_t,maxKeyLength)
(uint32_t,totalNodes)
(uint32_t,freeNodes)
(uint16_t,reserved1)
(uint32_t,clumpSize)
(uint8_t,btreeType)
(uint8_t,keyCompareType)
(uint32_t,attributes)
(tBTHeaderRecReserved3,reserved3))
BOOST_FUSION_ADD_SERIALIZER( BTHeaderRec )
struct HFSPlusBSDInfo {
uint32_t ownerID;
uint32_t groupID;
uint8_t adminFlags;
uint8_t ownerFlags;
uint16_t fileMode;
uint32_t iNodeNum; /* or link count, or raw device */
};
BOOST_FUSION_ADAPT_STRUCT(HFSPlusBSDInfo,
(uint32_t,ownerID)
(uint32_t,groupID)
(uint8_t,adminFlags)
(uint8_t,ownerFlags)
(uint16_t,fileMode)
(uint32_t,iNodeNum))
BOOST_FUSION_ADD_SERIALIZER(HFSPlusBSDInfo)
struct HFSPoint {
int16_t v;
int16_t h;
};
BOOST_FUSION_ADAPT_STRUCT(HFSPoint,
(int16_t,v)
(int16_t,h))
BOOST_FUSION_ADD_SERIALIZER(HFSPoint)
struct HFSRect {
int16_t top;
int16_t left;
int16_t bottom;
int16_t right;
};
BOOST_FUSION_ADAPT_STRUCT(HFSRect,
(int16_t,top)
(int16_t,left)
(int16_t,bottom)
(int16_t,right))
BOOST_FUSION_ADD_SERIALIZER(HFSRect)
typedef char OSType[4];
struct FileInfo {
OSType fileType; /* The type of the file */
OSType fileCreator; /* The file's creator */
uint16_t finderFlags;
HFSPoint location; /* File's location in the folder. */
uint16_t reservedField;
};
BOOST_FUSION_ADAPT_STRUCT(FileInfo,
(OSType,fileType)
(OSType,fileCreator)
(uint16_t,finderFlags)
(HFSPoint,location)
(uint16_t,reservedField))
BOOST_FUSION_ADD_SERIALIZER(FileInfo)
typedef int16_t tExtendedFileInfoReserved1[4];
struct ExtendedFileInfo {
tExtendedFileInfoReserved1 reserved1;
uint16_t extendedFinderFlags;
int16_t reserved2;
int32_t putAwayFolderID;
};
BOOST_FUSION_ADAPT_STRUCT(ExtendedFileInfo,
(tExtendedFileInfoReserved1,reserved1)
(uint16_t,extendedFinderFlags)
(int16_t,reserved2)
(int32_t,putAwayFolderID))
BOOST_FUSION_ADD_SERIALIZER(ExtendedFileInfo)
struct FolderInfo {
HFSRect windowBounds; /* The position and dimension of the */
/* folder's window */
uint16_t finderFlags;
HFSPoint location; /* Folder's location in the parent */
/* folder. If set to {0, 0}, the Finder */
/* will place the item automatically */
uint16_t reservedField;
};
BOOST_FUSION_ADAPT_STRUCT(FolderInfo,
(HFSRect,windowBounds)
(uint16_t,finderFlags)
(HFSPoint,location)
(uint16_t,reservedField))
BOOST_FUSION_ADD_SERIALIZER(FolderInfo)
struct ExtendedFolderInfo {
HFSPoint scrollPosition; /* Scroll position (for icon views) */
int32_t reserved1;
uint16_t extendedFinderFlags;
int16_t reserved2;
int32_t putAwayFolderID;
};
BOOST_FUSION_ADAPT_STRUCT(ExtendedFolderInfo,
(HFSPoint,scrollPosition)
(int32_t,reserved1)
(uint16_t,extendedFinderFlags)
(int16_t,reserved2)
(int32_t,putAwayFolderID))
BOOST_FUSION_ADD_SERIALIZER(ExtendedFolderInfo)
enum {
kHFSPlusFolderRecord = 0x0001,
kHFSPlusFileRecord = 0x0002,
kHFSPlusFolderThreadRecord = 0x0003,
kHFSPlusFileThreadRecord = 0x0004
};
struct HFSPlusCatalogFolder {
uint16_t flags;
uint32_t valence;
uint32_t folderID;
uint32_t createDate;
uint32_t contentModDate;
uint32_t attributeModDate;
uint32_t accessDate;
uint32_t backupDate;
HFSPlusBSDInfo permissions;
FolderInfo userInfo;
ExtendedFolderInfo finderInfo;
uint32_t textEncoding;
uint32_t reserved;
};
BOOST_FUSION_ADAPT_STRUCT(
HFSPlusCatalogFolder,
(uint16_t,flags)
(uint32_t,valence)
(uint32_t,folderID)
(uint32_t,createDate)
(uint32_t,contentModDate)
(uint32_t,attributeModDate)
(uint32_t,accessDate)
(uint32_t,backupDate)
(HFSPlusBSDInfo,permissions)
(FolderInfo,userInfo)
(ExtendedFolderInfo,finderInfo)
(uint32_t,textEncoding)
(uint32_t,reserved))
BOOST_FUSION_ADD_SERIALIZER( HFSPlusCatalogFolder )
struct HFSPlusCatalogFile {
uint16_t flags;
uint32_t reserved1;
uint32_t fileID;
uint32_t createDate;
uint32_t contentModDate;
uint32_t attributeModDate;
uint32_t accessDate;
uint32_t backupDate;
HFSPlusBSDInfo permissions;
FileInfo userInfo;
ExtendedFileInfo finderInfo;
uint32_t textEncoding;
uint32_t reserved2;
HFSPlusForkData dataFork;
HFSPlusForkData resourceFork;
};
BOOST_FUSION_ADAPT_STRUCT(
HFSPlusCatalogFile,
(uint16_t,flags)
(uint32_t,reserved1)
(uint32_t,fileID)
(uint32_t,createDate)
(uint32_t,contentModDate)
(uint32_t,attributeModDate)
(uint32_t,accessDate)
(uint32_t,backupDate)
(HFSPlusBSDInfo,permissions)
(FileInfo,userInfo)
(ExtendedFileInfo,finderInfo)
(uint32_t,textEncoding)
(uint32_t,reserved2)
(HFSPlusForkData,dataFork)
(HFSPlusForkData,resourceFork))
BOOST_FUSION_ADD_SERIALIZER( HFSPlusCatalogFile )
#define HFS_IFMT 0170000 /* type of file mask */
#define HFS_IFIFO 0010000 /* named pipe (fifo) */
#define HFS_IFCHR 0020000 /* character special */
#define HFS_IFDIR 0040000 /* directory */
#define HFS_IFBLK 0060000 /* block special */
#define HFS_IFREG 0100000 /* regular */
#define HFS_IFLNK 0120000 /* symbolic link */
#define HFS_IFSOCK 0140000 /* socket */
#define HFS_IFWHT 0160000 /* whiteout */