Whamcloud - gitweb
libext2fs: add inline_data feature into EXT2_LIB_FEATURE_INCOMPAT_SUPP
[tools/e2fsprogs.git] / lib / blkid / probe.h
1 /*
2  * probe.h - constants and on-disk structures for extracting device data
3  *
4  * Copyright (C) 1999 by Andries Brouwer
5  * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
6  * Copyright (C) 2001 by Andreas Dilger
7  *
8  * %Begin-Header%
9  * This file may be redistributed under the terms of the
10  * GNU Lesser General Public License.
11  * %End-Header%
12  */
13
14 #ifndef _BLKID_PROBE_H
15 #define _BLKID_PROBE_H
16
17 #include <blkid/blkid_types.h>
18
19 struct blkid_magic;
20
21 #define SB_BUFFER_SIZE          0x11000
22
23 struct blkid_probe {
24         int                     fd;
25         blkid_cache             cache;
26         blkid_dev               dev;
27         unsigned char           *sbbuf;
28         size_t                  sb_valid;
29         unsigned char           *buf;
30         size_t                  buf_max;
31 };
32
33 typedef int (*blkid_probe_t)(struct blkid_probe *probe,
34                              struct blkid_magic *id, unsigned char *buf);
35
36 struct blkid_magic {
37         const char      *bim_type;      /* type name for this magic */
38         long            bim_kboff;      /* kilobyte offset of superblock */
39         unsigned        bim_sboff;      /* byte offset within superblock */
40         unsigned        bim_len;        /* length of magic */
41         const char      *bim_magic;     /* magic string */
42         blkid_probe_t   bim_probe;      /* probe function */
43 };
44
45 /*
46  * Structures for each of the content types we want to extract information
47  * from.  We do not necessarily need the magic field here, because we have
48  * already identified the content type before we get this far.  It may still
49  * be useful if there are probe functions which handle multiple content types.
50  */
51 struct ext2_super_block {
52         __u32           s_inodes_count;
53         __u32           s_blocks_count;
54         __u32           s_r_blocks_count;
55         __u32           s_free_blocks_count;
56         __u32           s_free_inodes_count;
57         __u32           s_first_data_block;
58         __u32           s_log_block_size;
59         __u32           s_dummy3[7];
60         unsigned char   s_magic[2];
61         __u16           s_state;
62         __u32           s_dummy5[8];
63         __u32           s_feature_compat;
64         __u32           s_feature_incompat;
65         __u32           s_feature_ro_compat;
66         unsigned char   s_uuid[16];
67         char       s_volume_name[16];
68         char    s_last_mounted[64];
69         __u32   s_algorithm_usage_bitmap;
70         __u8    s_prealloc_blocks;
71         __u8    s_prealloc_dir_blocks;
72         __u16   s_reserved_gdt_blocks;
73         __u8    s_journal_uuid[16];
74         __u32   s_journal_inum;
75         __u32   s_journal_dev;
76         __u32   s_last_orphan;
77         __u32   s_hash_seed[4];
78         __u8    s_def_hash_version;
79         __u8    s_jnl_backup_type;
80         __u16   s_reserved_word_pad;
81         __u32   s_default_mount_opts;
82         __u32   s_first_meta_bg;
83         __u32   s_mkfs_time;
84         __u32   s_jnl_blocks[17];
85         __u32   s_blocks_count_hi;
86         __u32   s_r_blocks_count_hi;
87         __u32   s_free_blocks_hi;
88         __u16   s_min_extra_isize;
89         __u16   s_want_extra_isize;
90         __u32   s_flags;
91         __u16   s_raid_stride;
92         __u16   s_mmp_interval;
93         __u64   s_mmp_block;
94         __u32   s_raid_stripe_width;
95         __u32   s_reserved[163];
96 };
97
98 /* for s_flags */
99 #define EXT2_FLAGS_TEST_FILESYS         0x0004
100
101 /* for s_feature_compat */
102 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL         0x0004
103
104 /* for s_feature_ro_compat */
105 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER     0x0001
106 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE       0x0002
107 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR        0x0004
108 #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE        0x0008
109 #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM         0x0010
110 #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK        0x0020
111 #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE      0x0040
112 #define EXT4_FEATURE_RO_COMPAT_QUOTA            0x0100
113 #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM    0x0400
114
115 /* for s_feature_incompat */
116 #define EXT2_FEATURE_INCOMPAT_FILETYPE          0x0002
117 #define EXT3_FEATURE_INCOMPAT_RECOVER           0x0004
118 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV       0x0008
119 #define EXT2_FEATURE_INCOMPAT_META_BG           0x0010
120 #define EXT4_FEATURE_INCOMPAT_EXTENTS           0x0040 /* extents support */
121 #define EXT4_FEATURE_INCOMPAT_64BIT             0x0080
122 #define EXT4_FEATURE_INCOMPAT_MMP               0x0100
123 #define EXT4_FEATURE_INCOMPAT_FLEX_BG           0x0200
124
125 #define EXT2_FEATURE_RO_COMPAT_SUPP     (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
126                                          EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
127                                          EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
128 #define EXT2_FEATURE_INCOMPAT_SUPP      (EXT2_FEATURE_INCOMPAT_FILETYPE| \
129                                          EXT2_FEATURE_INCOMPAT_META_BG)
130 #define EXT2_FEATURE_INCOMPAT_UNSUPPORTED       ~EXT2_FEATURE_INCOMPAT_SUPP
131 #define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED      ~EXT2_FEATURE_RO_COMPAT_SUPP
132
133 #define EXT3_FEATURE_RO_COMPAT_SUPP     (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
134                                          EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
135                                          EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
136 #define EXT3_FEATURE_INCOMPAT_SUPP      (EXT2_FEATURE_INCOMPAT_FILETYPE| \
137                                          EXT3_FEATURE_INCOMPAT_RECOVER| \
138                                          EXT2_FEATURE_INCOMPAT_META_BG)
139 #define EXT3_FEATURE_INCOMPAT_UNSUPPORTED       ~EXT3_FEATURE_INCOMPAT_SUPP
140 #define EXT3_FEATURE_RO_COMPAT_UNSUPPORTED      ~EXT3_FEATURE_RO_COMPAT_SUPP
141
142
143 struct xfs_super_block {
144         unsigned char   xs_magic[4];
145         __u32           xs_blocksize;
146         __u64           xs_dblocks;
147         __u64           xs_rblocks;
148         __u32           xs_dummy1[2];
149         unsigned char   xs_uuid[16];
150         __u32           xs_dummy2[15];
151         char            xs_fname[12];
152         __u32           xs_dummy3[2];
153         __u64           xs_icount;
154         __u64           xs_ifree;
155         __u64           xs_fdblocks;
156 };
157
158 struct reiserfs_super_block {
159         __u32           rs_blocks_count;
160         __u32           rs_free_blocks;
161         __u32           rs_root_block;
162         __u32           rs_journal_block;
163         __u32           rs_journal_dev;
164         __u32           rs_orig_journal_size;
165         __u32           rs_dummy2[5];
166         __u16           rs_blocksize;
167         __u16           rs_dummy3[3];
168         unsigned char   rs_magic[12];
169         __u32           rs_dummy4[5];
170         unsigned char   rs_uuid[16];
171         char            rs_label[16];
172 };
173
174 struct reiser4_super_block {
175         unsigned char   rs4_magic[16];
176         __u16           rs4_dummy[2];
177         unsigned char   rs4_uuid[16];
178         unsigned char   rs4_label[16];
179         __u64           rs4_dummy2;
180 };
181
182 struct jfs_super_block {
183         unsigned char   js_magic[4];
184         __u32           js_version;
185         __u64           js_size;
186         __u32           js_bsize;       /* 4: aggregate block size in bytes */
187         __u16           js_l2bsize;     /* 2: log2 of s_bsize */
188         __u16           js_l2bfactor;   /* 2: log2(s_bsize/hardware block size) */
189         __u32           js_pbsize;      /* 4: hardware/LVM block size in bytes */
190         __u16           js_l2pbsize;    /* 2: log2 of s_pbsize */
191         __u16           js_pad;         /* 2: padding necessary for alignment */
192         __u32           js_dummy2[26];
193         unsigned char   js_uuid[16];
194         unsigned char   js_label[16];
195         unsigned char   js_loguuid[16];
196 };
197
198 struct romfs_super_block {
199         unsigned char   ros_magic[8];
200         __u32           ros_dummy1[2];
201         unsigned char   ros_volume[16];
202 };
203
204 struct cramfs_super_block {
205         __u8            magic[4];
206         __u32           size;
207         __u32           flags;
208         __u32           future;
209         __u8            signature[16];
210         struct cramfs_info {
211                 __u32           crc;
212                 __u32           edition;
213                 __u32           blocks;
214                 __u32           files;
215         } info;
216         __u8            name[16];
217 };
218
219 struct swap_id_block {
220 /*      unsigned char   sws_boot[1024]; */
221         __u32           sws_version;
222         __u32           sws_lastpage;
223         __u32           sws_nrbad;
224         unsigned char   sws_uuid[16];
225         char            sws_volume[16];
226         unsigned char   sws_pad[117];
227         __u32           sws_badpg;
228 };
229
230 /* Yucky misaligned values */
231 struct vfat_super_block {
232 /* 00*/ unsigned char   vs_ignored[3];
233 /* 03*/ unsigned char   vs_sysid[8];
234 /* 0b*/ unsigned char   vs_sector_size[2];
235 /* 0d*/ __u8            vs_cluster_size;
236 /* 0e*/ __u16           vs_reserved;
237 /* 10*/ __u8            vs_fats;
238 /* 11*/ unsigned char   vs_dir_entries[2];
239 /* 13*/ unsigned char   vs_sectors[2];
240 /* 15*/ unsigned char   vs_media;
241 /* 16*/ __u16           vs_fat_length;
242 /* 18*/ __u16           vs_secs_track;
243 /* 1a*/ __u16           vs_heads;
244 /* 1c*/ __u32           vs_hidden;
245 /* 20*/ __u32           vs_total_sect;
246 /* 24*/ __u32           vs_fat32_length;
247 /* 28*/ __u16           vs_flags;
248 /* 2a*/ __u8            vs_version[2];
249 /* 2c*/ __u32           vs_root_cluster;
250 /* 30*/ __u16           vs_insfo_sector;
251 /* 32*/ __u16           vs_backup_boot;
252 /* 34*/ __u16           vs_reserved2[6];
253 /* 40*/ unsigned char   vs_unknown[3];
254 /* 43*/ unsigned char   vs_serno[4];
255 /* 47*/ unsigned char   vs_label[11];
256 /* 52*/ unsigned char   vs_magic[8];
257 /* 5a*/ unsigned char   vs_dummy2[164];
258 /*1fe*/ unsigned char   vs_pmagic[2];
259 };
260
261 /* Yucky misaligned values */
262 struct msdos_super_block {
263 /* 00*/ unsigned char   ms_ignored[3];
264 /* 03*/ unsigned char   ms_sysid[8];
265 /* 0b*/ unsigned char   ms_sector_size[2];
266 /* 0d*/ __u8            ms_cluster_size;
267 /* 0e*/ __u16           ms_reserved;
268 /* 10*/ __u8            ms_fats;
269 /* 11*/ unsigned char   ms_dir_entries[2];
270 /* 13*/ unsigned char   ms_sectors[2];
271 /* 15*/ unsigned char   ms_media;
272 /* 16*/ __u16           ms_fat_length;
273 /* 18*/ __u16           ms_secs_track;
274 /* 1a*/ __u16           ms_heads;
275 /* 1c*/ __u32           ms_hidden;
276 /* 20*/ __u32           ms_total_sect;
277 /* 24*/ unsigned char   ms_unknown[3];
278 /* 27*/ unsigned char   ms_serno[4];
279 /* 2b*/ unsigned char   ms_label[11];
280 /* 36*/ unsigned char   ms_magic[8];
281 /* 3d*/ unsigned char   ms_dummy2[192];
282 /*1fe*/ unsigned char   ms_pmagic[2];
283 };
284
285 struct vfat_dir_entry {
286         __u8    name[11];
287         __u8    attr;
288         __u16   time_creat;
289         __u16   date_creat;
290         __u16   time_acc;
291         __u16   date_acc;
292         __u16   cluster_high;
293         __u16   time_write;
294         __u16   date_write;
295         __u16   cluster_low;
296         __u32   size;
297 };
298
299 /* maximum number of clusters */
300 #define FAT12_MAX 0xFF4
301 #define FAT16_MAX 0xFFF4
302 #define FAT32_MAX 0x0FFFFFF6
303
304 struct minix_super_block {
305         __u16           ms_ninodes;
306         __u16           ms_nzones;
307         __u16           ms_imap_blocks;
308         __u16           ms_zmap_blocks;
309         __u16           ms_firstdatazone;
310         __u16           ms_log_zone_size;
311         __u32           ms_max_size;
312         unsigned char   ms_magic[2];
313         __u16           ms_state;
314         __u32           ms_zones;
315 };
316
317 struct mdp_superblock_s {
318         __u32 md_magic;
319         __u32 major_version;
320         __u32 minor_version;
321         __u32 patch_version;
322         __u32 gvalid_words;
323         __u32 set_uuid0;
324         __u32 ctime;
325         __u32 level;
326         __u32 size;
327         __u32 nr_disks;
328         __u32 raid_disks;
329         __u32 md_minor;
330         __u32 not_persistent;
331         __u32 set_uuid1;
332         __u32 set_uuid2;
333         __u32 set_uuid3;
334 };
335
336 struct hfs_super_block {
337         char    h_magic[2];
338         char    h_dummy[18];
339         __u32   h_blksize;
340 };
341
342 struct ocfs_volume_header {
343         unsigned char   minor_version[4];
344         unsigned char   major_version[4];
345         unsigned char   signature[128];
346         char            mount[128];
347         unsigned char   mount_len[2];
348 };
349
350 struct ocfs_volume_label {
351         unsigned char   disk_lock[48];
352         char            label[64];
353         unsigned char   label_len[2];
354         unsigned char  vol_id[16];
355         unsigned char  vol_id_len[2];
356 };
357
358 #define ocfsmajor(o) ((__u32)o.major_version[0] \
359                    + (((__u32) o.major_version[1]) << 8) \
360                    + (((__u32) o.major_version[2]) << 16) \
361                    + (((__u32) o.major_version[3]) << 24))
362 #define ocfslabellen(o) ((__u32)o.label_len[0] + (((__u32) o.label_len[1]) << 8))
363 #define ocfsmountlen(o) ((__u32)o.mount_len[0] + (((__u32) o.mount_len[1])<<8))
364
365 #define OCFS_MAGIC "OracleCFS"
366
367 struct ocfs2_super_block {
368         unsigned char  signature[8];
369         unsigned char  s_dummy1[184];
370         unsigned char  s_dummy2[80];
371         char           s_label[64];
372         unsigned char  s_uuid[16];
373 };
374
375 #define OCFS2_MIN_BLOCKSIZE             512
376 #define OCFS2_MAX_BLOCKSIZE             4096
377
378 #define OCFS2_SUPER_BLOCK_BLKNO         2
379
380 #define OCFS2_SUPER_BLOCK_SIGNATURE     "OCFSV2"
381
382 struct oracle_asm_disk_label {
383         char dummy[32];
384         char dl_tag[8];
385         char dl_id[24];
386 };
387
388 #define ORACLE_ASM_DISK_LABEL_MARKED    "ORCLDISK"
389 #define ORACLE_ASM_DISK_LABEL_OFFSET    32
390
391 struct iso_volume_descriptor {
392         unsigned char   vd_type;
393         unsigned char   vd_id[5];
394         unsigned char   vd_version;
395         unsigned char   flags;
396         unsigned char   system_id[32];
397         unsigned char   volume_id[32];
398         unsigned char   unused[8];
399         unsigned char   space_size[8];
400         unsigned char   escape_sequences[8];
401 };
402
403 /* Common gfs/gfs2 constants: */
404 #define GFS_MAGIC               0x01161970
405 #define GFS_DEFAULT_BSIZE       4096
406 #define GFS_SUPERBLOCK_OFFSET   (0x10 * GFS_DEFAULT_BSIZE)
407 #define GFS_METATYPE_SB         1
408 #define GFS_FORMAT_SB           100
409 #define GFS_LOCKNAME_LEN        64
410
411 /* gfs1 constants: */
412 #define GFS_FORMAT_FS           1309
413 #define GFS_FORMAT_MULTI        1401
414 /* gfs2 constants: */
415 #define GFS2_FORMAT_FS          1801
416 #define GFS2_FORMAT_MULTI       1900
417
418 struct gfs2_meta_header {
419         __u32 mh_magic;
420         __u32 mh_type;
421         __u64 __pad0;          /* Was generation number in gfs1 */
422         __u32 mh_format;
423         __u32 __pad1;          /* Was incarnation number in gfs1 */
424 };
425
426 struct gfs2_inum {
427         __u64 no_formal_ino;
428         __u64 no_addr;
429 };
430
431 struct gfs2_sb {
432         struct gfs2_meta_header sb_header;
433
434         __u32 sb_fs_format;
435         __u32 sb_multihost_format;
436         __u32  __pad0;  /* Was superblock flags in gfs1 */
437
438         __u32 sb_bsize;
439         __u32 sb_bsize_shift;
440         __u32 __pad1;   /* Was journal segment size in gfs1 */
441
442         struct gfs2_inum sb_master_dir; /* Was jindex dinode in gfs1 */
443         struct gfs2_inum __pad2; /* Was rindex dinode in gfs1 */
444         struct gfs2_inum sb_root_dir;
445
446         char sb_lockproto[GFS_LOCKNAME_LEN];
447         char sb_locktable[GFS_LOCKNAME_LEN];
448         /* In gfs1, quota and license dinodes followed */
449 };
450
451 struct ntfs_super_block {
452         __u8    jump[3];
453         __u8    oem_id[8];
454         __u8    bios_parameter_block[25];
455         __u16   unused[2];
456         __u64   number_of_sectors;
457         __u64   mft_cluster_location;
458         __u64   mft_mirror_cluster_location;
459         __s8    cluster_per_mft_record;
460         __u8    reserved1[3];
461         __s8    cluster_per_index_record;
462         __u8    reserved2[3];
463         __u64   volume_serial;
464         __u16   checksum;
465 };
466
467 struct master_file_table_record {
468         __u32   magic;
469         __u16   usa_ofs;
470         __u16   usa_count;
471         __u64   lsn;
472         __u16   sequence_number;
473         __u16   link_count;
474         __u16   attrs_offset;
475         __u16   flags;
476         __u32   bytes_in_use;
477         __u32   bytes_allocated;
478 } __attribute__((__packed__));
479
480 struct file_attribute {
481         __u32   type;
482         __u32   len;
483         __u8    non_resident;
484         __u8    name_len;
485         __u16   name_offset;
486         __u16   flags;
487         __u16   instance;
488         __u32   value_len;
489         __u16   value_offset;
490 } __attribute__((__packed__));
491
492 #define MFT_RECORD_VOLUME                       3
493 #define MFT_RECORD_ATTR_VOLUME_NAME             0x60
494 #define MFT_RECORD_ATTR_VOLUME_INFO             0x70
495 #define MFT_RECORD_ATTR_OBJECT_ID               0x40
496 #define MFT_RECORD_ATTR_END                     0xffffffffu
497
498 /* HFS / HFS+ */
499 struct hfs_finder_info {
500         __u32        boot_folder;
501         __u32        start_app;
502         __u32        open_folder;
503         __u32        os9_folder;
504         __u32        reserved;
505         __u32        osx_folder;
506         __u8         id[8];
507 } __attribute__((packed));
508
509 struct hfs_mdb {
510         __u8         signature[2];
511         __u32        cr_date;
512         __u32        ls_Mod;
513         __u16        atrb;
514         __u16        nm_fls;
515         __u16        vbm_st;
516         __u16        alloc_ptr;
517         __u16        nm_al_blks;
518         __u32        al_blk_size;
519         __u32        clp_size;
520         __u16        al_bl_st;
521         __u32        nxt_cnid;
522         __u16        free_bks;
523         __u8         label_len;
524         __u8         label[27];
525         __u32        vol_bkup;
526         __u16        vol_seq_num;
527         __u32        wr_cnt;
528         __u32        xt_clump_size;
529         __u32        ct_clump_size;
530         __u16        num_root_dirs;
531         __u32        file_count;
532         __u32        dir_count;
533         struct hfs_finder_info finder_info;
534         __u8         embed_sig[2];
535         __u16        embed_startblock;
536         __u16        embed_blockcount;
537 } __attribute__((packed));
538
539
540 #define HFS_NODE_LEAF                   0xff
541 #define HFSPLUS_POR_CNID                1
542
543 struct hfsplus_bnode_descriptor {
544         __u32           next;
545         __u32           prev;
546         __u8            type;
547         __u8            height;
548         __u16           num_recs;
549         __u16           reserved;
550 } __attribute__((packed));
551
552 struct hfsplus_bheader_record {
553         __u16           depth;
554         __u32           root;
555         __u32           leaf_count;
556         __u32           leaf_head;
557         __u32           leaf_tail;
558         __u16           node_size;
559 } __attribute__((packed));
560
561 struct hfsplus_catalog_key {
562         __u16   key_len;
563         __u32   parent_id;
564         __u16   unicode_len;
565         __u8            unicode[255 * 2];
566 } __attribute__((packed));
567
568 struct hfsplus_extent {
569         __u32           start_block;
570         __u32           block_count;
571 } __attribute__((packed));
572
573 #define HFSPLUS_EXTENT_COUNT            8
574 struct hfsplus_fork {
575         __u64           total_size;
576         __u32           clump_size;
577         __u32           total_blocks;
578         struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT];
579 } __attribute__((packed));
580
581 struct hfsplus_vol_header {
582         __u8            signature[2];
583         __u16           version;
584         __u32           attributes;
585         __u32           last_mount_vers;
586         __u32           reserved;
587         __u32           create_date;
588         __u32           modify_date;
589         __u32           backup_date;
590         __u32           checked_date;
591         __u32           file_count;
592         __u32           folder_count;
593         __u32           blocksize;
594         __u32           total_blocks;
595         __u32           free_blocks;
596         __u32           next_alloc;
597         __u32           rsrc_clump_sz;
598         __u32           data_clump_sz;
599         __u32           next_cnid;
600         __u32           write_count;
601         __u64           encodings_bmp;
602         struct hfs_finder_info finder_info;
603         struct hfsplus_fork alloc_file;
604         struct hfsplus_fork ext_file;
605         struct hfsplus_fork cat_file;
606         struct hfsplus_fork attr_file;
607         struct hfsplus_fork start_file;
608 }  __attribute__((packed));
609
610
611 /* this is lvm's label_header & pv_header combined. */
612
613 #define LVM2_ID_LEN 32
614
615 struct lvm2_pv_label_header {
616         /* label_header */
617         __u8    id[8];          /* LABELONE */
618         __u64   sector_xl;      /* Sector number of this label */
619         __u32   crc_xl;         /* From next field to end of sector */
620         __u32   offset_xl;      /* Offset from start of struct to contents */
621         __u8    type[8];        /* LVM2 001 */
622         /* pv_header */
623         __u8    pv_uuid[LVM2_ID_LEN];
624 } __attribute__ ((packed));
625
626
627 /*
628  * this is a very generous portion of the super block, giving us
629  * room to translate 14 chunks with 3 stripes each.
630  */
631 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
632 #define BTRFS_LABEL_SIZE 256
633 #define BTRFS_UUID_SIZE 16
634 #define BTRFS_FSID_SIZE 16
635 #define BTRFS_CSUM_SIZE 32
636
637 struct btrfs_dev_item {
638         /* the internal btrfs device id */
639         __u64 devid;
640
641         /* size of the device */
642         __u64 total_bytes;
643
644         /* bytes used */
645         __u64 bytes_used;
646
647         /* optimal io alignment for this device */
648         __u32 io_align;
649
650         /* optimal io width for this device */
651         __u32 io_width;
652
653         /* minimal io size for this device */
654         __u32 sector_size;
655
656         /* type and info about this device */
657         __u64 type;
658
659         /* expected generation for this device */
660         __u64 generation;
661
662         /*
663          * starting byte of this partition on the device,
664          * to allowr for stripe alignment in the future
665          */
666         __u64 start_offset;
667
668         /* grouping information for allocation decisions */
669         __u32 dev_group;
670
671         /* seek speed 0-100 where 100 is fastest */
672         __u8 seek_speed;
673
674         /* bandwidth 0-100 where 100 is fastest */
675         __u8 bandwidth;
676
677         /* btrfs generated uuid for this device */
678         __u8 uuid[BTRFS_UUID_SIZE];
679
680         /* uuid of FS who owns this device */
681         __u8 fsid[BTRFS_UUID_SIZE];
682 } __attribute__ ((__packed__));
683
684 /*
685  * the super block basically lists the main trees of the FS
686  * it currently lacks any block count etc etc
687  */
688 struct btrfs_super_block {
689         __u8 csum[BTRFS_CSUM_SIZE];
690         /* the first 3 fields must match struct btrfs_header */
691         __u8 fsid[BTRFS_FSID_SIZE];    /* FS specific uuid */
692         __u64 bytenr; /* this block number */
693         __u64 flags;
694
695         /* allowed to be different from the btrfs_header from here own down */
696         __u64 magic;
697         __u64 generation;
698         __u64 root;
699         __u64 chunk_root;
700         __u64 log_root;
701
702         /* this will help find the new super based on the log root */
703         __u64 log_root_transid;
704         __u64 total_bytes;
705         __u64 bytes_used;
706         __u64 root_dir_objectid;
707         __u64 num_devices;
708         __u32 sectorsize;
709         __u32 nodesize;
710         __u32 leafsize;
711         __u32 stripesize;
712         __u32 sys_chunk_array_size;
713         __u64 chunk_root_generation;
714         __u64 compat_flags;
715         __u64 compat_ro_flags;
716         __u64 incompat_flags;
717         __u16 csum_type;
718         __u8 root_level;
719         __u8 chunk_root_level;
720         __u8 log_root_level;
721         struct btrfs_dev_item dev_item;
722
723         char label[BTRFS_LABEL_SIZE];
724
725         /* future expansion */
726         __u64 reserved[32];
727         __u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
728 } __attribute__ ((__packed__));
729
730 /*
731  * Byte swap functions
732  */
733 #ifdef __GNUC__
734 #define _INLINE_ static __inline__
735 #else                           /* For Watcom C */
736 #define _INLINE_ static inline
737 #endif
738
739 static __u16 blkid_swab16(__u16 val);
740 static __u32 blkid_swab32(__u32 val);
741 static __u64 blkid_swab64(__u64 val);
742
743 #if ((defined __GNUC__) && \
744      (defined(__i386__) || defined(__i486__) || defined(__i586__)))
745
746 #define _BLKID_HAVE_ASM_BITOPS_
747
748 _INLINE_ __u32 blkid_swab32(__u32 val)
749 {
750 #ifdef EXT2FS_REQUIRE_486
751         __asm__("bswap %0" : "=r" (val) : "0" (val));
752 #else
753         __asm__("xchgb %b0,%h0\n\t"     /* swap lower bytes     */
754                 "rorl $16,%0\n\t"       /* swap words           */
755                 "xchgb %b0,%h0"         /* swap higher bytes    */
756                 :"=q" (val)
757                 : "0" (val));
758 #endif
759         return val;
760 }
761
762 _INLINE_ __u16 blkid_swab16(__u16 val)
763 {
764         __asm__("xchgb %b0,%h0"         /* swap bytes           */ \
765                 : "=q" (val) \
766                 :  "0" (val)); \
767                 return val;
768 }
769
770 _INLINE_ __u64 blkid_swab64(__u64 val)
771 {
772         return (blkid_swab32(val >> 32) |
773                 (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
774 }
775 #endif
776
777 #if !defined(_BLKID_HAVE_ASM_BITOPS_)
778
779 _INLINE_  __u16 blkid_swab16(__u16 val)
780 {
781         return (val >> 8) | (val << 8);
782 }
783
784 _INLINE_ __u32 blkid_swab32(__u32 val)
785 {
786         return ((val>>24) | ((val>>8)&0xFF00) |
787                 ((val<<8)&0xFF0000) | (val<<24));
788 }
789
790 _INLINE_ __u64 blkid_swab64(__u64 val)
791 {
792         return (blkid_swab32(val >> 32) |
793                 (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
794 }
795 #endif
796
797
798
799 #ifdef WORDS_BIGENDIAN
800 #define blkid_le16(x) blkid_swab16(x)
801 #define blkid_le32(x) blkid_swab32(x)
802 #define blkid_le64(x) blkid_swab64(x)
803 #define blkid_be16(x) (x)
804 #define blkid_be32(x) (x)
805 #define blkid_be64(x) (x)
806 #else
807 #define blkid_le16(x) (x)
808 #define blkid_le32(x) (x)
809 #define blkid_le64(x) (x)
810 #define blkid_be16(x) blkid_swab16(x)
811 #define blkid_be32(x) blkid_swab32(x)
812 #define blkid_be64(x) blkid_swab64(x)
813 #endif
814
815 #undef _INLINE_
816
817 #endif /* _BLKID_PROBE_H */