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