3
0

probe.h 8.5 KB

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