Whamcloud - gitweb
blkid: Fix MD 0.90 superblock detection on little endian systems
[tools/e2fsprogs.git] / lib / blkid / probe.h
index 8471fd6..88bf311 100644 (file)
@@ -2,7 +2,7 @@
  * probe.h - constants and on-disk structures for extracting device data
  *
  * Copyright (C) 1999 by Andries Brouwer
- * Copyright (C) 1999, 2000 by Theodore Ts'o
+ * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
  * Copyright (C) 2001 by Andreas Dilger
  *
  * %Begin-Header%
 
 struct blkid_magic;
 
-typedef int (*blkid_probe_t)(int fd, blkid_dev **dev_p, const char *devname,
-                            struct blkid_magic *id, unsigned char *buf,
-                            blkid_loff_t size);
+#define SB_BUFFER_SIZE         0x11000
+
+struct blkid_probe {
+       int                     fd;
+       blkid_cache             cache;
+       blkid_dev               dev;
+       unsigned char           *sbbuf;
+       size_t                  sb_valid;
+       unsigned char           *buf;
+       size_t                  buf_max;
+};
+
+typedef int (*blkid_probe_t)(struct blkid_probe *probe, 
+                            struct blkid_magic *id, unsigned char *buf);
 
 struct blkid_magic {
        const char      *bim_type;      /* type name for this magic */
@@ -28,8 +39,6 @@ struct blkid_magic {
        unsigned        bim_sboff;      /* byte offset within superblock */
        unsigned        bim_len;        /* length of magic */
        const char      *bim_magic;     /* magic string */
-       unsigned        bim_align;      /* byte alignment of superblock */
-       unsigned        bim_kbsize;     /* size of superblock in kilobytes */
        blkid_probe_t   bim_probe;      /* probe function */
 };
 
@@ -56,6 +65,24 @@ struct ext2_super_block {
        __u32           s_feature_ro_compat;
        unsigned char   s_uuid[16];
        char       s_volume_name[16];
+       char    s_last_mounted[64];
+       __u32   s_algorithm_usage_bitmap;
+       __u8    s_prealloc_blocks;
+       __u8    s_prealloc_dir_blocks;
+       __u16   s_reserved_gdt_blocks;
+       __u8    s_journal_uuid[16];
+       __u32   s_journal_inum;
+       __u32   s_journal_dev;
+       __u32   s_last_orphan;
+       __u32   s_hash_seed[4];
+       __u8    s_def_hash_version;
+       __u8    s_jnl_backup_type;
+       __u16   s_reserved_word_pad;
+       __u32   s_default_mount_opts;
+       __u32   s_first_meta_bg;
+       __u32   s_mkfs_time;
+       __u32   s_jnl_blocks[17];
+       __u32   s_reserved[172];
 };
 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL                0x00000004
 #define EXT3_FEATURE_INCOMPAT_RECOVER          0x00000004
@@ -66,7 +93,7 @@ struct xfs_super_block {
        __u32           xs_blocksize;
        __u64           xs_dblocks;
        __u64           xs_rblocks;
-       __u32           xs_dummy1[8];
+       __u32           xs_dummy1[2];
        unsigned char   xs_uuid[16];
        __u32           xs_dummy2[15];
        char            xs_fname[12];
@@ -92,6 +119,59 @@ struct reiserfs_super_block {
        char            rs_label[16];
 };
 
+struct reiser4_super_block {
+       unsigned char   rs4_magic[16];
+       __u16           rs4_dummy[2];
+       unsigned char   rs4_uuid[16];
+       unsigned char   rs4_label[16];
+       __u64           rs4_dummy2;
+};
+
+struct jfs_super_block {
+       unsigned char   js_magic[4];
+       __u32           js_version;
+       __u64           js_size;
+       __u32           js_bsize;
+       __u32           js_dummy1;
+       __u32           js_pbsize;
+       __u32           js_dummy2[27];
+       unsigned char   js_uuid[16];
+       unsigned char   js_label[16];
+       unsigned char   js_loguuid[16];
+};
+
+struct romfs_super_block {
+       unsigned char   ros_magic[8];
+       __u32           ros_dummy1[2];
+       unsigned char   ros_volume[16];
+};
+
+struct cramfs_super_block {
+       __u8            magic[4];
+       __u32           size;
+       __u32           flags;
+       __u32           future;
+       __u8            signature[16];
+       struct cramfs_info {
+               __u32           crc;
+               __u32           edition;
+               __u32           blocks;
+               __u32           files;
+       } info;
+       __u8            name[16];
+};
+
+struct swap_id_block {
+/*     unsigned char   sws_boot[1024]; */
+       __u32           sws_version;
+       __u32           sws_lastpage;
+       __u32           sws_nrbad;
+       unsigned char   sws_uuid[16];
+       char            sws_volume[16];
+       unsigned char   sws_pad[117];
+       __u32           sws_badpg;
+};
+
 /* Yucky misaligned values */
 struct vfat_super_block {
 /* 00*/        unsigned char   vs_ignored[3];
@@ -117,7 +197,7 @@ struct vfat_super_block {
 /* 34*/        __u16           vs_reserved2[6];
 /* 40*/        unsigned char   vs_unknown[3];
 /* 43*/        unsigned char   vs_serno[4];
-/* 47*/        char            vs_label[11];
+/* 47*/        unsigned char   vs_label[11];
 /* 52*/        unsigned char   vs_magic[8];
 /* 5a*/        unsigned char   vs_dummy2[164];
 /*1fe*/        unsigned char   vs_pmagic[2];
@@ -141,12 +221,31 @@ struct msdos_super_block {
 /* 20*/        __u32           ms_total_sect;
 /* 24*/        unsigned char   ms_unknown[3];
 /* 27*/        unsigned char   ms_serno[4];
-/* 2b*/        char            ms_label[11];
+/* 2b*/        unsigned char   ms_label[11];
 /* 36*/        unsigned char   ms_magic[8];
 /* 3d*/        unsigned char   ms_dummy2[192];
 /*1fe*/        unsigned char   ms_pmagic[2];
 };
 
+struct vfat_dir_entry {
+       __u8    name[11];
+       __u8    attr;
+       __u16   time_creat;
+       __u16   date_creat;
+       __u16   time_acc;
+       __u16   date_acc;
+       __u16   cluster_high;
+       __u16   time_write;
+       __u16   date_write;
+       __u16   cluster_low;
+       __u32   size;
+};
+
+/* maximum number of clusters */
+#define FAT12_MAX 0xFF4
+#define FAT16_MAX 0xFFF4
+#define FAT32_MAX 0x0FFFFFF6
+
 struct minix_super_block {
        __u16           ms_ninodes;
        __u16           ms_nzones;
@@ -160,14 +259,6 @@ struct minix_super_block {
        __u32           ms_zones;
 };
 
-struct swap_header {
-       char            sh_bootbits[1024];
-       unsigned int    sh_version;
-       unsigned int    sh_last_page;
-       unsigned int    sh_nr_badpages;
-       char            sh_label[16];
-};
-
 struct mdp_superblock_s {
        __u32 md_magic;
        __u32 major_version;
@@ -193,36 +284,200 @@ struct hfs_super_block {
        __u32   h_blksize;
 };
 
-#ifndef le32_to_cpu    /* Assume if one is defined, all are defined */
-#define X16_to_cpu(x) ((__u16)((((__u16)(x) & 0x00ffU) << 8) | \
-                              (((__u16)(x) & 0xff00U) >> 8)))
-#define X32_to_cpu(x) ((__u32)((((__u32)(x) & 0x000000ffU) << 24) | \
-                              (((__u32)(x) & 0x0000ff00U) << 8) | \
-                              (((__u32)(x) & 0x00ff0000U) >> 8) | \
-                              (((__u32)(x) & 0xff000000U) >> 24)))
-#define X64_to_cpu(x) ((__u64)((((__u64)(x) & 0x00000000000000ffULL) << 56) | \
-                              (((__u64)(x) & 0x000000000000ff00ULL) << 40) | \
-                              (((__u64)(x) & 0x0000000000ff0000ULL) << 24) | \
-                              (((__u64)(x) & 0x00000000ff000000ULL) <<  8) | \
-                              (((__u64)(x) & 0x000000ff00000000ULL) >>  8) | \
-                              (((__u64)(x) & 0x0000ff0000000000ULL) >> 24) | \
-                              (((__u64)(x) & 0x00ff000000000000ULL) >> 40) | \
-                              (((__u64)(x) & 0xff00000000000000ULL) >> 56)))
-#if  __BYTE_ORDER == __BIG_ENDIAN
-#define le16_to_cpu(x) X16_to_cpu(x)
-#define le32_to_cpu(x) X32_to_cpu(x)
-#define le64_to_cpu(x) X64_to_cpu(x)
-#define be16_to_cpu(x) (x)
-#define be32_to_cpu(x) (x)
-#define be64_to_cpu(x) (x)
+struct ocfs_volume_header {
+       unsigned char   minor_version[4];
+       unsigned char   major_version[4];
+       unsigned char   signature[128];
+       char            mount[128];
+       unsigned char   mount_len[2];
+};
+
+struct ocfs_volume_label {
+       unsigned char   disk_lock[48];
+       char            label[64];      
+       unsigned char   label_len[2];
+       unsigned char  vol_id[16];
+       unsigned char  vol_id_len[2];
+};
+
+#define ocfsmajor(o) ((__u32)o.major_version[0] \
+                   + (((__u32) o.major_version[1]) << 8) \
+                   + (((__u32) o.major_version[2]) << 16) \
+                   + (((__u32) o.major_version[3]) << 24))
+#define ocfslabellen(o)        ((__u32)o.label_len[0] + (((__u32) o.label_len[1]) << 8))
+#define ocfsmountlen(o)        ((__u32)o.mount_len[0] + (((__u32) o.mount_len[1])<<8))
+
+#define OCFS_MAGIC "OracleCFS"
+
+struct ocfs2_super_block {
+       unsigned char  signature[8];
+       unsigned char  s_dummy1[184];
+       unsigned char  s_dummy2[80];
+       char           s_label[64];
+       unsigned char  s_uuid[16];
+};
+
+#define OCFS2_MIN_BLOCKSIZE             512
+#define OCFS2_MAX_BLOCKSIZE             4096
+
+#define OCFS2_SUPER_BLOCK_BLKNO         2
+
+#define OCFS2_SUPER_BLOCK_SIGNATURE     "OCFSV2"
+
+struct oracle_asm_disk_label {
+       char dummy[32];
+       char dl_tag[8];
+       char dl_id[24];
+};
+
+#define ORACLE_ASM_DISK_LABEL_MARKED    "ORCLDISK"
+#define ORACLE_ASM_DISK_LABEL_OFFSET    32
+
+struct iso_volume_descriptor {
+       unsigned char   vd_type;
+       unsigned char   vd_id[5];
+       unsigned char   vd_version;
+       unsigned char   flags;
+       unsigned char   system_id[32];
+       unsigned char   volume_id[32];
+       unsigned char   unused[8];
+       unsigned char   space_size[8];
+       unsigned char   escape_sequences[8];
+};
+
+/* Common gfs/gfs2 constants: */
+#define GFS_MAGIC               0x01161970
+#define GFS_DEFAULT_BSIZE       4096
+#define GFS_SUPERBLOCK_OFFSET  (0x10 * GFS_DEFAULT_BSIZE)
+#define GFS_METATYPE_SB         1
+#define GFS_FORMAT_SB           100
+#define GFS_LOCKNAME_LEN        64
+
+/* gfs1 constants: */
+#define GFS_FORMAT_FS           1309
+#define GFS_FORMAT_MULTI        1401
+/* gfs2 constants: */
+#define GFS2_FORMAT_FS          1801
+#define GFS2_FORMAT_MULTI       1900
+
+struct gfs2_meta_header {
+       __u32 mh_magic;
+       __u32 mh_type;
+       __u64 __pad0;          /* Was generation number in gfs1 */
+       __u32 mh_format;
+       __u32 __pad1;          /* Was incarnation number in gfs1 */
+};
+
+struct gfs2_inum {
+       __u64 no_formal_ino;
+       __u64 no_addr;
+};
+
+struct gfs2_sb {
+       struct gfs2_meta_header sb_header;
+
+       __u32 sb_fs_format;
+       __u32 sb_multihost_format;
+       __u32  __pad0;  /* Was superblock flags in gfs1 */
+       
+       __u32 sb_bsize;
+       __u32 sb_bsize_shift;
+       __u32 __pad1;   /* Was journal segment size in gfs1 */
+       
+       struct gfs2_inum sb_master_dir; /* Was jindex dinode in gfs1 */
+       struct gfs2_inum __pad2; /* Was rindex dinode in gfs1 */
+       struct gfs2_inum sb_root_dir;
+       
+       char sb_lockproto[GFS_LOCKNAME_LEN];
+       char sb_locktable[GFS_LOCKNAME_LEN];
+       /* In gfs1, quota and license dinodes followed */
+};
+
+/*
+ * Byte swap functions
+ */
+#ifdef __GNUC__
+#define _INLINE_ static __inline__
+#else                          /* For Watcom C */
+#define _INLINE_ static inline
+#endif
+
+static __u16 blkid_swab16(__u16 val);
+static __u32 blkid_swab32(__u32 val);
+static __u64 blkid_swab64(__u64 val);
+
+#if ((defined __GNUC__) && \
+     (defined(__i386__) || defined(__i486__) || defined(__i586__)))
+
+#define _BLKID_HAVE_ASM_BITOPS_
+
+_INLINE_ __u32 blkid_swab32(__u32 val)
+{
+#ifdef EXT2FS_REQUIRE_486
+       __asm__("bswap %0" : "=r" (val) : "0" (val));
 #else
-#define le16_to_cpu(x) (x)
-#define le32_to_cpu(x) (x)
-#define le64_to_cpu(x) (x)
-#define be16_to_cpu(x) X16_to_cpu(x)
-#define be32_to_cpu(x) X32_to_cpu(x)
-#define be64_to_cpu(x) X64_to_cpu(x)
+       __asm__("xchgb %b0,%h0\n\t"     /* swap lower bytes     */
+               "rorl $16,%0\n\t"       /* swap words           */
+               "xchgb %b0,%h0"         /* swap higher bytes    */
+               :"=q" (val)
+               : "0" (val));
 #endif
+       return val;
+}
+
+_INLINE_ __u16 blkid_swab16(__u16 val)
+{
+       __asm__("xchgb %b0,%h0"         /* swap bytes           */ \
+               : "=q" (val) \
+               :  "0" (val)); \
+               return val;
+}
+
+_INLINE_ __u64 blkid_swab64(__u64 val)
+{
+       return (blkid_swab32(val >> 32) |
+               (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
+}
 #endif
 
+#if !defined(_BLKID_HAVE_ASM_BITOPS_)
+
+_INLINE_  __u16 blkid_swab16(__u16 val)
+{
+       return (val >> 8) | (val << 8);
+}
+
+_INLINE_ __u32 blkid_swab32(__u32 val)
+{
+       return ((val>>24) | ((val>>8)&0xFF00) |
+               ((val<<8)&0xFF0000) | (val<<24));
+}
+
+_INLINE_ __u64 blkid_swab64(__u64 val)
+{
+       return (blkid_swab32(val >> 32) |
+               (((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
+}
+#endif 
+
+
+
+#ifdef WORDS_BIGENDIAN
+#define blkid_le16(x) blkid_swab16(x)
+#define blkid_le32(x) blkid_swab32(x)
+#define blkid_le64(x) blkid_swab64(x)
+#define blkid_be16(x) (x)
+#define blkid_be32(x) (x)
+#define blkid_be64(x) (x)
+#else
+#define blkid_le16(x) (x)
+#define blkid_le32(x) (x)
+#define blkid_le64(x) (x)
+#define blkid_be16(x) blkid_swab16(x)
+#define blkid_be32(x) blkid_swab32(x)
+#define blkid_be64(x) blkid_swab64(x)
+#endif
+
+#undef _INLINE_
+
 #endif /* _BLKID_PROBE_H */