Skip to contentSkip to conversation

libdisk: recognize gfs/gfs2

PATCH In review Eric Sandeen 2 participants 2 messages Nov 1, 2008 – Nov 12, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libdisk: recognize gfs/gfs2

Recognize gfs & gfs2 disk formats.

---

xfsprogs/libdisk/fstype.c +17 -0
Index: xfs-cmds-build/xfsprogs/libdisk/fstype.c
===================================================================
@@ -68,6 +68,7 @@ swapped(unsigned short a) {
     Added jfs - Christoph Hellwig
     Added sysv - Tim Launchbury
     Added udf - Bryce Nesbitt
+    Added gfs/gfs2 - Eric Sandeen
 */
 
 /*
@@ -192,6 +193,7 @@ fstype(const char *device) {
     struct hpfs_super_block hpfssb;
     struct adfs_super_block adfssb;
     struct sysv_super_block svsb;
+    struct gfs2_sb gfs2sb;
     struct stat statbuf;
 
     /* opening and reading an arbitrary unknown path can have
@@ -382,6 +384,21 @@ fstype(const char *device) {
     }
 
     if (!type) {
+	/* block 64 */
+	if (lseek(fd, GFS_SUPERBLOCK_OFFSET, SEEK_SET) != GFS_SUPERBLOCK_OFFSET
+	    || read(fd, (char *) &gfs2sb, sizeof(gfs2sb)) != sizeof(gfs2sb))
+	    goto io_error;
+	if (gfsmagic(gfs2sb)) {
+		if (gfsformat(gfs2sb) == GFS_FORMAT_FS &&
+		    gfsmultiformat(gfs2sb) == GFS_FORMAT_MULTI)
+			type = "gfs";
+		else if (gfsformat(gfs2sb) == GFS2_FORMAT_FS &&
+			 gfsmultiformat(gfs2sb) == GFS2_FORMAT_MULTI)
+			type = "gfs2";
+	}
+    }
+
+    if (!type) {
 	    /* perhaps the user tries to mount the swap space
 	       on a new disk; warn her before she does mkfs on it */
 	    int pagesize = getpagesize();
xfsprogs/libdisk/fstype.h +55 -0

64 lines not on this page · raw message