From: Eric Sandeen <sandeen@sandeen.net>
To: xfs-oss <xfs@oss.sgi.com>
Subject: [PATCH] libdisk: recognize gfs/gfs2
Date: Sat, 01 Nov 2008 14:06:04 -0500 [thread overview]
Message-ID: <490CA89C.6070709@sandeen.net> (raw)
Recognize gfs & gfs2 disk formats.
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
---
Index: xfs-cmds-build/xfsprogs/libdisk/fstype.c
===================================================================
--- xfs-cmds-build.orig/xfsprogs/libdisk/fstype.c
+++ 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();
Index: xfs-cmds-build/xfsprogs/libdisk/fstype.h
===================================================================
--- xfs-cmds-build.orig/xfsprogs/libdisk/fstype.h
+++ xfs-cmds-build/xfsprogs/libdisk/fstype.h
@@ -242,6 +242,56 @@ struct ocfs_volume_label {
#define ocfslabellen(o) assemble2le(o.label_len)
#define OCFS_MAGIC "OracleCFS"
+/* Common gfs/gfs2 constants: */
+#define GFS_MAGIC 0x01161970
+#define GFS_DEFAULT_BSIZE 4096
+#define GFS_SUPERBLOCK_OFFSET (0x10 * GFS_DEFAULT_BSIZE)
+#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 {
+ char mh_magic[4];
+ char mh_type[4];
+ char __pad0[8]; /* Was generation number in gfs1 */
+ char mh_format[4];
+ char __pad1[4]; /* Was incarnation number in gfs1 */
+};
+
+struct gfs2_inum {
+ char no_formal_ino[8];
+ char no_addr[8];
+};
+
+struct gfs2_sb {
+ struct gfs2_meta_header sb_header;
+
+ char sb_fs_format[4];
+ char sb_multihost_format[4];
+ char __pad0[4]; /* Was superblock flags in gfs1 */
+
+ char sb_bsize[4];
+ char sb_bsize_shift[4];
+ char __pad1[4]; /* 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 */
+};
+
+#define gfsmagic(s) assemble4be(s.sb_header.mh_magic)
+#define gfsformat(s) assemble4be(s.sb_fs_format)
+#define gfsmultiformat(s) assemble4be(s.sb_multihost_format)
+
static inline int
assemble2le(char *p) {
return (p[0] | (p[1] << 8));
@@ -251,3 +301,8 @@ static inline int
assemble4le(char *p) {
return (p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24));
}
+
+static inline int
+assemble4be(char *p) {
+ return (p[3] | (p[2] << 8) | (p[1] << 16) | (p[0] << 24));
+}
next reply other threads:[~2008-11-01 19:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-01 19:06 Eric Sandeen [this message]
2008-11-12 9:42 ` [PATCH] libdisk: recognize gfs/gfs2 Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=490CA89C.6070709@sandeen.net \
--to=sandeen@sandeen.net \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.