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
113 #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400
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
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
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
143 struct xfs_super_block {
144 unsigned char xs_magic[4];
149 unsigned char xs_uuid[16];
158 struct reiserfs_super_block {
159 __u32 rs_blocks_count;
160 __u32 rs_free_blocks;
162 __u32 rs_journal_block;
163 __u32 rs_journal_dev;
164 __u32 rs_orig_journal_size;
168 unsigned char rs_magic[12];
170 unsigned char rs_uuid[16];
174 struct reiser4_super_block {
175 unsigned char rs4_magic[16];
177 unsigned char rs4_uuid[16];
178 unsigned char rs4_label[16];
182 struct jfs_super_block {
183 unsigned char js_magic[4];
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 */
193 unsigned char js_uuid[16];
194 unsigned char js_label[16];
195 unsigned char js_loguuid[16];
198 struct romfs_super_block {
199 unsigned char ros_magic[8];
201 unsigned char ros_volume[16];
204 struct cramfs_super_block {
219 struct swap_id_block {
220 /* unsigned char sws_boot[1024]; */
224 unsigned char sws_uuid[16];
226 unsigned char sws_pad[117];
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];
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];
285 struct vfat_dir_entry {
299 /* maximum number of clusters */
300 #define FAT12_MAX 0xFF4
301 #define FAT16_MAX 0xFFF4
302 #define FAT32_MAX 0x0FFFFFF6
304 struct minix_super_block {
307 __u16 ms_imap_blocks;
308 __u16 ms_zmap_blocks;
309 __u16 ms_firstdatazone;
310 __u16 ms_log_zone_size;
312 unsigned char ms_magic[2];
317 struct mdp_superblock_s {
330 __u32 not_persistent;
336 struct hfs_super_block {
342 struct ocfs_volume_header {
343 unsigned char minor_version[4];
344 unsigned char major_version[4];
345 unsigned char signature[128];
347 unsigned char mount_len[2];
350 struct ocfs_volume_label {
351 unsigned char disk_lock[48];
353 unsigned char label_len[2];
354 unsigned char vol_id[16];
355 unsigned char vol_id_len[2];
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))
365 #define OCFS_MAGIC "OracleCFS"
367 struct ocfs2_super_block {
368 unsigned char signature[8];
369 unsigned char s_dummy1[184];
370 unsigned char s_dummy2[80];
372 unsigned char s_uuid[16];
375 #define OCFS2_MIN_BLOCKSIZE 512
376 #define OCFS2_MAX_BLOCKSIZE 4096
378 #define OCFS2_SUPER_BLOCK_BLKNO 2
380 #define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2"
382 struct oracle_asm_disk_label {
388 #define ORACLE_ASM_DISK_LABEL_MARKED "ORCLDISK"
389 #define ORACLE_ASM_DISK_LABEL_OFFSET 32
391 struct iso_volume_descriptor {
392 unsigned char vd_type;
393 unsigned char vd_id[5];
394 unsigned char vd_version;
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];
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
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
418 struct gfs2_meta_header {
421 __u64 __pad0; /* Was generation number in gfs1 */
423 __u32 __pad1; /* Was incarnation number in gfs1 */
432 struct gfs2_meta_header sb_header;
435 __u32 sb_multihost_format;
436 __u32 __pad0; /* Was superblock flags in gfs1 */
439 __u32 sb_bsize_shift;
440 __u32 __pad1; /* Was journal segment size in gfs1 */
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;
446 char sb_lockproto[GFS_LOCKNAME_LEN];
447 char sb_locktable[GFS_LOCKNAME_LEN];
448 /* In gfs1, quota and license dinodes followed */
451 struct ntfs_super_block {
454 __u8 bios_parameter_block[25];
456 __u64 number_of_sectors;
457 __u64 mft_cluster_location;
458 __u64 mft_mirror_cluster_location;
459 __s8 cluster_per_mft_record;
461 __s8 cluster_per_index_record;
467 struct master_file_table_record {
472 __u16 sequence_number;
477 __u32 bytes_allocated;
478 } __attribute__((__packed__));
480 struct file_attribute {
490 } __attribute__((__packed__));
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
499 struct hfs_finder_info {
507 } __attribute__((packed));
533 struct hfs_finder_info finder_info;
535 __u16 embed_startblock;
536 __u16 embed_blockcount;
537 } __attribute__((packed));
540 #define HFS_NODE_LEAF 0xff
541 #define HFSPLUS_POR_CNID 1
543 struct hfsplus_bnode_descriptor {
550 } __attribute__((packed));
552 struct hfsplus_bheader_record {
559 } __attribute__((packed));
561 struct hfsplus_catalog_key {
565 __u8 unicode[255 * 2];
566 } __attribute__((packed));
568 struct hfsplus_extent {
571 } __attribute__((packed));
573 #define HFSPLUS_EXTENT_COUNT 8
574 struct hfsplus_fork {
578 struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT];
579 } __attribute__((packed));
581 struct hfsplus_vol_header {
585 __u32 last_mount_vers;
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));
611 /* this is lvm's label_header & pv_header combined. */
613 #define LVM2_ID_LEN 32
615 struct lvm2_pv_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 */
623 __u8 pv_uuid[LVM2_ID_LEN];
624 } __attribute__ ((packed));
628 * this is a very generous portion of the super block, giving us
629 * room to translate 14 chunks with 3 stripes each.
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
637 struct btrfs_dev_item {
638 /* the internal btrfs device id */
641 /* size of the device */
647 /* optimal io alignment for this device */
650 /* optimal io width for this device */
653 /* minimal io size for this device */
656 /* type and info about this device */
659 /* expected generation for this device */
663 * starting byte of this partition on the device,
664 * to allowr for stripe alignment in the future
668 /* grouping information for allocation decisions */
671 /* seek speed 0-100 where 100 is fastest */
674 /* bandwidth 0-100 where 100 is fastest */
677 /* btrfs generated uuid for this device */
678 __u8 uuid[BTRFS_UUID_SIZE];
680 /* uuid of FS who owns this device */
681 __u8 fsid[BTRFS_UUID_SIZE];
682 } __attribute__ ((__packed__));
685 * the super block basically lists the main trees of the FS
686 * it currently lacks any block count etc etc
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 */
695 /* allowed to be different from the btrfs_header from here own down */
702 /* this will help find the new super based on the log root */
703 __u64 log_root_transid;
706 __u64 root_dir_objectid;
712 __u32 sys_chunk_array_size;
713 __u64 chunk_root_generation;
715 __u64 compat_ro_flags;
716 __u64 incompat_flags;
719 __u8 chunk_root_level;
721 struct btrfs_dev_item dev_item;
723 char label[BTRFS_LABEL_SIZE];
725 /* future expansion */
727 __u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
728 } __attribute__ ((__packed__));
731 * Byte swap functions
734 #define _INLINE_ static __inline__
735 #else /* For Watcom C */
736 #define _INLINE_ static inline
739 static __u16 blkid_swab16(__u16 val);
740 static __u32 blkid_swab32(__u32 val);
741 static __u64 blkid_swab64(__u64 val);
743 #if ((defined __GNUC__) && \
744 (defined(__i386__) || defined(__i486__) || defined(__i586__)))
746 #define _BLKID_HAVE_ASM_BITOPS_
748 _INLINE_ __u32 blkid_swab32(__u32 val)
750 #ifdef EXT2FS_REQUIRE_486
751 __asm__("bswap %0" : "=r" (val) : "0" (val));
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 */
762 _INLINE_ __u16 blkid_swab16(__u16 val)
764 __asm__("xchgb %b0,%h0" /* swap bytes */ \
770 _INLINE_ __u64 blkid_swab64(__u64 val)
772 return (blkid_swab32(val >> 32) |
773 (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
777 #if !defined(_BLKID_HAVE_ASM_BITOPS_)
779 _INLINE_ __u16 blkid_swab16(__u16 val)
781 return (val >> 8) | (val << 8);
784 _INLINE_ __u32 blkid_swab32(__u32 val)
786 return ((val>>24) | ((val>>8)&0xFF00) |
787 ((val<<8)&0xFF0000) | (val<<24));
790 _INLINE_ __u64 blkid_swab64(__u64 val)
792 return (blkid_swab32(val >> 32) |
793 (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
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)
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)
817 #endif /* _BLKID_PROBE_H */