aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaximilian attems <max@stro.at>2010-03-28 01:42:36 +0100
committermaximilian attems <max@stro.at>2010-03-28 01:46:56 +0100
commit4237d17e660d14dfd09b88cedca944ed579bd019 (patch)
tree3b2102e127a7de82804ce3aa8afe0b39a5255031
parent6baedbeb8ee474040a32a2a859534abfeeb68f1a (diff)
downloadklibc-4237d17e660d14dfd09b88cedca944ed579bd019.tar.gz
[klibc] fstype: btrfs support
Butter on bread seems useless for good french cheese. Although there are many nice usage cases for butter. This fs seems to be fancy and lately lots of users were asking for support: mkfs.btrfs /dev/dualvg0/testb WARNING! - Btrfs Btrfs v0.19 IS EXPERIMENTAL WARNING! - see http://btrfs.wiki.kernel.org before using fs created label (null) on /dev/dualvg0/testb nodesize 4096 leafsize 4096 sectorsize 4096 size 920.00MB ~/src/klibc-latest$ ./usr/kinit/fstype/static/fstype /dev/mapper/dualvg0-testb FSTYPE=btrfs FSSIZE=964689920 Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/kinit/fstype/btrfs.h57
-rw-r--r--usr/kinit/fstype/fstype.c14
2 files changed, 71 insertions, 0 deletions
diff --git a/usr/kinit/fstype/btrfs.h b/usr/kinit/fstype/btrfs.h
new file mode 100644
index 0000000000000..459da1217aee1
--- /dev/null
+++ b/usr/kinit/fstype/btrfs.h
@@ -0,0 +1,57 @@
+#ifndef __BTRFS_H
+#define __BTRFS_H
+
+# define BTRFS_MAGIC "_BHRfS_M"
+# define BTRFS_MAGIC_L 8
+
+/*
+ * Structure of the super block
+ */
+struct btrfs_super_block {
+ uint8_t csum[32];
+ uint8_t fsid[16];
+ uint64_t bytenr;
+ uint64_t flags;
+ uint8_t magic[8];
+ uint64_t generation;
+ uint64_t root;
+ uint64_t chunk_root;
+ uint64_t log_root;
+ uint64_t log_root_transid;
+ uint64_t total_bytes;
+ uint64_t bytes_used;
+ uint64_t root_dir_objectid;
+ uint64_t num_devices;
+ uint32_t sectorsize;
+ uint32_t nodesize;
+ uint32_t leafsize;
+ uint32_t stripesize;
+ uint32_t sys_chunk_array_size;
+ uint64_t chunk_root_generation;
+ uint64_t compat_flags;
+ uint64_t compat_ro_flags;
+ uint64_t incompat_flags;
+ uint16_t csum_type;
+ uint8_t root_level;
+ uint8_t chunk_root_level;
+ uint8_t log_root_level;
+ struct btrfs_dev_item {
+ uint64_t devid;
+ uint64_t total_bytes;
+ uint64_t bytes_used;
+ uint32_t io_align;
+ uint32_t io_width;
+ uint32_t sector_size;
+ uint64_t type;
+ uint64_t generation;
+ uint64_t start_offset;
+ uint32_t dev_group;
+ uint8_t seek_speed;
+ uint8_t bandwidth;
+ uint8_t uuid[16];
+ uint8_t fsid[16];
+ } __attribute__ ((__packed__)) dev_item;
+ uint8_t label[256];
+} __attribute__ ((__packed__));
+
+#endif /* __BTRFS_H */
diff --git a/usr/kinit/fstype/fstype.c b/usr/kinit/fstype/fstype.c
index bf63b1b509998..6aa82fc660dc9 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.h"
/*
* Slightly cleaned up version of jfs_superblock to
@@ -453,6 +454,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, BTRFS_MAGIC_L)) {
+ *bytes = sb->total_bytes;
+ return 1;
+ }
+ return 0;
+}
+
struct imagetype {
off_t block;
const char name[12];
@@ -488,6 +501,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},