2 * probe.h - constants and on-disk structures for extracting device data
4 * Copyright (C) 1999 by Andries Brouwer
5 * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
6 * Copyright (C) 2001 by Andreas Dilger
9 * This file may be redistributed under the terms of the
10 * GNU Lesser General Public License.
14 #ifndef _BLKID_PROBE_H
15 #define _BLKID_PROBE_H
17 #include <blkid/blkid_types.h>
21 #define SB_BUFFER_SIZE 0x11000
33 typedef int (*blkid_probe_t)(struct blkid_probe *probe,
34 struct blkid_magic *id, unsigned char *buf);
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 */
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.
51 struct ext2_super_block {
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;
60 unsigned char s_magic[2];
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];
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;
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;
94 __u32 s_raid_stripe_width;
95 __u32 s_reserved[163];
99 #define EXT2_FLAGS_TEST_FILESYS 0x0004
101 /* for s_feature_compat */
102 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
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
114 /* for s_feature_incompat */
115 #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
116 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
117 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
118 #define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
119 #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
120 #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
121 #define EXT4_FEATURE_INCOMPAT_MMP 0x0100
122 #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
124 #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
125 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
126 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
127 #define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
128 EXT2_FEATURE_INCOMPAT_META_BG)
129 #define EXT2_FEATURE_INCOMPAT_UNSUPPORTED ~EXT2_FEATURE_INCOMPAT_SUPP
130 #define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT2_FEATURE_RO_COMPAT_SUPP
132 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
133 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
134 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
135 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
136 EXT3_FEATURE_INCOMPAT_RECOVER| \
137 EXT2_FEATURE_INCOMPAT_META_BG)
138 #define EXT3_FEATURE_INCOMPAT_UNSUPPORTED ~EXT3_FEATURE_INCOMPAT_SUPP
139 #define EXT3_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT3_FEATURE_RO_COMPAT_SUPP
142 struct xfs_super_block {
143 unsigned char xs_magic[4];
148 unsigned char xs_uuid[16];
157 struct reiserfs_super_block {
158 __u32 rs_blocks_count;
159 __u32 rs_free_blocks;
161 __u32 rs_journal_block;
162 __u32 rs_journal_dev;
163 __u32 rs_orig_journal_size;
167 unsigned char rs_magic[12];
169 unsigned char rs_uuid[16];
173 struct reiser4_super_block {
174 unsigned char rs4_magic[16];
176 unsigned char rs4_uuid[16];
177 unsigned char rs4_label[16];
181 struct jfs_super_block {
182 unsigned char js_magic[4];
185 __u32 js_bsize; /* 4: aggregate block size in bytes */
186 __u16 js_l2bsize; /* 2: log2 of s_bsize */
187 __u16 js_l2bfactor; /* 2: log2(s_bsize/hardware block size) */
188 __u32 js_pbsize; /* 4: hardware/LVM block size in bytes */
189 __u16 js_l2pbsize; /* 2: log2 of s_pbsize */
190 __u16 js_pad; /* 2: padding necessary for alignment */
192 unsigned char js_uuid[16];
193 unsigned char js_label[16];
194 unsigned char js_loguuid[16];
197 struct romfs_super_block {
198 unsigned char ros_magic[8];
200 unsigned char ros_volume[16];
203 struct cramfs_super_block {
218 struct swap_id_block {
219 /* unsigned char sws_boot[1024]; */
223 unsigned char sws_uuid[16];
225 unsigned char sws_pad[117];
229 /* Yucky misaligned values */
230 struct vfat_super_block {
231 /* 00*/ unsigned char vs_ignored[3];
232 /* 03*/ unsigned char vs_sysid[8];
233 /* 0b*/ unsigned char vs_sector_size[2];
234 /* 0d*/ __u8 vs_cluster_size;
235 /* 0e*/ __u16 vs_reserved;
236 /* 10*/ __u8 vs_fats;
237 /* 11*/ unsigned char vs_dir_entries[2];
238 /* 13*/ unsigned char vs_sectors[2];
239 /* 15*/ unsigned char vs_media;
240 /* 16*/ __u16 vs_fat_length;
241 /* 18*/ __u16 vs_secs_track;
242 /* 1a*/ __u16 vs_heads;
243 /* 1c*/ __u32 vs_hidden;
244 /* 20*/ __u32 vs_total_sect;
245 /* 24*/ __u32 vs_fat32_length;
246 /* 28*/ __u16 vs_flags;
247 /* 2a*/ __u8 vs_version[2];
248 /* 2c*/ __u32 vs_root_cluster;
249 /* 30*/ __u16 vs_insfo_sector;
250 /* 32*/ __u16 vs_backup_boot;
251 /* 34*/ __u16 vs_reserved2[6];
252 /* 40*/ unsigned char vs_unknown[3];
253 /* 43*/ unsigned char vs_serno[4];
254 /* 47*/ unsigned char vs_label[11];
255 /* 52*/ unsigned char vs_magic[8];
256 /* 5a*/ unsigned char vs_dummy2[164];
257 /*1fe*/ unsigned char vs_pmagic[2];
260 /* Yucky misaligned values */
261 struct msdos_super_block {
262 /* 00*/ unsigned char ms_ignored[3];
263 /* 03*/ unsigned char ms_sysid[8];
264 /* 0b*/ unsigned char ms_sector_size[2];
265 /* 0d*/ __u8 ms_cluster_size;
266 /* 0e*/ __u16 ms_reserved;
267 /* 10*/ __u8 ms_fats;
268 /* 11*/ unsigned char ms_dir_entries[2];
269 /* 13*/ unsigned char ms_sectors[2];
270 /* 15*/ unsigned char ms_media;
271 /* 16*/ __u16 ms_fat_length;
272 /* 18*/ __u16 ms_secs_track;
273 /* 1a*/ __u16 ms_heads;
274 /* 1c*/ __u32 ms_hidden;
275 /* 20*/ __u32 ms_total_sect;
276 /* 24*/ unsigned char ms_unknown[3];
277 /* 27*/ unsigned char ms_serno[4];
278 /* 2b*/ unsigned char ms_label[11];
279 /* 36*/ unsigned char ms_magic[8];
280 /* 3d*/ unsigned char ms_dummy2[192];
281 /*1fe*/ unsigned char ms_pmagic[2];
284 struct vfat_dir_entry {
298 /* maximum number of clusters */
299 #define FAT12_MAX 0xFF4
300 #define FAT16_MAX 0xFFF4
301 #define FAT32_MAX 0x0FFFFFF6
303 struct minix_super_block {
306 __u16 ms_imap_blocks;
307 __u16 ms_zmap_blocks;
308 __u16 ms_firstdatazone;
309 __u16 ms_log_zone_size;
311 unsigned char ms_magic[2];
316 struct mdp_superblock_s {
329 __u32 not_persistent;
335 struct hfs_super_block {
341 struct ocfs_volume_header {
342 unsigned char minor_version[4];
343 unsigned char major_version[4];
344 unsigned char signature[128];
346 unsigned char mount_len[2];
349 struct ocfs_volume_label {
350 unsigned char disk_lock[48];
352 unsigned char label_len[2];
353 unsigned char vol_id[16];
354 unsigned char vol_id_len[2];
357 #define ocfsmajor(o) ((__u32)o.major_version[0] \
358 + (((__u32) o.major_version[1]) << 8) \
359 + (((__u32) o.major_version[2]) << 16) \
360 + (((__u32) o.major_version[3]) << 24))
361 #define ocfslabellen(o) ((__u32)o.label_len[0] + (((__u32) o.label_len[1]) << 8))
362 #define ocfsmountlen(o) ((__u32)o.mount_len[0] + (((__u32) o.mount_len[1])<<8))
364 #define OCFS_MAGIC "OracleCFS"
366 struct ocfs2_super_block {
367 unsigned char signature[8];
368 unsigned char s_dummy1[184];
369 unsigned char s_dummy2[80];
371 unsigned char s_uuid[16];
374 #define OCFS2_MIN_BLOCKSIZE 512
375 #define OCFS2_MAX_BLOCKSIZE 4096
377 #define OCFS2_SUPER_BLOCK_BLKNO 2
379 #define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2"
381 struct oracle_asm_disk_label {
387 #define ORACLE_ASM_DISK_LABEL_MARKED "ORCLDISK"
388 #define ORACLE_ASM_DISK_LABEL_OFFSET 32
390 struct iso_volume_descriptor {
391 unsigned char vd_type;
392 unsigned char vd_id[5];
393 unsigned char vd_version;
395 unsigned char system_id[32];
396 unsigned char volume_id[32];
397 unsigned char unused[8];
398 unsigned char space_size[8];
399 unsigned char escape_sequences[8];
402 /* Common gfs/gfs2 constants: */
403 #define GFS_MAGIC 0x01161970
404 #define GFS_DEFAULT_BSIZE 4096
405 #define GFS_SUPERBLOCK_OFFSET (0x10 * GFS_DEFAULT_BSIZE)
406 #define GFS_METATYPE_SB 1
407 #define GFS_FORMAT_SB 100
408 #define GFS_LOCKNAME_LEN 64
410 /* gfs1 constants: */
411 #define GFS_FORMAT_FS 1309
412 #define GFS_FORMAT_MULTI 1401
413 /* gfs2 constants: */
414 #define GFS2_FORMAT_FS 1801
415 #define GFS2_FORMAT_MULTI 1900
417 struct gfs2_meta_header {
420 __u64 __pad0; /* Was generation number in gfs1 */
422 __u32 __pad1; /* Was incarnation number in gfs1 */
431 struct gfs2_meta_header sb_header;
434 __u32 sb_multihost_format;
435 __u32 __pad0; /* Was superblock flags in gfs1 */
438 __u32 sb_bsize_shift;
439 __u32 __pad1; /* Was journal segment size in gfs1 */
441 struct gfs2_inum sb_master_dir; /* Was jindex dinode in gfs1 */
442 struct gfs2_inum __pad2; /* Was rindex dinode in gfs1 */
443 struct gfs2_inum sb_root_dir;
445 char sb_lockproto[GFS_LOCKNAME_LEN];
446 char sb_locktable[GFS_LOCKNAME_LEN];
447 /* In gfs1, quota and license dinodes followed */
450 struct ntfs_super_block {
453 __u8 bios_parameter_block[25];
455 __u64 number_of_sectors;
456 __u64 mft_cluster_location;
457 __u64 mft_mirror_cluster_location;
458 __s8 cluster_per_mft_record;
460 __s8 cluster_per_index_record;
466 struct master_file_table_record {
471 __u16 sequence_number;
476 __u32 bytes_allocated;
477 } __attribute__((__packed__));
479 struct file_attribute {
489 } __attribute__((__packed__));
491 #define MFT_RECORD_VOLUME 3
492 #define MFT_RECORD_ATTR_VOLUME_NAME 0x60
493 #define MFT_RECORD_ATTR_VOLUME_INFO 0x70
494 #define MFT_RECORD_ATTR_OBJECT_ID 0x40
495 #define MFT_RECORD_ATTR_END 0xffffffffu
498 struct hfs_finder_info {
506 } __attribute__((packed));
532 struct hfs_finder_info finder_info;
534 __u16 embed_startblock;
535 __u16 embed_blockcount;
536 } __attribute__((packed));
539 #define HFS_NODE_LEAF 0xff
540 #define HFSPLUS_POR_CNID 1
542 struct hfsplus_bnode_descriptor {
549 } __attribute__((packed));
551 struct hfsplus_bheader_record {
558 } __attribute__((packed));
560 struct hfsplus_catalog_key {
564 __u8 unicode[255 * 2];
565 } __attribute__((packed));
567 struct hfsplus_extent {
570 } __attribute__((packed));
572 #define HFSPLUS_EXTENT_COUNT 8
573 struct hfsplus_fork {
577 struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT];
578 } __attribute__((packed));
580 struct hfsplus_vol_header {
584 __u32 last_mount_vers;
601 struct hfs_finder_info finder_info;
602 struct hfsplus_fork alloc_file;
603 struct hfsplus_fork ext_file;
604 struct hfsplus_fork cat_file;
605 struct hfsplus_fork attr_file;
606 struct hfsplus_fork start_file;
607 } __attribute__((packed));
610 /* this is lvm's label_header & pv_header combined. */
612 #define LVM2_ID_LEN 32
614 struct lvm2_pv_label_header {
616 __u8 id[8]; /* LABELONE */
617 __u64 sector_xl; /* Sector number of this label */
618 __u32 crc_xl; /* From next field to end of sector */
619 __u32 offset_xl; /* Offset from start of struct to contents */
620 __u8 type[8]; /* LVM2 001 */
622 __u8 pv_uuid[LVM2_ID_LEN];
623 } __attribute__ ((packed));
627 * this is a very generous portion of the super block, giving us
628 * room to translate 14 chunks with 3 stripes each.
630 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
631 #define BTRFS_LABEL_SIZE 256
632 #define BTRFS_UUID_SIZE 16
633 #define BTRFS_FSID_SIZE 16
634 #define BTRFS_CSUM_SIZE 32
636 struct btrfs_dev_item {
637 /* the internal btrfs device id */
640 /* size of the device */
646 /* optimal io alignment for this device */
649 /* optimal io width for this device */
652 /* minimal io size for this device */
655 /* type and info about this device */
658 /* expected generation for this device */
662 * starting byte of this partition on the device,
663 * to allowr for stripe alignment in the future
667 /* grouping information for allocation decisions */
670 /* seek speed 0-100 where 100 is fastest */
673 /* bandwidth 0-100 where 100 is fastest */
676 /* btrfs generated uuid for this device */
677 __u8 uuid[BTRFS_UUID_SIZE];
679 /* uuid of FS who owns this device */
680 __u8 fsid[BTRFS_UUID_SIZE];
681 } __attribute__ ((__packed__));
684 * the super block basically lists the main trees of the FS
685 * it currently lacks any block count etc etc
687 struct btrfs_super_block {
688 __u8 csum[BTRFS_CSUM_SIZE];
689 /* the first 3 fields must match struct btrfs_header */
690 __u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
691 __u64 bytenr; /* this block number */
694 /* allowed to be different from the btrfs_header from here own down */
701 /* this will help find the new super based on the log root */
702 __u64 log_root_transid;
705 __u64 root_dir_objectid;
711 __u32 sys_chunk_array_size;
712 __u64 chunk_root_generation;
714 __u64 compat_ro_flags;
715 __u64 incompat_flags;
718 __u8 chunk_root_level;
720 struct btrfs_dev_item dev_item;
722 char label[BTRFS_LABEL_SIZE];
724 /* future expansion */
726 __u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
727 } __attribute__ ((__packed__));
730 * Byte swap functions
733 #define _INLINE_ static __inline__
734 #else /* For Watcom C */
735 #define _INLINE_ static inline
738 static __u16 blkid_swab16(__u16 val);
739 static __u32 blkid_swab32(__u32 val);
740 static __u64 blkid_swab64(__u64 val);
742 #if ((defined __GNUC__) && \
743 (defined(__i386__) || defined(__i486__) || defined(__i586__)))
745 #define _BLKID_HAVE_ASM_BITOPS_
747 _INLINE_ __u32 blkid_swab32(__u32 val)
749 #ifdef EXT2FS_REQUIRE_486
750 __asm__("bswap %0" : "=r" (val) : "0" (val));
752 __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
753 "rorl $16,%0\n\t" /* swap words */
754 "xchgb %b0,%h0" /* swap higher bytes */
761 _INLINE_ __u16 blkid_swab16(__u16 val)
763 __asm__("xchgb %b0,%h0" /* swap bytes */ \
769 _INLINE_ __u64 blkid_swab64(__u64 val)
771 return (blkid_swab32(val >> 32) |
772 (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
776 #if !defined(_BLKID_HAVE_ASM_BITOPS_)
778 _INLINE_ __u16 blkid_swab16(__u16 val)
780 return (val >> 8) | (val << 8);
783 _INLINE_ __u32 blkid_swab32(__u32 val)
785 return ((val>>24) | ((val>>8)&0xFF00) |
786 ((val<<8)&0xFF0000) | (val<<24));
789 _INLINE_ __u64 blkid_swab64(__u64 val)
791 return (blkid_swab32(val >> 32) |
792 (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
798 #ifdef WORDS_BIGENDIAN
799 #define blkid_le16(x) blkid_swab16(x)
800 #define blkid_le32(x) blkid_swab32(x)
801 #define blkid_le64(x) blkid_swab64(x)
802 #define blkid_be16(x) (x)
803 #define blkid_be32(x) (x)
804 #define blkid_be64(x) (x)
806 #define blkid_le16(x) (x)
807 #define blkid_le32(x) (x)
808 #define blkid_le64(x) (x)
809 #define blkid_be16(x) blkid_swab16(x)
810 #define blkid_be32(x) blkid_swab32(x)
811 #define blkid_be64(x) blkid_swab64(x)
816 #endif /* _BLKID_PROBE_H */