]> err.no Git - util-linux/commitdiff
blkid: add GFS and GFS2
authorKarel Zak <kzak@redhat.com>
Tue, 23 Sep 2008 13:22:55 +0000 (15:22 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Feb 2009 22:21:45 +0000 (23:21 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libs/blkid/src/probe.c
libs/blkid/src/probers/Makefile.am
libs/blkid/src/probers/gfs.c [new file with mode: 0644]
libs/blkid/src/probers/probers.h

index 06a49bf8a26a56e0d663412e19359df79bfa33d2..ebac6bbc2796e9215957279535a836299096c942 100644 (file)
@@ -55,6 +55,8 @@ static const struct blkid_idinfo *idinfos[] =
        &ext2_idinfo,
        &xfs_idinfo,
        &jfs_idinfo,
+       &gfs_idinfo,
+       &gfs2_idinfo,
        &jbd_idinfo
 };
 
index 1d36c26942753060e9cb49ed517d4441cacf9065..663700b0305e4a429df6a9b35eec7280a799c28f 100644 (file)
@@ -19,6 +19,7 @@ libprobers_a_SOURCES =        probers.h \
                        linux_raid.c \
                        jfs.c \
                        xfs.c \
-                       ext.c
+                       ext.c \
+                       gfs.c
 
 all-local: $(lib_LIBRARIES)
diff --git a/libs/blkid/src/probers/gfs.c b/libs/blkid/src/probers/gfs.c
new file mode 100644 (file)
index 0000000..44306dc
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 1999, 2001 by Andries Brouwer
+ * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
+ * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+#include <stdint.h>
+
+#include "blkidP.h"
+
+/* 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 {
+       uint32_t mh_magic;
+       uint32_t mh_type;
+       uint64_t __pad0;          /* Was generation number in gfs1 */
+       uint32_t mh_format;
+       uint32_t __pad1;          /* Was incarnation number in gfs1 */
+};
+
+struct gfs2_inum {
+       uint64_t no_formal_ino;
+       uint64_t no_addr;
+};
+
+struct gfs2_sb {
+       struct gfs2_meta_header sb_header;
+
+       uint32_t sb_fs_format;
+       uint32_t sb_multihost_format;
+       uint32_t  __pad0;  /* Was superblock flags in gfs1 */
+
+       uint32_t sb_bsize;
+       uint32_t sb_bsize_shift;
+       uint32_t __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 */
+};
+
+static int probe_gfs(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       struct gfs2_sb *sbd;
+
+       sbd = blkid_probe_get_sb(pr, mag, struct gfs2_sb);
+       if (!sbd)
+               return -1;
+
+       if (be32_to_cpu(sbd->sb_fs_format) == GFS_FORMAT_FS &&
+           be32_to_cpu(sbd->sb_multihost_format) == GFS_FORMAT_MULTI)
+       {
+               if (strlen(sbd->sb_locktable))
+                       blkid_probe_set_label(pr,
+                               (unsigned char *) sbd->sb_locktable,
+                               sizeof(sbd->sb_locktable));
+               return 0;
+       }
+       return -1;
+}
+
+static int probe_gfs2(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       struct gfs2_sb *sbd;
+
+       sbd = blkid_probe_get_sb(pr, mag, struct gfs2_sb);
+       if (!sbd)
+               return -1;
+
+       if (be32_to_cpu(sbd->sb_fs_format) == GFS2_FORMAT_FS &&
+           be32_to_cpu(sbd->sb_multihost_format) == GFS2_FORMAT_MULTI)
+       {
+               if (strlen(sbd->sb_locktable))
+                       blkid_probe_set_label(pr,
+                               (unsigned char *) sbd->sb_locktable,
+                               sizeof(sbd->sb_locktable));
+               return 0;
+       }
+       return -1;
+}
+
+const struct blkid_idinfo gfs_idinfo =
+{
+       .name           = "gfs",
+       .usage          = BLKID_USAGE_FILESYSTEM,
+       .probefunc      = probe_gfs,
+       .magics         =
+       {
+               { .magic = "\x01\x16\x19\x70", .len = 4, .kboff = 64 },
+               { NULL }
+       }
+};
+
+const struct blkid_idinfo gfs2_idinfo =
+{
+       .name           = "gfs2",
+       .usage          = BLKID_USAGE_FILESYSTEM,
+       .probefunc      = probe_gfs2,
+       .magics         =
+       {
+               { .magic = "\x01\x16\x19\x70", .len = 4, .kboff = 64 },
+               { NULL }
+       }
+};
+
index ba4bab7b0a055e7ec092e370f7c939693c0ee85f..1c8b5f21ac9ff0f08b46ce46541ba4f1a527ba95 100644 (file)
@@ -35,5 +35,7 @@ extern const struct blkid_idinfo ext2_idinfo;
 extern const struct blkid_idinfo jbd_idinfo;
 extern const struct blkid_idinfo jfs_idinfo;
 extern const struct blkid_idinfo xfs_idinfo;
+extern const struct blkid_idinfo gfs_idinfo;
+extern const struct blkid_idinfo gfs2_idinfo;
 
 #endif /* _BLKID_PROBE_H */