2
libparted - a library for manipulating disk partitions
3
Copyright (C) 2003-2005, 2007, 2009-2012 Free Software Foundation, Inc.
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.
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.
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/>.
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))))
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
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 */
44
#define HFS_SIGNATURE 0x4244 /* 'BD' */
45
#define HFSP_SIGNATURE 0x482B /* 'H+' */
46
#define HFSX_SIGNATURE 0x4858 /* 'HX' */
48
#define HFSP_VERSION 4
49
#define HFSX_VERSION 5
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
60
#define HFS_IDX_NODE 0x00
61
#define HFS_HDR_NODE 0x01
62
#define HFS_MAP_NODE 0x02
63
#define HFS_LEAF_NODE 0xFF
65
#define HFS_FIRST_REC 0x0E
66
#define HFS_NSD_HD_REC 0x78
67
#define HFS_MAP_REC 0xF8
69
#define HFS_DATA_FORK 0x00
70
#define HFS_RES_FORK 0xFF
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
77
#define HFSP_ATTR_INLINE 0x10
78
#define HFSP_ATTR_FORK 0x20
79
#define HFSP_ATTR_EXTENTS 0x30
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
92
#define HFSJ_JOURN_IN_FS 0x00
93
#define HFSJ_JOURN_OTHER_DEV 0x01
94
#define HFSJ_JOURN_NEED_INIT 0x02
96
#define HFSJ_HEADER_MAGIC 0x4a4e4c78
97
#define HFSJ_ENDIAN_MAGIC 0x12345678
99
#define HFSX_CASE_FOLDING 0xCF /* case insensitive HFSX */
100
#define HFSX_BINARY_COMPARE 0xBC /* case sensitive HFSX */
103
#define HFSP_EXT_NB 8
105
/* Define the filenames used by the FS extractor */
106
#ifdef HFS_EXTRACT_FS
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"
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"
120
#endif /* HFS_EXTRACT_FS */
124
/* ----------------------------------- */
125
/* -- HFS DATA STRUCTURES -- */
126
/* ----------------------------------- */
128
/* Extent descriptor */
129
struct __attribute__ ((packed)) _HfsExtDescriptor {
130
uint16_t start_block;
131
uint16_t block_count;
133
typedef struct _HfsExtDescriptor HfsExtDescriptor;
134
typedef HfsExtDescriptor HfsExtDataRec[HFS_EXT_NB];
137
struct __attribute__ ((packed)) _HfsMasterDirectoryBlock {
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;
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;
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 */
168
struct __attribute__ ((packed)) {
170
HfsExtDescriptor location;
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;
178
typedef struct _HfsMasterDirectoryBlock HfsMasterDirectoryBlock;
180
/* B*-Tree Node Descriptor */
181
struct __attribute__ ((packed)) _HfsNodeDescriptor {
189
typedef struct _HfsNodeDescriptor HfsNodeDescriptor;
191
/* Header record of a whole B*-Tree */
192
struct __attribute__ ((packed)) _HfsHeaderRecord {
195
uint32_t leaf_records;
196
uint32_t first_leaf_node;
197
uint32_t last_leaf_node;
199
uint16_t max_key_len;
200
uint32_t total_nodes;
204
typedef struct _HfsHeaderRecord HfsHeaderRecord;
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 */
212
char name[31]; /* in fact physicaly 1 upto 31 */
214
typedef struct _HfsCatalogKey HfsCatalogKey;
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 */
223
typedef struct _HfsExtentKey HfsExtentKey;
225
/* Catalog subdata case directory */
226
struct __attribute__ ((packed)) _HfsDir {
228
uint16_t valence; /* number of files in this directory */
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];
237
typedef struct _HfsDir HfsDir;
239
/* Catalog subdata case file */
240
struct __attribute__ ((packed)) _HfsFile {
242
int8_t type; /* should be 0 */
243
int8_t FInfo[16]; /* used by Finder, handle as reserved */
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 */
256
HfsExtDataRec extents_data;
257
HfsExtDataRec extents_res;
260
typedef struct _HfsFile HfsFile;
262
/* Catalog subdata case directory thread */
263
struct __attribute__ ((packed)) _HfsDirTh {
264
uint32_t reserved[2];
269
typedef struct _HfsDirTh HfsDirTh;
271
/* Catalog subdata case file thread */
272
typedef struct _HfsDirTh HfsFileTh; /* same as directory thread */
275
struct __attribute__ ((packed)) _HfsCatalog {
285
typedef struct _HfsCatalog HfsCatalog;
289
/* ------------------------------------ */
290
/* -- HFS+ DATA STRUCTURES -- */
291
/* ------------------------------------ */
293
/* documented since 2004 in tn1150 */
294
struct __attribute__ ((packed)) _HfsPPerms {
297
uint32_t permissions;
298
uint32_t special_devices;
300
typedef struct _HfsPPerms HfsPPerms;
302
/* HFS+ extent descriptor*/
303
struct __attribute__ ((packed)) _HfsPExtDescriptor {
304
uint32_t start_block;
305
uint32_t block_count;
307
typedef struct _HfsPExtDescriptor HfsPExtDescriptor;
308
typedef HfsPExtDescriptor HfsPExtDataRec[HFSP_EXT_NB];
310
/* HFS+ fork data structure */
311
struct __attribute__ ((packed)) _HfsPForkData {
312
uint64_t logical_size;
314
uint32_t total_blocks;
315
HfsPExtDataRec extents;
317
typedef struct _HfsPForkData HfsPForkData;
319
/* HFS+ catalog node ID */
320
typedef uint32_t HfsPNodeID;
322
/* HFS+ file names */
323
typedef uint16_t unichar;
324
struct __attribute__ ((packed)) _HfsPUniStr255 {
326
unichar unicode[255]; /* 1 upto 255 */
328
typedef struct _HfsPUniStr255 HfsPUniStr255;
330
/* HFS+ volume header */
331
struct __attribute__ ((packed)) _HfsPVolumeHeader {
335
uint32_t last_mounted_version;
336
uint32_t journal_info_block;
338
uint32_t create_date;
339
uint32_t modify_date;
340
uint32_t backup_date;
341
uint32_t checked_date;
347
uint32_t total_blocks;
348
uint32_t free_blocks;
350
uint32_t next_allocation;
351
uint32_t res_clump_size;
352
uint32_t data_clump_size;
353
HfsPNodeID next_catalog_ID;
355
uint32_t write_count;
356
uint64_t encodings_bitmap;
358
uint8_t finder_info[32];
360
HfsPForkData allocation_file;
361
HfsPForkData extents_file;
362
HfsPForkData catalog_file;
363
HfsPForkData attributes_file;
364
HfsPForkData startup_file;
366
typedef struct _HfsPVolumeHeader HfsPVolumeHeader;
368
/* HFS+ B-Tree Node Descriptor. Same as HFS btree. */
369
struct __attribute__ ((packed)) _HfsPNodeDescriptor {
377
typedef struct _HfsPNodeDescriptor HfsPNodeDescriptor;
379
/* Header record of a whole HFS+ B-Tree. */
380
struct __attribute__ ((packed)) _HfsPHeaderRecord {
383
uint32_t leaf_records;
384
uint32_t first_leaf_node;
385
uint32_t last_leaf_node;
387
uint16_t max_key_len;
388
uint32_t total_nodes;
389
uint32_t free_nodes; /* same as hfs btree until here */
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 */
398
uint32_t reserved3[16];
400
typedef struct _HfsPHeaderRecord HfsPHeaderRecord;
402
/* Catalog key for B-Tree lookup in the HFS+ catalog file */
403
struct __attribute__ ((packed)) _HfsPCatalogKey {
405
HfsPNodeID parent_ID;
406
HfsPUniStr255 node_name;
408
typedef struct _HfsPCatalogKey HfsPCatalogKey;
410
/* HFS+ catalog subdata case dir */
411
struct __attribute__ ((packed)) _HfsPDir {
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;
426
typedef struct _HfsPDir HfsPDir;
428
/* HFS+ catalog subdata case file */
429
struct __attribute__ ((packed)) _HfsPFile {
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;
444
HfsPForkData data_fork;
445
HfsPForkData res_fork;
447
typedef struct _HfsPFile HfsPFile;
449
/* HFS+ catalog subdata case thread */
450
struct __attribute__ ((packed)) _HfsPThread {
452
HfsPNodeID parent_ID;
453
HfsPUniStr255 node_name;
455
typedef struct _HfsPThread HfsPDirTh;
456
typedef struct _HfsPThread HfsPFileTh;
458
/* HFS+ Catalog leaf data */
459
struct __attribute__ ((packed)) _HfsPCatalog {
468
typedef struct _HfsPCatalog HfsPCatalog;
470
/* HFS+ extents file key */
471
struct __attribute__ ((packed)) _HfsPExtentKey {
478
typedef struct _HfsPExtentKey HfsPExtentKey;
480
/* extent file data is HfsPExtDataRec */
482
/* Fork data attribute file */
483
struct __attribute__ ((packed)) _HfsPForkDataAttr {
484
uint32_t record_type;
486
union __attribute__ ((packed)) {
488
HfsPExtDataRec extents;
491
typedef struct _HfsPForkDataAttr HfsPForkDataAttr;
494
/* ----------- Journal data structures ----------- */
496
/* Info block : stored in a block # defined in the VH */
497
struct __attribute__ ((packed)) _HfsJJournalInfoBlock {
499
uint32_t device_signature[8];
502
uint32_t reserved[32];
504
typedef struct _HfsJJournalInfoBlock HfsJJournalInfoBlock;
506
struct __attribute__ ((packed)) _HfsJJournalHeader {
516
typedef struct _HfsJJournalHeader HfsJJournalHeader;
518
struct __attribute__ ((packed)) _HfsJBlockInfo {
519
uint64_t bnum; /* sector number */
520
uint32_t bsize; /* size in bytes */
523
typedef struct _HfsJBlockInfo HfsJBlockInfo;
525
struct __attribute__ ((packed)) _HfsJBlockListHeader {
526
uint16_t max_blocks; /* reserved */
531
HfsJBlockInfo binfo[1];
533
typedef struct _HfsJBlockListHeader HfsJBlockListHeader;
537
/* ---------------------------------------- */
538
/* -- INTERNAL DATA STRUCTURES -- */
539
/* ---------------------------------------- */
541
/* Data of an opened HFS file */
542
struct _HfsPrivateFile {
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 */
550
typedef struct _HfsPrivateFile HfsPrivateFile;
552
/* To store bad block list */
553
struct _HfsPrivateLinkExtent {
554
HfsExtDescriptor extent;
555
struct _HfsPrivateLinkExtent* next;
557
typedef struct _HfsPrivateLinkExtent HfsPrivateLinkExtent;
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;
569
typedef struct _HfsPrivateFSData HfsPrivateFSData;
571
/* Generic btree key */
572
struct __attribute__ ((packed)) _HfsPrivateGenericKey {
574
uint8_t key_content[1]; /* we use 1 as a minimum size */
576
typedef struct _HfsPrivateGenericKey HfsPrivateGenericKey;
578
/* ----- HFS+ ----- */
580
/* Data of an opened HFS file */
581
struct _HfsPPrivateFile {
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 */
589
typedef struct _HfsPPrivateFile HfsPPrivateFile;
591
struct _HfsPPrivateExtent {
592
PedSector start_sector;
593
PedSector sector_count;
595
typedef struct _HfsPPrivateExtent HfsPPrivateExtent;
597
/* To store bad block list */
598
struct _HfsPPrivateLinkExtent {
599
HfsPExtDescriptor extent;
600
struct _HfsPPrivateLinkExtent* next;
602
typedef struct _HfsPPrivateLinkExtent HfsPPrivateLinkExtent;
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_ */
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 */
622
typedef struct _HfsPPrivateFSData HfsPPrivateFSData;
624
/* Generic + btree key */
625
struct __attribute__ ((packed)) _HfsPPrivateGenericKey {
627
uint8_t key_content[1]; /* we use 1 as a minimum size */
629
typedef struct _HfsPPrivateGenericKey HfsPPrivateGenericKey;
631
/* ---- common ---- */
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;
640
typedef struct _HfsCPrivateLeafRec HfsCPrivateLeafRec;
642
extern uint8_t* hfs_block;
643
extern uint8_t* hfsp_block;
644
extern unsigned hfs_block_count;
645
extern unsigned hfsp_block_count;