~youscribe/parted/3.1

« back to all changes in this revision

Viewing changes to libparted/fs/r/hfs/hfs.h

  • Committer: Guilhem Lettron
  • Date: 2012-10-22 14:37:59 UTC
  • Revision ID: guilhem+ubuntu@lettron.fr-20121022143759-m403kecgz13sknvp
3.1 from tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    libparted - a library for manipulating disk partitions
 
3
    Copyright (C) 2003-2005, 2007, 2009-2012 Free Software Foundation, Inc.
 
4
 
 
5
    This program is free software; you can redistribute it and/or modify
 
6
    it under the terms of the GNU General Public License as published by
 
7
    the Free Software Foundation; either version 3 of the License, or
 
8
    (at your option) any later version.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
#ifndef _HFS_H
 
20
#define _HFS_H
 
21
 
 
22
/* WARNING : bn is used 2 times in theses macro */
 
23
/* so _never_ use side effect operators when using them */
 
24
#define TST_BLOC_OCCUPATION(tab,bn) \
 
25
        (((tab)[(bn)/8])  &  (1<<(7-((bn)&7))))
 
26
#define SET_BLOC_OCCUPATION(tab,bn) \
 
27
        (((tab)[(bn)/8]) |=  (1<<(7-((bn)&7))))
 
28
#define CLR_BLOC_OCCUPATION(tab,bn) \
 
29
        (((tab)[(bn)/8]) &= ~(1<<(7-((bn)&7))))
 
30
 
 
31
/* Maximum number of blocks for the copy buffers */
 
32
#define BLOCK_MAX_BUFF  256
 
33
/* Maximum size of the copy buffers, in bytes */
 
34
#define BYTES_MAX_BUFF  8388608
 
35
 
 
36
/* Apple Creator Codes follow */
 
37
#define HFSP_IMPL_Shnk  0x53686e6b      /* in use */
 
38
#define HFSP_IMPL_Xpnd  0x58706e64      /* reserved */
 
39
#define HFSP_IMPL_Resz  0x5265737a      /* reserved */
 
40
#define HFSP_IMPL_PHpx  0x50482b78      /* reserved */
 
41
#define HFSP_IMPL_traP  0x74726150      /* reserved */
 
42
#define HFSP_IMPL_GnuP  0x476e7550      /* reserved */
 
43
 
 
44
#define HFS_SIGNATURE   0x4244          /* 'BD' */
 
45
#define HFSP_SIGNATURE  0x482B          /* 'H+' */
 
46
#define HFSX_SIGNATURE  0x4858          /* 'HX' */
 
47
 
 
48
#define HFSP_VERSION     4
 
49
#define HFSX_VERSION     5
 
50
 
 
51
#define HFS_HARD_LOCK    7
 
52
#define HFS_UNMOUNTED    8
 
53
#define HFS_BAD_SPARED   9
 
54
#define HFS_SOFT_LOCK   15
 
55
#define HFSP_NO_CACHE   10
 
56
#define HFSP_INCONSISTENT 11
 
57
#define HFSP_REUSE_CNID 12
 
58
#define HFSP_JOURNALED  13
 
59
 
 
60
#define HFS_IDX_NODE    0x00
 
61
#define HFS_HDR_NODE    0x01
 
62
#define HFS_MAP_NODE    0x02
 
63
#define HFS_LEAF_NODE   0xFF
 
64
 
 
65
#define HFS_FIRST_REC   0x0E
 
66
#define HFS_NSD_HD_REC  0x78
 
67
#define HFS_MAP_REC     0xF8
 
68
 
 
69
#define HFS_DATA_FORK   0x00
 
70
#define HFS_RES_FORK    0xFF
 
71
 
 
72
#define HFS_CAT_DIR     0x01
 
73
#define HFS_CAT_FILE    0x02
 
74
#define HFS_CAT_DIR_TH  0x03
 
75
#define HFS_CAT_FILE_TH 0x04
 
76
 
 
77
#define HFSP_ATTR_INLINE        0x10
 
78
#define HFSP_ATTR_FORK          0x20
 
79
#define HFSP_ATTR_EXTENTS       0x30
 
80
 
 
81
#define HFS_ROOT_PAR_ID         0x01
 
82
#define HFS_ROOT_DIR_ID         0x02
 
83
#define HFS_XTENT_ID            0x03
 
84
#define HFS_CATALOG_ID          0x04
 
85
#define HFS_BAD_BLOCK_ID        0x05
 
86
#define HFSP_ALLOC_ID           0x06
 
87
#define HFSP_STARTUP_ID         0x07
 
88
#define HFSP_ATTRIB_ID          0x08
 
89
#define HFSP_BOGUS_ID           0x0F
 
90
#define HFSP_FIRST_AV_ID        0x10
 
91
 
 
92
#define HFSJ_JOURN_IN_FS        0x00
 
93
#define HFSJ_JOURN_OTHER_DEV    0x01
 
94
#define HFSJ_JOURN_NEED_INIT    0x02
 
95
 
 
96
#define HFSJ_HEADER_MAGIC       0x4a4e4c78
 
97
#define HFSJ_ENDIAN_MAGIC       0x12345678
 
98
 
 
99
#define HFSX_CASE_FOLDING       0xCF    /* case insensitive HFSX */
 
100
#define HFSX_BINARY_COMPARE     0xBC    /* case sensitive   HFSX */
 
101
 
 
102
#define HFS_EXT_NB      3
 
103
#define HFSP_EXT_NB     8
 
104
 
 
105
/* Define the filenames used by the FS extractor */
 
106
#ifdef HFS_EXTRACT_FS
 
107
 
 
108
#define HFS_MDB_FILENAME        "mdb.hfs"
 
109
#define HFS_CATALOG_FILENAME    "catalog.hfs"
 
110
#define HFS_EXTENTS_FILENAME    "extents.hfs"
 
111
#define HFS_BITMAP_FILENAME     "bitmap.hfs"
 
112
 
 
113
#define HFSP_VH_FILENAME        "vh.hfsplus"
 
114
#define HFSP_CATALOG_FILENAME   "catalog.hfsplus"
 
115
#define HFSP_EXTENTS_FILENAME   "extents.hfsplus"
 
116
#define HFSP_BITMAP_FILENAME    "bitmap.hfsplus"
 
117
#define HFSP_ATTRIB_FILENAME    "attributes.hfsplus"
 
118
#define HFSP_STARTUP_FILENAME   "startup.hfsplus"
 
119
 
 
120
#endif /* HFS_EXTRACT_FS */
 
121
 
 
122
 
 
123
 
 
124
/* ----------------------------------- */
 
125
/* --      HFS DATA STRUCTURES      -- */
 
126
/* ----------------------------------- */
 
127
 
 
128
/* Extent descriptor */
 
129
struct __attribute__ ((packed)) _HfsExtDescriptor {
 
130
        uint16_t        start_block;
 
131
        uint16_t        block_count;
 
132
};
 
133
typedef struct _HfsExtDescriptor HfsExtDescriptor;
 
134
typedef HfsExtDescriptor HfsExtDataRec[HFS_EXT_NB];
 
135
 
 
136
/* Volume header */
 
137
struct __attribute__ ((packed)) _HfsMasterDirectoryBlock {
 
138
        uint16_t         signature;
 
139
        uint32_t         create_date;
 
140
        uint32_t         modify_date;
 
141
        uint16_t         volume_attributes;
 
142
        uint16_t         files_in_root;
 
143
        uint16_t         volume_bitmap_block;       /* in sectors */
 
144
        uint16_t         next_allocation;
 
145
        uint16_t         total_blocks;
 
146
        uint32_t         block_size;                /* in bytes */
 
147
        uint32_t         def_clump_size;            /* in bytes */
 
148
        uint16_t         start_block;               /* in sectors */
 
149
        uint32_t         next_free_node;
 
150
        uint16_t         free_blocks;
 
151
        uint8_t          name_length;
 
152
        char             name[27];
 
153
        uint32_t         backup_date;
 
154
        uint16_t         backup_number;
 
155
        uint32_t         write_count;
 
156
        uint32_t         extents_clump;
 
157
        uint32_t         catalog_clump;
 
158
        uint16_t         dirs_in_root;
 
159
        uint32_t         file_count;
 
160
        uint32_t         dir_count;
 
161
        uint32_t         finder_info[8];
 
162
        union __attribute__ ((packed)) {
 
163
                struct __attribute__ ((packed)) {
 
164
                        uint16_t    volume_cache_size;    /* in blocks */
 
165
                        uint16_t    bitmap_cache_size;    /* in blocks */
 
166
                        uint16_t    common_cache_size;    /* in blocks */
 
167
                } legacy;
 
168
                struct __attribute__ ((packed)) {
 
169
                        uint16_t            signature;
 
170
                        HfsExtDescriptor    location;
 
171
                } embedded;
 
172
        } old_new;
 
173
        uint32_t         extents_file_size;  /* in bytes, block size multiple */
 
174
        HfsExtDataRec    extents_file_rec;
 
175
        uint32_t         catalog_file_size;  /* in bytes, block size multiple */
 
176
        HfsExtDataRec    catalog_file_rec;
 
177
};
 
178
typedef struct _HfsMasterDirectoryBlock HfsMasterDirectoryBlock;
 
179
 
 
180
/* B*-Tree Node Descriptor */
 
181
struct __attribute__ ((packed)) _HfsNodeDescriptor {
 
182
        uint32_t        next;
 
183
        uint32_t        previous;
 
184
        int8_t          type;
 
185
        uint8_t         height;
 
186
        uint16_t        rec_nb;
 
187
        uint16_t        reserved;
 
188
};
 
189
typedef struct _HfsNodeDescriptor HfsNodeDescriptor;
 
190
 
 
191
/* Header record of a whole B*-Tree */
 
192
struct __attribute__ ((packed)) _HfsHeaderRecord {
 
193
        uint16_t        depth;
 
194
        uint32_t        root_node;
 
195
        uint32_t        leaf_records;
 
196
        uint32_t        first_leaf_node;
 
197
        uint32_t        last_leaf_node;
 
198
        uint16_t        node_size;
 
199
        uint16_t        max_key_len;
 
200
        uint32_t        total_nodes;
 
201
        uint32_t        free_nodes;
 
202
        int8_t          reserved[76];
 
203
};
 
204
typedef struct _HfsHeaderRecord HfsHeaderRecord;
 
205
 
 
206
/* Catalog key for B*-Tree lookup in the catalog file */
 
207
struct __attribute__ ((packed)) _HfsCatalogKey {
 
208
        uint8_t         key_length; /* length of the key without key_length */
 
209
        uint8_t         reserved;
 
210
        uint32_t        parent_ID;
 
211
        uint8_t         name_length;
 
212
        char            name[31];   /* in fact physicaly 1 upto 31 */
 
213
};
 
214
typedef struct _HfsCatalogKey HfsCatalogKey;
 
215
 
 
216
/* Extents overflow key for B*-Tree lookup */
 
217
struct __attribute__ ((packed)) _HfsExtentKey {
 
218
        uint8_t         key_length; /* length of the key without key_length */
 
219
        uint8_t         type;       /* data or ressource fork */
 
220
        uint32_t        file_ID;
 
221
        uint16_t        start;
 
222
};
 
223
typedef struct _HfsExtentKey HfsExtentKey;
 
224
 
 
225
/* Catalog subdata case directory */
 
226
struct __attribute__ ((packed)) _HfsDir {
 
227
        uint16_t        flags;
 
228
        uint16_t        valence;        /* number of files in this directory */
 
229
        uint32_t        dir_ID;
 
230
        uint32_t        create_date;
 
231
        uint32_t        modify_date;
 
232
        uint32_t        backup_date;
 
233
        int8_t          DInfo[16];      /* used by Finder, handle as reserved */
 
234
        int8_t          DXInfo[16];     /* used by Finder, handle as reserved */
 
235
        uint32_t        reserved[4];
 
236
};
 
237
typedef struct _HfsDir HfsDir;
 
238
 
 
239
/* Catalog subdata case file */
 
240
struct __attribute__ ((packed)) _HfsFile {
 
241
        int8_t          flags;
 
242
        int8_t          type;           /* should be 0 */
 
243
        int8_t          FInfo[16];      /* used by Finder, handle as reserved */
 
244
        uint32_t        file_ID;
 
245
        uint16_t        data_start_block;
 
246
        uint32_t        data_sz_byte;
 
247
        uint32_t        data_sz_block;
 
248
        uint16_t        res_start_block;
 
249
        uint32_t        res_sz_byte;
 
250
        uint32_t        res_sz_block;
 
251
        uint32_t        create_date;
 
252
        uint32_t        modify_date;
 
253
        uint32_t        backup_date;
 
254
        int8_t          FXInfo[16];     /* used by Finder, handle as reserved */
 
255
        uint16_t        clump_size;
 
256
        HfsExtDataRec   extents_data;
 
257
        HfsExtDataRec   extents_res;
 
258
        uint32_t        reserved;
 
259
};
 
260
typedef struct _HfsFile HfsFile;
 
261
 
 
262
/* Catalog subdata case directory thread */
 
263
struct __attribute__ ((packed)) _HfsDirTh {
 
264
        uint32_t        reserved[2];
 
265
        uint32_t        parent_ID;
 
266
        int8_t          name_length;
 
267
        char            name[31];
 
268
};
 
269
typedef struct _HfsDirTh HfsDirTh;
 
270
 
 
271
/* Catalog subdata case file thread */
 
272
typedef struct _HfsDirTh HfsFileTh;        /* same as directory thread */
 
273
 
 
274
/* Catalog data */
 
275
struct __attribute__ ((packed)) _HfsCatalog {
 
276
        int8_t          type;
 
277
        int8_t          reserved;
 
278
        union {
 
279
                HfsDir       dir;
 
280
                HfsFile      file;
 
281
                HfsDirTh     dir_th;
 
282
                HfsFileTh    file_th;
 
283
        } sel;
 
284
};
 
285
typedef struct _HfsCatalog HfsCatalog;
 
286
 
 
287
 
 
288
 
 
289
/* ------------------------------------ */
 
290
/* --      HFS+ DATA STRUCTURES      -- */
 
291
/* ------------------------------------ */
 
292
 
 
293
/* documented since 2004 in tn1150 */
 
294
struct __attribute__ ((packed)) _HfsPPerms {
 
295
        uint32_t        owner_ID;
 
296
        uint32_t        group_ID;
 
297
        uint32_t        permissions;
 
298
        uint32_t        special_devices;
 
299
};
 
300
typedef struct _HfsPPerms HfsPPerms;
 
301
 
 
302
/* HFS+ extent descriptor*/
 
303
struct __attribute__ ((packed)) _HfsPExtDescriptor {
 
304
        uint32_t        start_block;
 
305
        uint32_t        block_count;
 
306
};
 
307
typedef struct _HfsPExtDescriptor HfsPExtDescriptor;
 
308
typedef HfsPExtDescriptor HfsPExtDataRec[HFSP_EXT_NB];
 
309
 
 
310
/* HFS+ fork data structure */
 
311
struct __attribute__ ((packed)) _HfsPForkData {
 
312
        uint64_t        logical_size;
 
313
        uint32_t        clump_size;
 
314
        uint32_t        total_blocks;
 
315
        HfsPExtDataRec  extents;
 
316
};
 
317
typedef struct _HfsPForkData HfsPForkData;
 
318
 
 
319
/* HFS+ catalog node ID */
 
320
typedef uint32_t HfsPNodeID;
 
321
 
 
322
/* HFS+ file names */
 
323
typedef uint16_t unichar;
 
324
struct __attribute__ ((packed)) _HfsPUniStr255 {
 
325
        uint16_t        length;
 
326
        unichar         unicode[255];        /* 1 upto 255 */
 
327
};
 
328
typedef struct _HfsPUniStr255 HfsPUniStr255;
 
329
 
 
330
/* HFS+ volume header */
 
331
struct __attribute__ ((packed)) _HfsPVolumeHeader {
 
332
        uint16_t        signature;
 
333
        uint16_t        version;
 
334
        uint32_t        attributes;
 
335
        uint32_t        last_mounted_version;
 
336
        uint32_t        journal_info_block;
 
337
 
 
338
        uint32_t        create_date;
 
339
        uint32_t        modify_date;
 
340
        uint32_t        backup_date;
 
341
        uint32_t        checked_date;
 
342
 
 
343
        uint32_t        file_count;
 
344
        uint32_t        dir_count;
 
345
 
 
346
        uint32_t        block_size;
 
347
        uint32_t        total_blocks;
 
348
        uint32_t        free_blocks;
 
349
 
 
350
        uint32_t        next_allocation;
 
351
        uint32_t        res_clump_size;
 
352
        uint32_t        data_clump_size;
 
353
        HfsPNodeID      next_catalog_ID;
 
354
 
 
355
        uint32_t        write_count;
 
356
        uint64_t        encodings_bitmap;
 
357
 
 
358
        uint8_t         finder_info[32];
 
359
 
 
360
        HfsPForkData    allocation_file;
 
361
        HfsPForkData    extents_file;
 
362
        HfsPForkData    catalog_file;
 
363
        HfsPForkData    attributes_file;
 
364
        HfsPForkData    startup_file;
 
365
};
 
366
typedef struct _HfsPVolumeHeader HfsPVolumeHeader;
 
367
 
 
368
/* HFS+ B-Tree Node Descriptor. Same as HFS btree. */
 
369
struct __attribute__ ((packed)) _HfsPNodeDescriptor {
 
370
        uint32_t        next;
 
371
        uint32_t        previous;
 
372
        int8_t          type;
 
373
        uint8_t         height;
 
374
        uint16_t        rec_nb;
 
375
        uint16_t        reserved;
 
376
};
 
377
typedef struct _HfsPNodeDescriptor HfsPNodeDescriptor;
 
378
 
 
379
/* Header record of a whole HFS+ B-Tree. */
 
380
struct __attribute__ ((packed)) _HfsPHeaderRecord {
 
381
        uint16_t        depth;
 
382
        uint32_t        root_node;
 
383
        uint32_t        leaf_records;
 
384
        uint32_t        first_leaf_node;
 
385
        uint32_t        last_leaf_node;
 
386
        uint16_t        node_size;
 
387
        uint16_t        max_key_len;
 
388
        uint32_t        total_nodes;
 
389
        uint32_t        free_nodes;        /* same as hfs btree until here */
 
390
        uint16_t        reserved1;
 
391
 
 
392
        uint32_t        clump_size;
 
393
        uint8_t         btree_type;        /* must be 0 for HFS+ B-Tree */
 
394
        uint8_t         key_compare_type; /* hfsx => 0xCF = case folding */
 
395
                                          /*         0xBC = binary compare */
 
396
                                          /* otherwise, reserved */
 
397
        uint32_t        attributes;
 
398
        uint32_t        reserved3[16];
 
399
};
 
400
typedef struct _HfsPHeaderRecord HfsPHeaderRecord;
 
401
 
 
402
/* Catalog key for B-Tree lookup in the HFS+ catalog file */
 
403
struct __attribute__ ((packed)) _HfsPCatalogKey {
 
404
        uint16_t        key_length;
 
405
        HfsPNodeID      parent_ID;
 
406
        HfsPUniStr255   node_name;
 
407
};
 
408
typedef struct _HfsPCatalogKey HfsPCatalogKey;
 
409
 
 
410
/* HFS+ catalog subdata case dir */
 
411
struct __attribute__ ((packed)) _HfsPDir {
 
412
        uint16_t        flags;
 
413
        uint32_t        valence;
 
414
        HfsPNodeID      dir_ID;
 
415
        uint32_t        create_date;
 
416
        uint32_t        modify_date;
 
417
        uint32_t        attrib_mod_date;
 
418
        uint32_t        access_date;
 
419
        uint32_t        backup_date;
 
420
        HfsPPerms       permissions;
 
421
        int8_t          DInfo[16];        /* used by Finder, handle as reserved */
 
422
        int8_t          DXInfo[16];       /* used by Finder, handle as reserved */
 
423
        uint32_t        text_encoding;
 
424
        uint32_t        reserved;
 
425
};
 
426
typedef struct _HfsPDir HfsPDir;
 
427
 
 
428
/* HFS+ catalog subdata case file */
 
429
struct __attribute__ ((packed)) _HfsPFile {
 
430
        uint16_t        flags;
 
431
        uint32_t        reserved1;
 
432
        HfsPNodeID      file_ID;
 
433
        uint32_t        create_date;
 
434
        uint32_t        modify_date;
 
435
        uint32_t        attrib_mod_date;
 
436
        uint32_t        access_date;
 
437
        uint32_t        backup_date;
 
438
        HfsPPerms       permissions;
 
439
        int8_t          FInfo[16];        /* used by Finder, handle as reserved */
 
440
        int8_t          FXInfo[16];       /* used by Finder, handle as reserved */
 
441
        uint32_t        text_encoding;
 
442
        uint32_t        reserved2;
 
443
 
 
444
        HfsPForkData    data_fork;
 
445
        HfsPForkData    res_fork;
 
446
};
 
447
typedef struct _HfsPFile HfsPFile;
 
448
 
 
449
/* HFS+ catalog subdata case thread */
 
450
struct __attribute__ ((packed)) _HfsPThread {
 
451
        int16_t         reserved;
 
452
        HfsPNodeID      parent_ID;
 
453
        HfsPUniStr255   node_name;
 
454
};
 
455
typedef struct _HfsPThread HfsPDirTh;
 
456
typedef struct _HfsPThread HfsPFileTh;
 
457
 
 
458
/* HFS+ Catalog leaf data */
 
459
struct __attribute__ ((packed)) _HfsPCatalog {
 
460
        int16_t         type;
 
461
        union {
 
462
                HfsPDir         dir;
 
463
                HfsPFile        file;
 
464
                HfsPDirTh       dir_th;
 
465
                HfsPFileTh      file_th;
 
466
        } sel;
 
467
};
 
468
typedef struct _HfsPCatalog HfsPCatalog;
 
469
 
 
470
/* HFS+ extents file key */
 
471
struct __attribute__ ((packed)) _HfsPExtentKey {
 
472
        uint16_t        key_length;
 
473
        uint8_t         type;
 
474
        uint8_t         pad;
 
475
        HfsPNodeID      file_ID;
 
476
        uint32_t        start;
 
477
};
 
478
typedef struct _HfsPExtentKey HfsPExtentKey;
 
479
 
 
480
/* extent file data is HfsPExtDataRec */
 
481
 
 
482
/* Fork data attribute file */
 
483
struct __attribute__ ((packed)) _HfsPForkDataAttr {
 
484
        uint32_t        record_type;
 
485
        uint32_t        reserved;
 
486
        union __attribute__ ((packed)) {
 
487
                HfsPForkData        fork;
 
488
                HfsPExtDataRec      extents;
 
489
        } fork_res;
 
490
};
 
491
typedef struct _HfsPForkDataAttr HfsPForkDataAttr;
 
492
 
 
493
 
 
494
/* ----------- Journal data structures ----------- */
 
495
 
 
496
/* Info block : stored in a block # defined in the VH */
 
497
struct __attribute__ ((packed)) _HfsJJournalInfoBlock {
 
498
        uint32_t        flags;
 
499
        uint32_t        device_signature[8];
 
500
        uint64_t        offset;
 
501
        uint64_t        size;
 
502
        uint32_t        reserved[32];
 
503
};
 
504
typedef struct _HfsJJournalInfoBlock HfsJJournalInfoBlock;
 
505
 
 
506
struct __attribute__ ((packed)) _HfsJJournalHeader {
 
507
        uint32_t        magic;
 
508
        uint32_t        endian;
 
509
        uint64_t        start;
 
510
        uint64_t        end;
 
511
        uint64_t        size;
 
512
        uint32_t        blhdr_size;
 
513
        uint32_t        checksum;
 
514
        uint32_t        jhdr_size;
 
515
};
 
516
typedef struct _HfsJJournalHeader HfsJJournalHeader;
 
517
 
 
518
struct __attribute__ ((packed)) _HfsJBlockInfo {
 
519
        uint64_t        bnum;          /* sector number */
 
520
        uint32_t        bsize;         /* size in bytes */
 
521
        uint32_t        next;
 
522
};
 
523
typedef struct _HfsJBlockInfo HfsJBlockInfo;
 
524
 
 
525
struct __attribute__ ((packed)) _HfsJBlockListHeader {
 
526
        uint16_t        max_blocks;    /* reserved */
 
527
        uint16_t        num_blocks;
 
528
        uint32_t        bytes_used;
 
529
        uint32_t        checksum;
 
530
        uint32_t        pad;
 
531
        HfsJBlockInfo   binfo[1];
 
532
};
 
533
typedef struct _HfsJBlockListHeader HfsJBlockListHeader;
 
534
 
 
535
 
 
536
 
 
537
/* ---------------------------------------- */
 
538
/* --      INTERNAL DATA STRUCTURES      -- */
 
539
/* ---------------------------------------- */
 
540
 
 
541
/* Data of an opened HFS file */
 
542
struct _HfsPrivateFile {
 
543
        PedSector       sect_nb;
 
544
        PedFileSystem*  fs;
 
545
        uint32_t        CNID;          /* disk order (BE) */
 
546
        HfsExtDataRec   first;         /* disk order (BE) */
 
547
        HfsExtDataRec   cache;         /* disk order (BE) */
 
548
        uint16_t        start_cache;   /* CPU order */
 
549
};
 
550
typedef struct _HfsPrivateFile HfsPrivateFile;
 
551
 
 
552
/* To store bad block list */
 
553
struct _HfsPrivateLinkExtent {
 
554
        HfsExtDescriptor                 extent;
 
555
        struct _HfsPrivateLinkExtent*    next;
 
556
};
 
557
typedef struct _HfsPrivateLinkExtent HfsPrivateLinkExtent;
 
558
 
 
559
/* HFS Filesystem specific data */
 
560
struct _HfsPrivateFSData {
 
561
        uint8_t                     alloc_map[(1<<16) / 8];
 
562
        HfsMasterDirectoryBlock*    mdb;
 
563
        HfsPrivateFile*             extent_file;
 
564
        HfsPrivateFile*             catalog_file;
 
565
        HfsPrivateLinkExtent*       bad_blocks_xtent_list;
 
566
        unsigned int                bad_blocks_xtent_nb;
 
567
        char                        bad_blocks_loaded;
 
568
};
 
569
typedef struct _HfsPrivateFSData HfsPrivateFSData;
 
570
 
 
571
/* Generic btree key */
 
572
struct __attribute__ ((packed)) _HfsPrivateGenericKey {
 
573
        uint8_t         key_length;
 
574
        uint8_t         key_content[1];                /* we use 1 as a minimum size */
 
575
};
 
576
typedef struct _HfsPrivateGenericKey HfsPrivateGenericKey;
 
577
 
 
578
/* ----- HFS+ ----- */
 
579
 
 
580
/* Data of an opened HFS file */
 
581
struct _HfsPPrivateFile {
 
582
        PedSector       sect_nb;
 
583
        PedFileSystem*  fs;
 
584
        HfsPNodeID      CNID;          /* disk order (BE) */
 
585
        HfsPExtDataRec  first;         /* disk order (BE) */
 
586
        HfsPExtDataRec  cache;         /* disk order (BE) */
 
587
        uint32_t        start_cache;   /* CPU order */
 
588
};
 
589
typedef struct _HfsPPrivateFile HfsPPrivateFile;
 
590
 
 
591
struct _HfsPPrivateExtent {
 
592
        PedSector       start_sector;
 
593
        PedSector       sector_count;
 
594
};
 
595
typedef struct _HfsPPrivateExtent HfsPPrivateExtent;
 
596
 
 
597
/* To store bad block list */
 
598
struct _HfsPPrivateLinkExtent {
 
599
        HfsPExtDescriptor                 extent;
 
600
        struct _HfsPPrivateLinkExtent*    next;
 
601
};
 
602
typedef struct _HfsPPrivateLinkExtent HfsPPrivateLinkExtent;
 
603
 
 
604
/* HFS+ file system specific data */
 
605
struct _HfsPPrivateFSData {
 
606
        PedFileSystem*          wrapper;      /* NULL if hfs+ is not embedded */
 
607
        PedGeometry*            plus_geom;    /* Geometry of HFS+ _volume_ */
 
608
        uint8_t*                alloc_map;
 
609
        uint8_t*                dirty_alloc_map;
 
610
        HfsPVolumeHeader*       vh;
 
611
        HfsPPrivateFile*        extents_file;
 
612
        HfsPPrivateFile*        catalog_file;
 
613
        HfsPPrivateFile*        attributes_file;
 
614
        HfsPPrivateFile*        allocation_file;
 
615
        HfsPPrivateLinkExtent*  bad_blocks_xtent_list;
 
616
        uint32_t                jib_start_block;
 
617
        uint32_t                jl_start_block;
 
618
        unsigned int            bad_blocks_xtent_nb;
 
619
        char                    bad_blocks_loaded;
 
620
        char                    free_geom;    /* 1 = plus_geom must be freed */
 
621
};
 
622
typedef struct _HfsPPrivateFSData HfsPPrivateFSData;
 
623
 
 
624
/* Generic + btree key */
 
625
struct __attribute__ ((packed)) _HfsPPrivateGenericKey {
 
626
        uint16_t        key_length;
 
627
        uint8_t         key_content[1];       /* we use 1 as a minimum size */
 
628
};
 
629
typedef struct _HfsPPrivateGenericKey HfsPPrivateGenericKey;
 
630
 
 
631
/* ---- common ---- */
 
632
 
 
633
/* node and lead record reference for a BTree search */
 
634
struct _HfsCPrivateLeafRec {
 
635
        unsigned int    node_size;     /* in sectors */
 
636
        unsigned int    node_number;
 
637
        unsigned int    record_pos;
 
638
        unsigned int    record_number;
 
639
};
 
640
typedef struct _HfsCPrivateLeafRec HfsCPrivateLeafRec;
 
641
 
 
642
extern uint8_t*    hfs_block;
 
643
extern uint8_t*    hfsp_block;
 
644
extern unsigned    hfs_block_count;
 
645
extern unsigned    hfsp_block_count;
 
646
 
 
647
#endif /* _HFS_H */