All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: xfs mailing list <xfs@oss.sgi.com>
Cc: "MASON,CHRISTOPHER" <CHRIS.MASON@oracle.com>
Subject: [PATCH] xfsprogs: add btrfs detection to libdisk
Date: Thu, 08 Jan 2009 12:13:23 -0600	[thread overview]
Message-ID: <49664243.1090405@redhat.com> (raw)

Now that the btrfs disk format has stabilized, libdisk can
recognize it and mkfs.xfs will not overwrite it w/o "-f" :

# mkfs.btrfs -l 16384 -L mylabel -n 8192 -s 4096 /tmp/fsfile 
fs created label mylabel on /tmp/fsfile
        nodesize 8192 leafsize 16384 sectorsize 4096 size 1.28GB
Btrfs v0.16-37-gb8271dc
# mkfs.xfs /tmp/fsfile 
mkfs.xfs: /tmp/fsfile appears to contain an existing filesystem (btrfs).
mkfs.xfs: Use the -f option to force overwrite.

This'll fix up xfsqa failures when mkfs.btrfs is found, too.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
---

diff --git a/libdisk/fstype.c b/libdisk/fstype.c
index 775b74b..f84b4e4 100644
--- a/libdisk/fstype.c
+++ b/libdisk/fstype.c
@@ -68,7 +68,7 @@ swapped(unsigned short a) {
     Added jfs - Christoph Hellwig
     Added sysv - Tim Launchbury
     Added udf - Bryce Nesbitt
-    Added gfs/gfs2 - Eric Sandeen
+    Added gfs/gfs2, btrfs - Eric Sandeen
 */
 
 /*
@@ -194,6 +194,7 @@ fstype(const char *device) {
     struct adfs_super_block adfssb;
     struct sysv_super_block svsb;
     struct gfs2_sb gfs2sb;
+    struct btrfs_super_block btrfssb;
     struct stat statbuf;
 
     /* opening and reading an arbitrary unknown path can have
@@ -399,6 +400,17 @@ fstype(const char *device) {
     }
 
     if (!type) {
+	/* block 64 */
+	if (lseek(fd, BTRFS_SUPER_INFO_OFFSET, SEEK_SET) != BTRFS_SUPER_INFO_OFFSET 
+	    || read(fd, (char *) &btrfssb, sizeof(btrfssb)) != sizeof(btrfssb))
+	    goto io_error;
+	if (!strncmp((char *)(btrfssb.magic), BTRFS_MAGIC,
+                    sizeof(btrfssb.magic))) {
+		type = "btrfs";
+	}
+    }
+
+    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();
diff --git a/libdisk/fstype.h b/libdisk/fstype.h
index cd3eec9..ca97434 100644
--- a/libdisk/fstype.h
+++ b/libdisk/fstype.h
@@ -292,6 +292,32 @@ struct gfs2_sb {
 #define gfsformat(s)		assemble4be(s.sb_fs_format)
 #define gfsmultiformat(s)	assemble4be(s.sb_multihost_format)
 
+/* btrfs constants */
+#define BTRFS_SUPER_INFO_OFFSET (64 * 1024)
+
+/* 32 bytes in various csum fields */
+#define BTRFS_CSUM_SIZE 32
+
+#define BTRFS_FSID_SIZE 16
+
+#define BTRFS_MAGIC "_BHRfS_M"
+
+/*
+ * the super block basically lists the main trees of the FS
+ * it currently lacks any block count etc etc
+ */
+struct btrfs_super_block {
+	char csum[BTRFS_CSUM_SIZE];
+	/* the first 3 fields must match struct btrfs_header */
+	char fsid[BTRFS_FSID_SIZE];    /* FS specific uuid */
+	char bytenr[8]; /* this block number */
+	char flags[8];
+
+	/* allowed to be different from the btrfs_header from here own down */
+	char magic[8];
+	/* more follows but this is all our libdisk cares about*/
+} __attribute__ ((__packed__));
+
 static inline int
 assemble2le(char *p) {
 	return (p[0] | (p[1] << 8));

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

             reply	other threads:[~2009-01-08 19:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-08 18:13 Eric Sandeen [this message]
2009-01-08 19:12 ` [PATCH] xfsprogs: add btrfs detection to libdisk 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=49664243.1090405@redhat.com \
    --to=sandeen@redhat.com \
    --cc=CHRIS.MASON@oracle.com \
    --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.