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

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