probe.h 8.7 KB

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