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
19 #include <blkid/blkid_types.h>
23 #define SB_BUFFER_SIZE 0x11000
35 typedef int (*blkid_probe_t)(struct blkid_probe *probe,
36 struct blkid_magic *id, unsigned char *buf);
39 const char *bim_type; /* type name for this magic */
40 long bim_kboff; /* kilobyte offset of superblock */
41 unsigned bim_sboff; /* byte offset within superblock */
42 unsigned bim_len; /* length of magic */
43 const char *bim_magic; /* magic string */
44 blkid_probe_t bim_probe; /* probe function */
48 * Structures for each of the content types we want to extract information
49 * from. We do not necessarily need the magic field here, because we have
50 * already identified the content type before we get this far. It may still
51 * be useful if there are probe functions which handle multiple content types.
53 struct ext2_super_block {
56 __u32 s_r_blocks_count;
57 __u32 s_free_blocks_count;
58 __u32 s_free_inodes_count;
59 __u32 s_first_data_block;
60 __u32 s_log_block_size;
62 unsigned char s_magic[2];
65 __u32 s_feature_compat;
66 __u32 s_feature_incompat;
67 __u32 s_feature_ro_compat;
68 unsigned char s_uuid[16];
69 char s_volume_name[16];
70 char s_last_mounted[64];
71 __u32 s_algorithm_usage_bitmap;
72 __u8 s_prealloc_blocks;
73 __u8 s_prealloc_dir_blocks;
74 __u16 s_reserved_gdt_blocks;
75 __u8 s_journal_uuid[16];
80 __u8 s_def_hash_version;
81 __u8 s_jnl_backup_type;
82 __u16 s_reserved_word_pad;
83 __u32 s_default_mount_opts;
84 __u32 s_first_meta_bg;
86 __u32 s_jnl_blocks[17];
87 __u32 s_blocks_count_hi;
88 __u32 s_r_blocks_count_hi;
89 __u32 s_free_blocks_hi;
90 __u16 s_min_extra_isize;
91 __u16 s_want_extra_isize;
96 __u32 s_raid_stripe_width;
97 __u32 s_reserved[163];
101 #define EXT2_FLAGS_TEST_FILESYS 0x0004
103 /* for s_feature_compat */
104 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
106 /* for s_feature_ro_compat */
107 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
108 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
109 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
110 #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
111 #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
112 #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
113 #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
114 #define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100
115 #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400
117 /* for s_feature_incompat */
118 #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
119 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
120 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
121 #define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
122 #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
123 #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
124 #define EXT4_FEATURE_INCOMPAT_MMP 0x0100
125 #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
127 #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
128 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
129 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
130 #define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
131 EXT2_FEATURE_INCOMPAT_META_BG)
132 #define EXT2_FEATURE_INCOMPAT_UNSUPPORTED ~EXT2_FEATURE_INCOMPAT_SUPP
133 #define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT2_FEATURE_RO_COMPAT_SUPP
135 #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
136 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
137 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
138 #define EXT3_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
139 EXT3_FEATURE_INCOMPAT_RECOVER| \
140 EXT2_FEATURE_INCOMPAT_META_BG)
141 #define EXT3_FEATURE_INCOMPAT_UNSUPPORTED ~EXT3_FEATURE_INCOMPAT_SUPP
142 #define EXT3_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT3_FEATURE_RO_COMPAT_SUPP
145 struct xfs_super_block {
146 unsigned char xs_magic[4];
151 unsigned char xs_uuid[16];
160 struct reiserfs_super_block {
161 __u32 rs_blocks_count;
162 __u32 rs_free_blocks;
164 __u32 rs_journal_block;
165 __u32 rs_journal_dev;
166 __u32 rs_orig_journal_size;
170 unsigned char rs_magic[12];
172 unsigned char rs_uuid[16];
176 struct reiser4_super_block {
177 unsigned char rs4_magic[16];
179 unsigned char rs4_uuid[16];
180 unsigned char rs4_label[16];
184 struct jfs_super_block {
185 unsigned char js_magic[4];
188 __u32 js_bsize; /* 4: aggregate block size in bytes */
189 __u16 js_l2bsize; /* 2: log2 of s_bsize */
190 __u16 js_l2bfactor; /* 2: log2(s_bsize/hardware block size) */
191 __u32 js_pbsize; /* 4: hardware/LVM block size in bytes */
192 __u16 js_l2pbsize; /* 2: log2 of s_pbsize */
193 __u16 js_pad; /* 2: padding necessary for alignment */
195 unsigned char js_uuid[16];
196 unsigned char js_label[16];
197 unsigned char js_loguuid[16];
200 struct romfs_super_block {
201 unsigned char ros_magic[8];
203 unsigned char ros_volume[16];
206 struct cramfs_super_block {
221 struct swap_id_block {
222 /* unsigned char sws_boot[1024]; */
226 unsigned char sws_uuid[16];
228 unsigned char sws_pad[117];
232 /* Yucky misaligned values */
233 struct vfat_super_block {
234 /* 00*/ unsigned char vs_ignored[3];
235 /* 03*/ unsigned char vs_sysid[8];
236 /* 0b*/ unsigned char vs_sector_size[2];
237 /* 0d*/ __u8 vs_cluster_size;
238 /* 0e*/ __u16 vs_reserved;
239 /* 10*/ __u8 vs_fats;
240 /* 11*/ unsigned char vs_dir_entries[2];
241 /* 13*/ unsigned char vs_sectors[2];
242 /* 15*/ unsigned char vs_media;
243 /* 16*/ __u16 vs_fat_length;
244 /* 18*/ __u16 vs_secs_track;
245 /* 1a*/ __u16 vs_heads;
246 /* 1c*/ __u32 vs_hidden;
247 /* 20*/ __u32 vs_total_sect;
248 /* 24*/ __u32 vs_fat32_length;
249 /* 28*/ __u16 vs_flags;
250 /* 2a*/ __u8 vs_version[2];
251 /* 2c*/ __u32 vs_root_cluster;
252 /* 30*/ __u16 vs_insfo_sector;
253 /* 32*/ __u16 vs_backup_boot;
254 /* 34*/ __u16 vs_reserved2[6];
255 /* 40*/ unsigned char vs_unknown[3];
256 /* 43*/ unsigned char vs_serno[4];
257 /* 47*/ unsigned char vs_label[11];
258 /* 52*/ unsigned char vs_magic[8];
259 /* 5a*/ unsigned char vs_dummy2[164];
260 /*1fe*/ unsigned char vs_pmagic[2];
263 /* Yucky misaligned values */
264 struct msdos_super_block {
265 /* 00*/ unsigned char ms_ignored[3];
266 /* 03*/ unsigned char ms_sysid[8];
267 /* 0b*/ unsigned char ms_sector_size[2];
268 /* 0d*/ __u8 ms_cluster_size;
269 /* 0e*/ __u16 ms_reserved;
270 /* 10*/ __u8 ms_fats;
271 /* 11*/ unsigned char ms_dir_entries[2];
272 /* 13*/ unsigned char ms_sectors[2];
273 /* 15*/ unsigned char ms_media;
274 /* 16*/ __u16 ms_fat_length;
275 /* 18*/ __u16 ms_secs_track;
276 /* 1a*/ __u16 ms_heads;
277 /* 1c*/ __u32 ms_hidden;
278 /* 20*/ __u32 ms_total_sect;
279 /* 24*/ unsigned char ms_unknown[3];
280 /* 27*/ unsigned char ms_serno[4];
281 /* 2b*/ unsigned char ms_label[11];
282 /* 36*/ unsigned char ms_magic[8];
283 /* 3d*/ unsigned char ms_dummy2[192];
284 /*1fe*/ unsigned char ms_pmagic[2];
287 struct vfat_dir_entry {
301 /* maximum number of clusters */
302 #define FAT12_MAX 0xFF4
303 #define FAT16_MAX 0xFFF4
304 #define FAT32_MAX 0x0FFFFFF6
306 struct minix_super_block {
309 __u16 ms_imap_blocks;
310 __u16 ms_zmap_blocks;
311 __u16 ms_firstdatazone;
312 __u16 ms_log_zone_size;
314 unsigned char ms_magic[2];
319 struct mdp_superblock_s {
332 __u32 not_persistent;
338 struct hfs_super_block {
344 struct ocfs_volume_header {
345 unsigned char minor_version[4];
346 unsigned char major_version[4];
347 unsigned char signature[128];
349 unsigned char mount_len[2];
352 struct ocfs_volume_label {
353 unsigned char disk_lock[48];
355 unsigned char label_len[2];
356 unsigned char vol_id[16];
357 unsigned char vol_id_len[2];
360 #define ocfsmajor(o) ((__u32)o.major_version[0] \
361 + (((__u32) o.major_version[1]) << 8) \
362 + (((__u32) o.major_version[2]) << 16) \
363 + (((__u32) o.major_version[3]) << 24))
364 #define ocfslabellen(o) ((__u32)o.label_len[0] + (((__u32) o.label_len[1]) << 8))
365 #define ocfsmountlen(o) ((__u32)o.mount_len[0] + (((__u32) o.mount_len[1])<<8))
367 #define OCFS_MAGIC "OracleCFS"
369 struct ocfs2_super_block {
370 unsigned char signature[8];
371 unsigned char s_dummy1[184];
372 unsigned char s_dummy2[80];
374 unsigned char s_uuid[16];
377 #define OCFS2_MIN_BLOCKSIZE 512
378 #define OCFS2_MAX_BLOCKSIZE 4096
380 #define OCFS2_SUPER_BLOCK_BLKNO 2
382 #define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2"
384 struct oracle_asm_disk_label {
390 #define ORACLE_ASM_DISK_LABEL_MARKED "ORCLDISK"
391 #define ORACLE_ASM_DISK_LABEL_OFFSET 32
393 struct iso_volume_descriptor {
394 unsigned char vd_type;
395 unsigned char vd_id[5];
396 unsigned char vd_version;
398 unsigned char system_id[32];
399 unsigned char volume_id[32];
400 unsigned char unused[8];
401 unsigned char space_size[8];
402 unsigned char escape_sequences[8];
405 /* Common gfs/gfs2 constants: */
406 #define GFS_MAGIC 0x01161970
407 #define GFS_DEFAULT_BSIZE 4096
408 #define GFS_SUPERBLOCK_OFFSET (0x10 * GFS_DEFAULT_BSIZE)
409 #define GFS_METATYPE_SB 1
410 #define GFS_FORMAT_SB 100
411 #define GFS_LOCKNAME_LEN 64
413 /* gfs1 constants: */
414 #define GFS_FORMAT_FS 1309
415 #define GFS_FORMAT_MULTI 1401
416 /* gfs2 constants: */
417 #define GFS2_FORMAT_FS 1801
418 #define GFS2_FORMAT_MULTI 1900
420 struct gfs2_meta_header {
423 __u64 __pad0; /* Was generation number in gfs1 */
425 __u32 __pad1; /* Was incarnation number in gfs1 */
434 struct gfs2_meta_header sb_header;
437 __u32 sb_multihost_format;
438 __u32 __pad0; /* Was superblock flags in gfs1 */
441 __u32 sb_bsize_shift;
442 __u32 __pad1; /* Was journal segment size in gfs1 */
444 struct gfs2_inum sb_master_dir; /* Was jindex dinode in gfs1 */
445 struct gfs2_inum __pad2; /* Was rindex dinode in gfs1 */
446 struct gfs2_inum sb_root_dir;
448 char sb_lockproto[GFS_LOCKNAME_LEN];
449 char sb_locktable[GFS_LOCKNAME_LEN];
450 /* In gfs1, quota and license dinodes followed */
453 struct ntfs_super_block {
456 __u8 bios_parameter_block[25];
458 __u64 number_of_sectors;
459 __u64 mft_cluster_location;
460 __u64 mft_mirror_cluster_location;
461 __s8 cluster_per_mft_record;
463 __s8 cluster_per_index_record;
469 struct master_file_table_record {
474 __u16 sequence_number;
479 __u32 bytes_allocated;
480 } __attribute__((__packed__));
482 struct file_attribute {
492 } __attribute__((__packed__));
494 #define MFT_RECORD_VOLUME 3
495 #define MFT_RECORD_ATTR_VOLUME_NAME 0x60
496 #define MFT_RECORD_ATTR_VOLUME_INFO 0x70
497 #define MFT_RECORD_ATTR_OBJECT_ID 0x40
498 #define MFT_RECORD_ATTR_END 0xffffffffu
501 struct hfs_finder_info {
509 } __attribute__((packed));
535 struct hfs_finder_info finder_info;
537 __u16 embed_startblock;
538 __u16 embed_blockcount;
539 } __attribute__((packed));
542 #define HFS_NODE_LEAF 0xff
543 #define HFSPLUS_POR_CNID 1
545 struct hfsplus_bnode_descriptor {
552 } __attribute__((packed));
554 struct hfsplus_bheader_record {
561 } __attribute__((packed));
563 struct hfsplus_catalog_key {
567 __u8 unicode[255 * 2];
568 } __attribute__((packed));
570 struct hfsplus_extent {
573 } __attribute__((packed));
575 #define HFSPLUS_EXTENT_COUNT 8
576 struct hfsplus_fork {
580 struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT];
581 } __attribute__((packed));
583 struct hfsplus_vol_header {
587 __u32 last_mount_vers;
604 struct hfs_finder_info finder_info;
605 struct hfsplus_fork alloc_file;
606 struct hfsplus_fork ext_file;
607 struct hfsplus_fork cat_file;
608 struct hfsplus_fork attr_file;
609 struct hfsplus_fork start_file;
610 } __attribute__((packed));
613 /* this is lvm's label_header & pv_header combined. */
615 #define LVM2_ID_LEN 32
617 struct lvm2_pv_label_header {
619 __u8 id[8]; /* LABELONE */
620 __u64 sector_xl; /* Sector number of this label */
621 __u32 crc_xl; /* From next field to end of sector */
622 __u32 offset_xl; /* Offset from start of struct to contents */
623 __u8 type[8]; /* LVM2 001 */
625 __u8 pv_uuid[LVM2_ID_LEN];
626 } __attribute__ ((packed));
630 * this is a very generous portion of the super block, giving us
631 * room to translate 14 chunks with 3 stripes each.
633 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
634 #define BTRFS_LABEL_SIZE 256
635 #define BTRFS_UUID_SIZE 16
636 #define BTRFS_FSID_SIZE 16
637 #define BTRFS_CSUM_SIZE 32
639 struct btrfs_dev_item {
640 /* the internal btrfs device id */
643 /* size of the device */
649 /* optimal io alignment for this device */
652 /* optimal io width for this device */
655 /* minimal io size for this device */
658 /* type and info about this device */
661 /* expected generation for this device */
665 * starting byte of this partition on the device,
666 * to allow for stripe alignment in the future
670 /* grouping information for allocation decisions */
673 /* seek speed 0-100 where 100 is fastest */
676 /* bandwidth 0-100 where 100 is fastest */
679 /* btrfs generated uuid for this device */
680 __u8 uuid[BTRFS_UUID_SIZE];
682 /* uuid of FS who owns this device */
683 __u8 fsid[BTRFS_UUID_SIZE];
684 } __attribute__ ((__packed__));
687 * the super block basically lists the main trees of the FS
688 * it currently lacks any block count etc etc
690 struct btrfs_super_block {
691 __u8 csum[BTRFS_CSUM_SIZE];
692 /* the first 3 fields must match struct btrfs_header */
693 __u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
694 __u64 bytenr; /* this block number */
697 /* allowed to be different from the btrfs_header from here own down */
704 /* this will help find the new super based on the log root */
705 __u64 log_root_transid;
708 __u64 root_dir_objectid;
714 __u32 sys_chunk_array_size;
715 __u64 chunk_root_generation;
717 __u64 compat_ro_flags;
718 __u64 incompat_flags;
721 __u8 chunk_root_level;
723 struct btrfs_dev_item dev_item;
725 char label[BTRFS_LABEL_SIZE];
727 /* future expansion */
729 __u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
730 } __attribute__ ((__packed__));
732 #define F2FS_MAX_EXTENSION 64 /* # of extension entries */
734 struct f2fs_super_block {
735 __u32 magic; /* Magic Number */
736 __u16 major_ver; /* Major Version */
737 __u16 minor_ver; /* Minor Version */
738 __u32 log_sectorsize; /* log2 sector size in bytes */
739 __u32 log_sectors_per_block; /* log2 # of sectors per block */
740 __u32 log_blocksize; /* log2 block size in bytes */
741 __u32 log_blocks_per_seg; /* log2 # of blocks per segment */
742 __u32 segs_per_sec; /* # of segments per section */
743 __u32 secs_per_zone; /* # of sections per zone */
744 __u32 checksum_offset; /* checksum offset inside super block */
745 __u64 block_count; /* total # of user blocks */
746 __u32 section_count; /* total # of sections */
747 __u32 segment_count; /* total # of segments */
748 __u32 segment_count_ckpt; /* # of segments for checkpoint */
749 __u32 segment_count_sit; /* # of segments for SIT */
750 __u32 segment_count_nat; /* # of segments for NAT */
751 __u32 segment_count_ssa; /* # of segments for SSA */
752 __u32 segment_count_main; /* # of segments for main area */
753 __u32 segment0_blkaddr; /* start block address of segment 0 */
754 __u32 cp_blkaddr; /* start block address of checkpoint */
755 __u32 sit_blkaddr; /* start block address of SIT */
756 __u32 nat_blkaddr; /* start block address of NAT */
757 __u32 ssa_blkaddr; /* start block address of SSA */
758 __u32 main_blkaddr; /* start block address of main area */
759 __u32 root_ino; /* root inode number */
760 __u32 node_ino; /* node inode number */
761 __u32 meta_ino; /* meta inode number */
762 __u8 uuid[16]; /* 128-bit uuid for volume */
763 __u16 volume_name[512]; /* volume name */
764 __u32 extension_count; /* # of extensions below */
765 __u8 extension_list[F2FS_MAX_EXTENSION][8]; /* extension array */
766 } __attribute__((__packed__));
768 struct exfat_super_block {
771 uint8_t __unused1[53];
772 uint64_t block_start;
773 uint64_t block_count;
774 uint32_t fat_block_start;
775 uint32_t fat_block_count;
776 uint32_t cluster_block_start;
777 uint32_t cluster_count;
778 uint32_t rootdir_cluster;
779 uint8_t volume_serial[4];
784 uint16_t volume_state;
789 uint8_t allocated_percent;
790 } __attribute__((__packed__));
792 struct exfat_entry_label {
796 } __attribute__((__packed__));
798 #define BLOCK_SIZE(sb) (1 << (sb)->block_bits)
799 #define CLUSTER_SIZE(sb) (BLOCK_SIZE(sb) << (sb)->bpc_bits)
801 #define EXFAT_FIRST_DATA_CLUSTER 2
802 #define EXFAT_LAST_DATA_CLUSTER 0xffffff6
803 #define EXFAT_ENTRY_SIZE 32
805 #define EXFAT_ENTRY_EOD 0x00
806 #define EXFAT_ENTRY_LABEL 0x83
809 * Byte swap functions
812 #define _INLINE_ static __inline__
813 #else /* For Watcom C */
814 #define _INLINE_ static inline
817 _INLINE_ __u16 blkid_swab16(__u16 val)
819 return (val >> 8) | (val << 8);
822 _INLINE_ __u32 blkid_swab32(__u32 val)
824 return ((val>>24) | ((val>>8)&0xFF00) |
825 ((val<<8)&0xFF0000) | (val<<24));
828 _INLINE_ __u64 blkid_swab64(__u64 val)
830 return (blkid_swab32(val >> 32) |
831 (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
834 #ifdef WORDS_BIGENDIAN
835 #define blkid_le16(x) blkid_swab16(x)
836 #define blkid_le32(x) blkid_swab32(x)
837 #define blkid_le64(x) blkid_swab64(x)
838 #define blkid_be16(x) (x)
839 #define blkid_be32(x) (x)
840 #define blkid_be64(x) (x)
842 #define blkid_le16(x) (x)
843 #define blkid_le32(x) (x)
844 #define blkid_le64(x) (x)
845 #define blkid_be16(x) blkid_swab16(x)
846 #define blkid_be32(x) blkid_swab32(x)
847 #define blkid_be64(x) blkid_swab64(x)
852 #endif /* _BLKID_PROBE_H */