[klibc] [PATCH] btrfs support
Benjamin Cama
benoar at free.fr
Sat Apr 3 11:33:22 PDT 2010
Hi,
As I use btrfs as root FS, I wanted fstype to be able to recognize it.
The following patch add support for this FS.
Regards,
benjamin
Signed-off-by: Benjamin Cama <benoar at free.fr>
---
diff --git a/usr/kinit/fstype/btrfs_fs.h b/usr/kinit/fstype/btrfs_fs.h
new file mode 100644
index 0000000..e1f933e
--- /dev/null
+++ b/usr/kinit/fstype/btrfs_fs.h
@@ -0,0 +1,51 @@
+#ifndef __BTRFS_FS_H
+#define __BTRFS_FS_H
+
+/* Extracted from fs/btrfs/ctree.h and shortened a bit */
+
+#define BTRFS_MAGIC "_BHRfS_M"
+
+#define BTRFS_CSUM_SIZE 32
+#define BTRFS_FSID_SIZE 16
+
+/*
+ * the super block basically lists the main trees of the FS
+ * it currently lacks any block count etc etc
+ */
+struct btrfs_super_block {
+ __u8 csum[BTRFS_CSUM_SIZE];
+ /* the first 4 fields must match struct btrfs_header */
+ __u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
+ __le64 bytenr; /* this block number */
+ __le64 flags;
+
+ /* allowed to be different from the btrfs_header from here own down */
+ __le64 magic;
+ __le64 generation;
+ __le64 root;
+ __le64 chunk_root;
+ __le64 log_root;
+
+ /* this will help find the new super based on the log root */
+ __le64 log_root_transid;
+ __le64 total_bytes;
+ __le64 bytes_used;
+ __le64 root_dir_objectid;
+ __le64 num_devices;
+ __le32 sectorsize;
+ __le32 nodesize;
+ __le32 leafsize;
+ __le32 stripesize;
+ __le32 sys_chunk_array_size;
+ __le64 chunk_root_generation;
+ __le64 compat_flags;
+ __le64 compat_ro_flags;
+ __le64 incompat_flags;
+ __le16 csum_type;
+ __u8 root_level;
+ __u8 chunk_root_level;
+ __u8 log_root_level;
+ /* truncated here for klibc */
+} __attribute__ ((__packed__));
+
+#endif /* __BTRFS_FS_H */
diff --git a/usr/kinit/fstype/fstype.c b/usr/kinit/fstype/fstype.c
index 69e0e30..c50bf01 100644
--- a/usr/kinit/fstype/fstype.c
+++ b/usr/kinit/fstype/fstype.c
@@ -36,6 +36,7 @@
#include "gfs2_fs.h"
#include "ocfs2_fs.h"
#include "nilfs_fs.h"
+#include "btrfs_fs.h"
/*
* Slightly cleaned up version of jfs_superblock to
@@ -461,6 +462,18 @@ static int nilfs2_image(const void *buf, unsigned long long *bytes)
return 0;
}
+static int btrfs_image(const void *buf, unsigned long long *bytes)
+{
+ const struct btrfs_super_block *sb =
+ (const struct btrfs_super_block *)buf;
+
+ if (!memcmp(&sb->magic, BTRFS_MAGIC, sizeof(BTRFS_MAGIC)-1)) {
+ *bytes = (unsigned long long)__le64_to_cpu(sb->total_bytes);
+ return 1;
+ }
+ return 0;
+}
+
struct imagetype {
off_t block;
const char name[12];
@@ -496,6 +509,7 @@ static struct imagetype images[] = {
{64, "reiserfs", reiserfs_image},
{64, "reiser4", reiser4_image},
{64, "gfs2", gfs2_image},
+ {64, "btrfs", btrfs_image},
{32, "jfs", jfs_image},
{32, "iso9660", iso_image},
{0, "luks", luks_image},
More information about the klibc
mailing list