From b5517ca6678d590b52f38ad701fbaf6c9716b73d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Sun, 17 Sep 2006 21:10:58 -0400 Subject: [PATCH] Add GFS/GFS2 support to the blkid library. Signed-off-by: Karel Zak --- lib/blkid/ChangeLog | 4 ++++ lib/blkid/probe.c | 46 +++++++++++++++++++++++++++++++++++++++++++ lib/blkid/probe.h | 48 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog index 7835a26f4..4f46942d9 100644 --- a/lib/blkid/ChangeLog +++ b/lib/blkid/ChangeLog @@ -1,3 +1,7 @@ +2006-09-17 Karel Zak + + * probe.c (probe_gfs, _gfs2), probe.h: Add support for GFS/GFS2 + 2006-09-12 Theodore Tso * devname.c (dm_probe_all): probe_one expects device names passed diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c index 33f15a94c..f06a5d0fe 100644 --- a/lib/blkid/probe.c +++ b/lib/blkid/probe.c @@ -648,6 +648,50 @@ static int probe_oracleasm(struct blkid_probe *probe, return 0; } +static int probe_gfs(struct blkid_probe *probe, + struct blkid_magic *id __BLKID_ATTR((unused)), + unsigned char *buf) +{ + struct gfs2_sb *sbd; + const char *label = 0; + + sbd = (struct gfs2_sb *)buf; + + if (blkid_be32(sbd->sb_fs_format) == GFS_FORMAT_FS && + blkid_be32(sbd->sb_multihost_format) == GFS_FORMAT_MULTI) + { + blkid_set_tag(probe->dev, "UUID", 0, 0); + + if (strlen(sbd->sb_locktable)) + label = sbd->sb_locktable; + blkid_set_tag(probe->dev, "LABEL", label, sizeof(sbd->sb_locktable)); + return 0; + } + return 1; +} + +static int probe_gfs2(struct blkid_probe *probe, + struct blkid_magic *id __BLKID_ATTR((unused)), + unsigned char *buf) +{ + struct gfs2_sb *sbd; + const char *label = 0; + + sbd = (struct gfs2_sb *)buf; + + if (blkid_be32(sbd->sb_fs_format) == GFS2_FORMAT_FS && + blkid_be32(sbd->sb_multihost_format) == GFS2_FORMAT_MULTI) + { + blkid_set_tag(probe->dev, "UUID", 0, 0); + + if (strlen(sbd->sb_locktable)) + label = sbd->sb_locktable; + blkid_set_tag(probe->dev, "LABEL", label, sizeof(sbd->sb_locktable)); + return 0; + } + return 1; +} + /* * BLKID_BLK_OFFS is at least as large as the highest bim_kboff defined * in the type_array table below + bim_kbalign. @@ -675,6 +719,8 @@ static struct blkid_magic type_array[] = { { "reiserfs", 64, 0x34, 8, "ReIsErFs", probe_reiserfs }, { "reiserfs", 8, 20, 8, "ReIsErFs", probe_reiserfs }, { "reiser4", 64, 0, 7, "ReIsEr4", probe_reiserfs4 }, + { "gfs2", 64, 0, 4, "\x01\x16\x19\x70", probe_gfs2 }, + { "gfs", 64, 0, 4, "\x01\x16\x19\x70", probe_gfs }, { "vfat", 0, 0x52, 5, "MSWIN", probe_fat }, { "vfat", 0, 0x52, 8, "FAT32 ", probe_fat }, { "vfat", 0, 0x36, 5, "MSDOS", probe_fat }, diff --git a/lib/blkid/probe.h b/lib/blkid/probe.h index 840e526e1..88bf3116c 100644 --- a/lib/blkid/probe.h +++ b/lib/blkid/probe.h @@ -345,6 +345,54 @@ struct iso_volume_descriptor { 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 */ -- 2.47.2