Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 1 | /* |
| 2 | * probe.h - constants and on-disk structures for extracting device data |
| 3 | * |
| 4 | * Copyright (C) 1999 by Andries Brouwer |
Theodore Ts'o | 50b380b | 2003-02-12 23:51:21 -0500 | [diff] [blame] | 5 | * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 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 | |
Theodore Ts'o | 50b380b | 2003-02-12 23:51:21 -0500 | [diff] [blame] | 21 | typedef int (*blkid_probe_t)(int fd, blkid_cache cache, blkid_dev dev, |
Theodore Ts'o | 79dd234 | 2003-02-22 17:15:20 -0500 | [diff] [blame] | 22 | struct blkid_magic *id, unsigned char *buf); |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 23 | |
| 24 | struct blkid_magic { |
| 25 | const char *bim_type; /* type name for this magic */ |
| 26 | long bim_kboff; /* kilobyte offset of superblock */ |
| 27 | unsigned bim_sboff; /* byte offset within superblock */ |
| 28 | unsigned bim_len; /* length of magic */ |
Theodore Ts'o | d3f9179 | 2003-01-25 00:26:48 -0500 | [diff] [blame] | 29 | const char *bim_magic; /* magic string */ |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 30 | blkid_probe_t bim_probe; /* probe function */ |
| 31 | }; |
| 32 | |
| 33 | /* |
| 34 | * Structures for each of the content types we want to extract information |
| 35 | * from. We do not necessarily need the magic field here, because we have |
| 36 | * already identified the content type before we get this far. It may still |
| 37 | * be useful if there are probe functions which handle multiple content types. |
| 38 | */ |
| 39 | struct ext2_super_block { |
| 40 | __u32 s_inodes_count; |
| 41 | __u32 s_blocks_count; |
| 42 | __u32 s_r_blocks_count; |
| 43 | __u32 s_free_blocks_count; |
| 44 | __u32 s_free_inodes_count; |
| 45 | __u32 s_first_data_block; |
| 46 | __u32 s_log_block_size; |
| 47 | __u32 s_dummy3[7]; |
| 48 | unsigned char s_magic[2]; |
| 49 | __u16 s_state; |
| 50 | __u32 s_dummy5[8]; |
| 51 | __u32 s_feature_compat; |
| 52 | __u32 s_feature_incompat; |
| 53 | __u32 s_feature_ro_compat; |
| 54 | unsigned char s_uuid[16]; |
Theodore Ts'o | d3f9179 | 2003-01-25 00:26:48 -0500 | [diff] [blame] | 55 | char s_volume_name[16]; |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 56 | }; |
| 57 | #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x00000004 |
| 58 | #define EXT3_FEATURE_INCOMPAT_RECOVER 0x00000004 |
| 59 | #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x00000008 |
| 60 | |
| 61 | struct xfs_super_block { |
| 62 | unsigned char xs_magic[4]; |
| 63 | __u32 xs_blocksize; |
| 64 | __u64 xs_dblocks; |
| 65 | __u64 xs_rblocks; |
Theodore Ts'o | 09a2ef8 | 2003-04-03 00:04:28 -0500 | [diff] [blame^] | 66 | __u32 xs_dummy1[2]; |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 67 | unsigned char xs_uuid[16]; |
| 68 | __u32 xs_dummy2[15]; |
Theodore Ts'o | d3f9179 | 2003-01-25 00:26:48 -0500 | [diff] [blame] | 69 | char xs_fname[12]; |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 70 | __u32 xs_dummy3[2]; |
| 71 | __u64 xs_icount; |
| 72 | __u64 xs_ifree; |
| 73 | __u64 xs_fdblocks; |
| 74 | }; |
| 75 | |
| 76 | struct reiserfs_super_block { |
| 77 | __u32 rs_blocks_count; |
| 78 | __u32 rs_free_blocks; |
| 79 | __u32 rs_root_block; |
| 80 | __u32 rs_journal_block; |
| 81 | __u32 rs_journal_dev; |
| 82 | __u32 rs_orig_journal_size; |
| 83 | __u32 rs_dummy2[5]; |
| 84 | __u16 rs_blocksize; |
| 85 | __u16 rs_dummy3[3]; |
| 86 | unsigned char rs_magic[12]; |
| 87 | __u32 rs_dummy4[5]; |
| 88 | unsigned char rs_uuid[16]; |
Theodore Ts'o | d3f9179 | 2003-01-25 00:26:48 -0500 | [diff] [blame] | 89 | char rs_label[16]; |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 90 | }; |
| 91 | |
Theodore Ts'o | 09a2ef8 | 2003-04-03 00:04:28 -0500 | [diff] [blame^] | 92 | struct jfs_super_block { |
| 93 | unsigned char js_magic[4]; |
| 94 | __u32 js_version; |
| 95 | __u64 js_size; |
| 96 | __u32 js_bsize; |
| 97 | __u32 js_dummy1; |
| 98 | __u32 js_pbsize; |
| 99 | __u32 js_dummy2[27]; |
| 100 | unsigned char js_uuid[16]; |
| 101 | unsigned char js_label[16]; |
| 102 | unsigned char js_loguuid[16]; |
| 103 | }; |
| 104 | |
| 105 | struct romfs_super_block { |
| 106 | unsigned char ros_magic[8]; |
| 107 | __u32 ros_dummy1[2]; |
| 108 | unsigned char ros_volume[16]; |
| 109 | }; |
| 110 | |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 111 | /* Yucky misaligned values */ |
| 112 | struct vfat_super_block { |
| 113 | /* 00*/ unsigned char vs_ignored[3]; |
| 114 | /* 03*/ unsigned char vs_sysid[8]; |
| 115 | /* 0b*/ unsigned char vs_sector_size[2]; |
| 116 | /* 0d*/ __u8 vs_cluster_size; |
| 117 | /* 0e*/ __u16 vs_reserved; |
| 118 | /* 10*/ __u8 vs_fats; |
| 119 | /* 11*/ unsigned char vs_dir_entries[2]; |
| 120 | /* 13*/ unsigned char vs_sectors[2]; |
| 121 | /* 15*/ unsigned char vs_media; |
| 122 | /* 16*/ __u16 vs_fat_length; |
| 123 | /* 18*/ __u16 vs_secs_track; |
| 124 | /* 1a*/ __u16 vs_heads; |
| 125 | /* 1c*/ __u32 vs_hidden; |
| 126 | /* 20*/ __u32 vs_total_sect; |
| 127 | /* 24*/ __u32 vs_fat32_length; |
| 128 | /* 28*/ __u16 vs_flags; |
| 129 | /* 2a*/ __u8 vs_version[2]; |
| 130 | /* 2c*/ __u32 vs_root_cluster; |
| 131 | /* 30*/ __u16 vs_insfo_sector; |
| 132 | /* 32*/ __u16 vs_backup_boot; |
| 133 | /* 34*/ __u16 vs_reserved2[6]; |
| 134 | /* 40*/ unsigned char vs_unknown[3]; |
| 135 | /* 43*/ unsigned char vs_serno[4]; |
Theodore Ts'o | d3f9179 | 2003-01-25 00:26:48 -0500 | [diff] [blame] | 136 | /* 47*/ char vs_label[11]; |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 137 | /* 52*/ unsigned char vs_magic[8]; |
| 138 | /* 5a*/ unsigned char vs_dummy2[164]; |
| 139 | /*1fe*/ unsigned char vs_pmagic[2]; |
| 140 | }; |
| 141 | |
| 142 | /* Yucky misaligned values */ |
| 143 | struct msdos_super_block { |
| 144 | /* 00*/ unsigned char ms_ignored[3]; |
| 145 | /* 03*/ unsigned char ms_sysid[8]; |
| 146 | /* 0b*/ unsigned char ms_sector_size[2]; |
| 147 | /* 0d*/ __u8 ms_cluster_size; |
| 148 | /* 0e*/ __u16 ms_reserved; |
| 149 | /* 10*/ __u8 ms_fats; |
| 150 | /* 11*/ unsigned char ms_dir_entries[2]; |
| 151 | /* 13*/ unsigned char ms_sectors[2]; |
| 152 | /* 15*/ unsigned char ms_media; |
| 153 | /* 16*/ __u16 ms_fat_length; |
| 154 | /* 18*/ __u16 ms_secs_track; |
| 155 | /* 1a*/ __u16 ms_heads; |
| 156 | /* 1c*/ __u32 ms_hidden; |
| 157 | /* 20*/ __u32 ms_total_sect; |
| 158 | /* 24*/ unsigned char ms_unknown[3]; |
| 159 | /* 27*/ unsigned char ms_serno[4]; |
Theodore Ts'o | d3f9179 | 2003-01-25 00:26:48 -0500 | [diff] [blame] | 160 | /* 2b*/ char ms_label[11]; |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 161 | /* 36*/ unsigned char ms_magic[8]; |
| 162 | /* 3d*/ unsigned char ms_dummy2[192]; |
| 163 | /*1fe*/ unsigned char ms_pmagic[2]; |
| 164 | }; |
| 165 | |
| 166 | struct minix_super_block { |
| 167 | __u16 ms_ninodes; |
| 168 | __u16 ms_nzones; |
| 169 | __u16 ms_imap_blocks; |
| 170 | __u16 ms_zmap_blocks; |
| 171 | __u16 ms_firstdatazone; |
| 172 | __u16 ms_log_zone_size; |
| 173 | __u32 ms_max_size; |
| 174 | unsigned char ms_magic[2]; |
| 175 | __u16 ms_state; |
| 176 | __u32 ms_zones; |
| 177 | }; |
| 178 | |
| 179 | struct swap_header { |
| 180 | char sh_bootbits[1024]; |
| 181 | unsigned int sh_version; |
| 182 | unsigned int sh_last_page; |
| 183 | unsigned int sh_nr_badpages; |
| 184 | char sh_label[16]; |
| 185 | }; |
| 186 | |
| 187 | struct mdp_superblock_s { |
| 188 | __u32 md_magic; |
| 189 | __u32 major_version; |
| 190 | __u32 minor_version; |
| 191 | __u32 patch_version; |
| 192 | __u32 gvalid_words; |
| 193 | __u32 set_uuid0; |
| 194 | __u32 ctime; |
| 195 | __u32 level; |
| 196 | __u32 size; |
| 197 | __u32 nr_disks; |
| 198 | __u32 raid_disks; |
| 199 | __u32 md_minor; |
| 200 | __u32 not_persistent; |
| 201 | __u32 set_uuid1; |
| 202 | __u32 set_uuid2; |
| 203 | __u32 set_uuid3; |
| 204 | }; |
| 205 | |
| 206 | struct hfs_super_block { |
| 207 | char h_magic[2]; |
| 208 | char h_dummy[18]; |
| 209 | __u32 h_blksize; |
| 210 | }; |
| 211 | |
Theodore Ts'o | 76b07bb | 2003-01-27 01:09:24 -0500 | [diff] [blame] | 212 | /* |
| 213 | * Byte swap functions |
| 214 | */ |
| 215 | #ifdef __GNUC__ |
Theodore Ts'o | ed78c02 | 2003-03-06 11:09:18 -0500 | [diff] [blame] | 216 | #define _INLINE_ static __inline__ |
Theodore Ts'o | 76b07bb | 2003-01-27 01:09:24 -0500 | [diff] [blame] | 217 | #else /* For Watcom C */ |
Theodore Ts'o | ed78c02 | 2003-03-06 11:09:18 -0500 | [diff] [blame] | 218 | #define _INLINE_ static inline |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 219 | #endif |
Theodore Ts'o | 76b07bb | 2003-01-27 01:09:24 -0500 | [diff] [blame] | 220 | |
Theodore Ts'o | ed78c02 | 2003-03-06 11:09:18 -0500 | [diff] [blame] | 221 | static __u16 blkid_swab16(__u16 val); |
| 222 | static __u32 blkid_swab32(__u32 val); |
| 223 | static __u64 blkid_swab64(__u64 val); |
Theodore Ts'o | 50b380b | 2003-02-12 23:51:21 -0500 | [diff] [blame] | 224 | |
Theodore Ts'o | 76b07bb | 2003-01-27 01:09:24 -0500 | [diff] [blame] | 225 | #if ((defined __GNUC__) && \ |
| 226 | (defined(__i386__) || defined(__i486__) || defined(__i586__))) |
| 227 | |
| 228 | #define _BLKID_HAVE_ASM_BITOPS_ |
| 229 | |
| 230 | _INLINE_ __u32 blkid_swab32(__u32 val) |
| 231 | { |
| 232 | #ifdef EXT2FS_REQUIRE_486 |
| 233 | __asm__("bswap %0" : "=r" (val) : "0" (val)); |
| 234 | #else |
| 235 | __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */ |
| 236 | "rorl $16,%0\n\t" /* swap words */ |
| 237 | "xchgb %b0,%h0" /* swap higher bytes */ |
| 238 | :"=q" (val) |
| 239 | : "0" (val)); |
| 240 | #endif |
| 241 | return val; |
| 242 | } |
| 243 | |
| 244 | _INLINE_ __u16 blkid_swab16(__u16 val) |
| 245 | { |
| 246 | __asm__("xchgb %b0,%h0" /* swap bytes */ \ |
| 247 | : "=q" (val) \ |
| 248 | : "0" (val)); \ |
| 249 | return val; |
| 250 | } |
| 251 | |
| 252 | _INLINE_ __u64 blkid_swab64(__u64 val) |
| 253 | { |
| 254 | return (blkid_swab32(val >> 32) | |
| 255 | (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32)); |
| 256 | } |
| 257 | #endif |
| 258 | |
| 259 | #if !defined(_BLKID_HAVE_ASM_BITOPS_) |
| 260 | |
| 261 | _INLINE_ __u16 blkid_swab16(__u16 val) |
| 262 | { |
| 263 | return (val >> 8) | (val << 8); |
| 264 | } |
| 265 | |
| 266 | _INLINE_ __u32 blkid_swab32(__u32 val) |
| 267 | { |
| 268 | return ((val>>24) | ((val>>8)&0xFF00) | |
| 269 | ((val<<8)&0xFF0000) | (val<<24)); |
| 270 | } |
| 271 | |
Theodore Ts'o | ed78c02 | 2003-03-06 11:09:18 -0500 | [diff] [blame] | 272 | _INLINE_ __u64 blkid_swab64(__u64 val) |
Theodore Ts'o | 76b07bb | 2003-01-27 01:09:24 -0500 | [diff] [blame] | 273 | { |
| 274 | return (blkid_swab32(val >> 32) | |
| 275 | (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32)); |
| 276 | } |
| 277 | #endif |
| 278 | |
| 279 | |
| 280 | |
| 281 | #if __BYTE_ORDER == __BIG_ENDIAN |
| 282 | #define blkid_le16(x) blkid_swab16(x) |
| 283 | #define blkid_le32(x) blkid_swab32(x) |
| 284 | #define blkid_le64(x) blkid_swab64(x) |
| 285 | #define blkid_be16(x) (x) |
| 286 | #define blkid_be32(x) (x) |
| 287 | #define blkid_be64(x) (x) |
| 288 | #else |
| 289 | #define blkid_le16(x) (x) |
| 290 | #define blkid_le32(x) (x) |
| 291 | #define blkid_le64(x) (x) |
| 292 | #define blkid_be16(x) blkid_swab16(x) |
| 293 | #define blkid_be32(x) blkid_swab32(x) |
| 294 | #define blkid_be64(x) blkid_swab64(x) |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 295 | #endif |
| 296 | |
Theodore Ts'o | ed78c02 | 2003-03-06 11:09:18 -0500 | [diff] [blame] | 297 | #undef _INLINE_ |
| 298 | |
Theodore Ts'o | e12f2ae | 2003-01-23 16:45:16 -0500 | [diff] [blame] | 299 | #endif /* _BLKID_PROBE_H */ |