Blame SOURCES/parted-3.1-libparted-Recognize-btrfs-filesystem.patch

9cc286
From 242217de0268d6036a6e6a3f196abd79bfcb98b8 Mon Sep 17 00:00:00 2001
9cc286
From: "Brian C. Lane" <bcl@redhat.com>
9cc286
Date: Tue, 27 Aug 2013 17:27:07 -0700
9cc286
Subject: [PATCH 1/2] libparted: Recognize btrfs filesystem
9cc286
9cc286
Add support for showing 'btrfs' in  the 'file system' column. Also
9cc286
allows the used to enter btrfs as the fs type. It doesn't really do
9cc286
anything -- just sets the partition type to linux.
9cc286
9cc286
* NEWS (Changes in behavior): Mention it.
9cc286
* doc/parted.texti: Document btrfs fs.
9cc286
* (libparted/fs/Makefile.am): Add btrfs.c
9cc286
* (libparted/fs/btrfs/btrfs.c): Probe for btrfs
9cc286
* (libparted/libparted.c): Register btrfs
9cc286
---
9cc286
 NEWS                       |  3 ++
9cc286
 doc/parted.texi            |  1 +
9cc286
 libparted/fs/Makefile.am   |  1 +
9cc286
 libparted/fs/btrfs/btrfs.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++
9cc286
 libparted/libparted.c      |  4 +++
9cc286
 5 files changed, 87 insertions(+)
9cc286
 create mode 100644 libparted/fs/btrfs/btrfs.c
9cc286
9cc286
diff --git a/NEWS b/NEWS
9cc286
index 596ab37..e2d01ed 100644
9cc286
--- a/NEWS
9cc286
+++ b/NEWS
9cc286
@@ -84,6 +84,9 @@ GNU parted NEWS                                    -*- outline -*-
9cc286
 
9cc286
 ** Changes in behavior
9cc286
 
9cc286
+  Added support for recognizing btrfs filesystem. This simply displays
9cc286
+  btrfs in the 'file system' column of the parted output.
9cc286
+
9cc286
   Floppy drives are no longer scanned on linux: they cannot be partitioned
9cc286
   anyhow, and some users have a misconfigured BIOS that claims to have a
9cc286
   floppy when they don't, and scanning gets hung up.
9cc286
diff --git a/doc/parted.texi b/doc/parted.texi
9cc286
index 6561d0e..2b1ce64 100644
9cc286
--- a/doc/parted.texi
9cc286
+++ b/doc/parted.texi
9cc286
@@ -575,6 +575,7 @@ partition table.
9cc286
 @item NTFS
9cc286
 @item reiserfs
9cc286
 @item ufs
9cc286
+@item btrfs
9cc286
 @end itemize
9cc286
 
9cc286
 Example:
9cc286
diff --git a/libparted/fs/Makefile.am b/libparted/fs/Makefile.am
9cc286
index 8d48ea1..a8fb313 100644
9cc286
--- a/libparted/fs/Makefile.am
9cc286
+++ b/libparted/fs/Makefile.am
9cc286
@@ -25,6 +25,7 @@ libfs_la_SOURCES =		\
9cc286
   amiga/asfs.c			\
9cc286
   amiga/asfs.h			\
9cc286
   amiga/a-interface.c		\
9cc286
+  btrfs/btrfs.c			\
9cc286
   ext2/ext2.h			\
9cc286
   ext2/ext2_fs.h		\
9cc286
   ext2/interface.c		\
9cc286
diff --git a/libparted/fs/btrfs/btrfs.c b/libparted/fs/btrfs/btrfs.c
9cc286
new file mode 100644
9cc286
index 0000000..e5abed6
9cc286
--- /dev/null
9cc286
+++ b/libparted/fs/btrfs/btrfs.c
9cc286
@@ -0,0 +1,78 @@
9cc286
+/*
9cc286
+    libparted - a library for manipulating disk partitions
9cc286
+    Copyright (C) 2013 Free Software Foundation, Inc.
9cc286
+
9cc286
+    This program is free software; you can redistribute it and/or modify
9cc286
+    it under the terms of the GNU General Public License as published by
9cc286
+    the Free Software Foundation; either version 3 of the License, or
9cc286
+    (at your option) any later version.
9cc286
+
9cc286
+    This program is distributed in the hope that it will be useful,
9cc286
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
9cc286
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9cc286
+    GNU General Public License for more details.
9cc286
+
9cc286
+    You should have received a copy of the GNU General Public License
9cc286
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
9cc286
+*/
9cc286
+
9cc286
+#include <config.h>
9cc286
+
9cc286
+#include <parted/parted.h>
9cc286
+#include <parted/endian.h>
9cc286
+
9cc286
+/* Located 64k inside the partition (start of the first btrfs superblock) */
9cc286
+#define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
9cc286
+#define BTRFS_CSUM_SIZE 32
9cc286
+#define BTRFS_FSID_SIZE 16
9cc286
+
9cc286
+
9cc286
+static PedGeometry*
9cc286
+btrfs_probe (PedGeometry* geom)
9cc286
+{
9cc286
+        union {
9cc286
+            struct {
9cc286
+                /* Just enough of the btrfs_super_block to get the magic */
9cc286
+                uint8_t csum[BTRFS_CSUM_SIZE];
9cc286
+                uint8_t fsid[BTRFS_FSID_SIZE];
9cc286
+                uint64_t bytenr;
9cc286
+                uint64_t flags;
9cc286
+                uint64_t magic;
9cc286
+            } sb;
9cc286
+            int8_t      sector[8192];
9cc286
+        } buf;
9cc286
+        PedSector offset = (64*1024)/geom->dev->sector_size;
9cc286
+
9cc286
+        if (geom->length < offset+1)
9cc286
+                return 0;
9cc286
+        if (!ped_geometry_read (geom, &buf, offset, 1))
9cc286
+                return 0;
9cc286
+
9cc286
+        if (PED_LE64_TO_CPU(buf.sb.magic) == BTRFS_MAGIC) {
9cc286
+                return ped_geometry_new (geom->dev, geom->start, geom->length);
9cc286
+        }
9cc286
+        return NULL;
9cc286
+}
9cc286
+
9cc286
+static PedFileSystemOps btrfs_ops = {
9cc286
+        probe:          btrfs_probe,
9cc286
+};
9cc286
+
9cc286
+static PedFileSystemType btrfs_type = {
9cc286
+        next:   NULL,
9cc286
+        ops:    &btrfs_ops,
9cc286
+        name:   "btrfs",
9cc286
+        block_sizes: ((int[2]){512, 0})
9cc286
+};
9cc286
+
9cc286
+void
9cc286
+ped_file_system_btrfs_init ()
9cc286
+{
9cc286
+        ped_file_system_type_register (&btrfs_type);
9cc286
+}
9cc286
+
9cc286
+void
9cc286
+ped_file_system_btrfs_done ()
9cc286
+{
9cc286
+        ped_file_system_type_unregister (&btrfs_type);
9cc286
+}
9cc286
diff --git a/libparted/libparted.c b/libparted/libparted.c
9cc286
index a6d86f0..3c3b337 100644
9cc286
--- a/libparted/libparted.c
9cc286
+++ b/libparted/libparted.c
9cc286
@@ -109,6 +109,7 @@ extern void ped_file_system_hfs_init (void);
9cc286
 extern void ped_file_system_fat_init (void);
9cc286
 extern void ped_file_system_ext2_init (void);
9cc286
 extern void ped_file_system_nilfs2_init (void);
9cc286
+extern void ped_file_system_btrfs_init (void);
9cc286
 
9cc286
 static void
9cc286
 init_file_system_types ()
9cc286
@@ -124,6 +125,7 @@ init_file_system_types ()
9cc286
 	ped_file_system_fat_init ();
9cc286
 	ped_file_system_ext2_init ();
9cc286
 	ped_file_system_nilfs2_init ();
9cc286
+	ped_file_system_btrfs_init ();
9cc286
 }
9cc286
 
9cc286
 extern void ped_disk_aix_done ();
9cc286
@@ -186,6 +188,7 @@ extern void ped_file_system_reiserfs_done (void);
9cc286
 extern void ped_file_system_ufs_done (void);
9cc286
 extern void ped_file_system_xfs_done (void);
9cc286
 extern void ped_file_system_amiga_done (void);
9cc286
+extern void ped_file_system_btrfs_done (void);
9cc286
 
9cc286
 static void
9cc286
 done_file_system_types ()
9cc286
@@ -201,6 +204,7 @@ done_file_system_types ()
9cc286
 	ped_file_system_ufs_done ();
9cc286
 	ped_file_system_xfs_done ();
9cc286
 	ped_file_system_amiga_done ();
9cc286
+	ped_file_system_btrfs_done ();
9cc286
 }
9cc286
 
9cc286
 static void _done() __attribute__ ((destructor));
9cc286
-- 
9cc286
1.8.3.1
9cc286