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