probe.h revision d3f917989badf78d1f97654e46d60d1f3d25cd17
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 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
14#ifndef _BLKID_PROBE_H
15#define _BLKID_PROBE_H
16
17#include <blkid/blkid_types.h>
18
19struct blkid_magic;
20
21typedef int (*blkid_probe_t)(int fd, blkid_dev **dev_p, const char *devname,
22			     struct blkid_magic *id, unsigned char *buf,
23			     blkid_loff_t size);
24
25struct blkid_magic {
26	const char	*bim_type;	/* type name for this magic */
27	long		bim_kboff;	/* kilobyte offset of superblock */
28	unsigned	bim_sboff;	/* byte offset within superblock */
29	unsigned	bim_len;	/* length of magic */
30	const char	*bim_magic;	/* magic string */
31	unsigned	bim_align;	/* byte alignment of superblock */
32	unsigned	bim_kbsize;	/* size of superblock in kilobytes */
33	blkid_probe_t	bim_probe;	/* probe function */
34};
35
36/*
37 * Structures for each of the content types we want to extract information
38 * from.  We do not necessarily need the magic field here, because we have
39 * already identified the content type before we get this far.  It may still
40 * be useful if there are probe functions which handle multiple content types.
41 */
42struct ext2_super_block {
43	__u32		s_inodes_count;
44	__u32		s_blocks_count;
45	__u32		s_r_blocks_count;
46	__u32		s_free_blocks_count;
47	__u32		s_free_inodes_count;
48	__u32		s_first_data_block;
49	__u32		s_log_block_size;
50	__u32		s_dummy3[7];
51	unsigned char	s_magic[2];
52	__u16		s_state;
53	__u32		s_dummy5[8];
54	__u32		s_feature_compat;
55	__u32		s_feature_incompat;
56	__u32		s_feature_ro_compat;
57	unsigned char   s_uuid[16];
58	char	   s_volume_name[16];
59};
60#define EXT3_FEATURE_COMPAT_HAS_JOURNAL		0x00000004
61#define EXT3_FEATURE_INCOMPAT_RECOVER		0x00000004
62#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV	0x00000008
63
64struct xfs_super_block {
65	unsigned char	xs_magic[4];
66	__u32		xs_blocksize;
67	__u64		xs_dblocks;
68	__u64		xs_rblocks;
69	__u32		xs_dummy1[8];
70	unsigned char	xs_uuid[16];
71	__u32		xs_dummy2[15];
72	char		xs_fname[12];
73	__u32		xs_dummy3[2];
74	__u64		xs_icount;
75	__u64		xs_ifree;
76	__u64		xs_fdblocks;
77};
78
79struct reiserfs_super_block {
80	__u32		rs_blocks_count;
81	__u32		rs_free_blocks;
82	__u32		rs_root_block;
83	__u32		rs_journal_block;
84	__u32		rs_journal_dev;
85	__u32		rs_orig_journal_size;
86	__u32		rs_dummy2[5];
87	__u16		rs_blocksize;
88	__u16		rs_dummy3[3];
89	unsigned char	rs_magic[12];
90	__u32		rs_dummy4[5];
91	unsigned char	rs_uuid[16];
92	char		rs_label[16];
93};
94
95/* Yucky misaligned values */
96struct vfat_super_block {
97/* 00*/	unsigned char	vs_ignored[3];
98/* 03*/	unsigned char	vs_sysid[8];
99/* 0b*/	unsigned char	vs_sector_size[2];
100/* 0d*/	__u8		vs_cluster_size;
101/* 0e*/	__u16		vs_reserved;
102/* 10*/	__u8		vs_fats;
103/* 11*/	unsigned char	vs_dir_entries[2];
104/* 13*/	unsigned char	vs_sectors[2];
105/* 15*/	unsigned char	vs_media;
106/* 16*/	__u16		vs_fat_length;
107/* 18*/	__u16		vs_secs_track;
108/* 1a*/	__u16		vs_heads;
109/* 1c*/	__u32		vs_hidden;
110/* 20*/	__u32		vs_total_sect;
111/* 24*/	__u32		vs_fat32_length;
112/* 28*/	__u16		vs_flags;
113/* 2a*/	__u8		vs_version[2];
114/* 2c*/	__u32		vs_root_cluster;
115/* 30*/	__u16		vs_insfo_sector;
116/* 32*/	__u16		vs_backup_boot;
117/* 34*/	__u16		vs_reserved2[6];
118/* 40*/	unsigned char	vs_unknown[3];
119/* 43*/	unsigned char	vs_serno[4];
120/* 47*/	char		vs_label[11];
121/* 52*/	unsigned char   vs_magic[8];
122/* 5a*/	unsigned char	vs_dummy2[164];
123/*1fe*/	unsigned char	vs_pmagic[2];
124};
125
126/* Yucky misaligned values */
127struct msdos_super_block {
128/* 00*/	unsigned char	ms_ignored[3];
129/* 03*/	unsigned char	ms_sysid[8];
130/* 0b*/	unsigned char	ms_sector_size[2];
131/* 0d*/	__u8		ms_cluster_size;
132/* 0e*/	__u16		ms_reserved;
133/* 10*/	__u8		ms_fats;
134/* 11*/	unsigned char	ms_dir_entries[2];
135/* 13*/	unsigned char	ms_sectors[2];
136/* 15*/	unsigned char	ms_media;
137/* 16*/	__u16		ms_fat_length;
138/* 18*/	__u16		ms_secs_track;
139/* 1a*/	__u16		ms_heads;
140/* 1c*/	__u32		ms_hidden;
141/* 20*/	__u32		ms_total_sect;
142/* 24*/	unsigned char	ms_unknown[3];
143/* 27*/	unsigned char	ms_serno[4];
144/* 2b*/	char		ms_label[11];
145/* 36*/	unsigned char   ms_magic[8];
146/* 3d*/	unsigned char	ms_dummy2[192];
147/*1fe*/	unsigned char	ms_pmagic[2];
148};
149
150struct minix_super_block {
151	__u16		ms_ninodes;
152	__u16		ms_nzones;
153	__u16		ms_imap_blocks;
154	__u16		ms_zmap_blocks;
155	__u16		ms_firstdatazone;
156	__u16		ms_log_zone_size;
157	__u32		ms_max_size;
158	unsigned char	ms_magic[2];
159	__u16		ms_state;
160	__u32		ms_zones;
161};
162
163struct swap_header {
164	char		sh_bootbits[1024];
165	unsigned int	sh_version;
166	unsigned int	sh_last_page;
167	unsigned int	sh_nr_badpages;
168	char		sh_label[16];
169};
170
171struct mdp_superblock_s {
172	__u32 md_magic;
173	__u32 major_version;
174	__u32 minor_version;
175	__u32 patch_version;
176	__u32 gvalid_words;
177	__u32 set_uuid0;
178	__u32 ctime;
179	__u32 level;
180	__u32 size;
181	__u32 nr_disks;
182	__u32 raid_disks;
183	__u32 md_minor;
184	__u32 not_persistent;
185	__u32 set_uuid1;
186	__u32 set_uuid2;
187	__u32 set_uuid3;
188};
189
190struct hfs_super_block {
191	char	h_magic[2];
192	char	h_dummy[18];
193	__u32	h_blksize;
194};
195
196#ifndef le32_to_cpu	/* Assume if one is defined, all are defined */
197#define X16_to_cpu(x) ((__u16)((((__u16)(x) & 0x00ffU) << 8) | \
198			       (((__u16)(x) & 0xff00U) >> 8)))
199#define X32_to_cpu(x) ((__u32)((((__u32)(x) & 0x000000ffU) << 24) | \
200			       (((__u32)(x) & 0x0000ff00U) << 8) | \
201			       (((__u32)(x) & 0x00ff0000U) >> 8) | \
202			       (((__u32)(x) & 0xff000000U) >> 24)))
203#define X64_to_cpu(x) ((__u64)((((__u64)(x) & 0x00000000000000ffULL) << 56) | \
204			       (((__u64)(x) & 0x000000000000ff00ULL) << 40) | \
205			       (((__u64)(x) & 0x0000000000ff0000ULL) << 24) | \
206			       (((__u64)(x) & 0x00000000ff000000ULL) <<  8) | \
207			       (((__u64)(x) & 0x000000ff00000000ULL) >>  8) | \
208			       (((__u64)(x) & 0x0000ff0000000000ULL) >> 24) | \
209			       (((__u64)(x) & 0x00ff000000000000ULL) >> 40) | \
210			       (((__u64)(x) & 0xff00000000000000ULL) >> 56)))
211#if  __BYTE_ORDER == __BIG_ENDIAN
212#define le16_to_cpu(x) X16_to_cpu(x)
213#define le32_to_cpu(x) X32_to_cpu(x)
214#define le64_to_cpu(x) X64_to_cpu(x)
215#define be16_to_cpu(x) (x)
216#define be32_to_cpu(x) (x)
217#define be64_to_cpu(x) (x)
218#else
219#define le16_to_cpu(x) (x)
220#define le32_to_cpu(x) (x)
221#define le64_to_cpu(x) (x)
222#define be16_to_cpu(x) X16_to_cpu(x)
223#define be32_to_cpu(x) X32_to_cpu(x)
224#define be64_to_cpu(x) X64_to_cpu(x)
225#endif
226#endif
227
228#endif /* _BLKID_PROBE_H */
229