[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: btrfs
From:       Vladimir Dronnikov <dronnikov () gmail ! com>
Date:       2009-10-28 19:41:21
Message-ID: 6784529b0910281241t52a7c970t872f42bacd023088 () mail ! gmail ! com
[Download RAW message or body]

> Oops. Please, discard this chunk.
> Also the copyleft should be mangled...

The updated patch is attached.

--
Vladimir

["test.patch" (application/octet-stream)]

--- busybox.orig/util-linux/Config.in	Sat Oct 17 20:17:17 2009
+++ busybox/util-linux/Config.in	Mon Oct 26 04:51:37 2009
@@ -451,6 +451,13 @@
 	help
 	  TODO
 
+config FEATURE_VOLUMEID_BTRFS
+	bool "btrfs filesystem"
+	default n
+	depends on VOLUMEID
+	help
+	  TODO
+
 config FEATURE_VOLUMEID_REISERFS
 	bool "Reiser filesystem"
 	default n
--- busybox.orig/util-linux/volume_id/Kbuild	Tue May  5 17:03:35 2009
+++ busybox/util-linux/volume_id/Kbuild	Mon Oct 26 04:51:07 2009
@@ -11,6 +11,7 @@
 lib-$(CONFIG_FEATURE_MOUNT_LABEL)               += get_devname.o
 
 lib-$(CONFIG_VOLUMEID)                          += volume_id.o util.o
+lib-$(CONFIG_FEATURE_VOLUMEID_BTRFS)            += btrfs.o
 lib-$(CONFIG_FEATURE_VOLUMEID_EXT)              += ext.o
 lib-$(CONFIG_FEATURE_VOLUMEID_FAT)              += fat.o
 lib-$(CONFIG_FEATURE_VOLUMEID_HFS)              += hfs.o
--- /dev/null	Thu Jan  1 00:00:00 1970
+++ busybox/util-linux/volume_id/btrfs.c	Mon Oct 26 09:18:37 2009
@@ -0,0 +1,100 @@
+/*
+ * volume_id - reads filesystem label and uuid
+ *
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2009 Vladimir Dronnikov <dronnikov@gmail.com>
+ *
+ *	This library is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU Lesser General Public
+ *	License as published by the Free Software Foundation; either
+ *	version 2.1 of the License, or (at your option) any later version.
+ *
+ *	This library is distributed in the hope that it will be useful,
+ *	but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ *	Lesser General Public License for more details.
+ *
+ *	You should have received a copy of the GNU Lesser General Public
+ *	License along with this library; if not, write to the Free Software
+ *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "volume_id_internal.h"
+
+#define	BTRFS_UUID_SIZE 16
+#define BTRFS_LABEL_SIZE 256
+#define BTRFS_CSUM_SIZE 32
+#define BTRFS_FSID_SIZE 16
+
+#define BTRFS_MAGIC "_BHRfS_M"
+
+struct btrfs_dev_item {
+	__le64 devid;
+	__le64 total_bytes;
+	__le64 bytes_used;
+	__le32 io_align;
+	__le32 io_width;
+	__le32 sector_size;
+	__le64 type;
+	__le64 generation;
+	__le64 start_offset;
+	__le32 dev_group;
+	uint8_t seek_speed;
+	uint8_t bandwidth;
+	uint8_t uuid[BTRFS_UUID_SIZE];
+	uint8_t fsid[BTRFS_UUID_SIZE];
+} PACKED;
+
+struct btrfs_super_block {
+	uint8_t csum[BTRFS_CSUM_SIZE];
+	uint8_t fsid[BTRFS_FSID_SIZE];	// UUID
+	__le64 bytenr;
+	__le64 flags;
+	uint8_t magic[8];
+	__le64 generation;
+	__le64 root;
+	__le64 chunk_root;
+	__le64 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;
+	uint8_t root_level;
+	uint8_t chunk_root_level;
+	uint8_t log_root_level;
+	struct btrfs_dev_item dev_item;
+	uint8_t label[BTRFS_LABEL_SIZE];	// LABEL
+	// ...
+} PACKED;
+
+int volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/)
+{
+#define off ((uint64_t) (64 * 1024))
+	struct btrfs_super_block *sb;
+
+	dbg("btrfs: probing at offset 0x%llx", (unsigned long long) off);
+
+	sb = volume_id_get_buffer(id, off, sizeof(*sb));
+	if (sb == NULL)
+		return -1;
+
+	if (memcmp(sb->magic, BTRFS_MAGIC, 8) != 0)
+		return -1;
+
+	// N.B.: btrfs supports 256-byte labels
+	volume_id_set_label_string(id, sb->label, VOLUME_ID_LABEL_SIZE);
+	volume_id_set_uuid(id, sb->fsid, UUID_DCE);
+
+	return 0;
+}
--- busybox.orig/util-linux/volume_id/get_devname.c	Thu Sep 24 20:41:41 2009
+++ busybox/util-linux/volume_id/get_devname.c	Mon Oct 26 06:21:04 2009
@@ -44,7 +44,7 @@
 	if (vid->label[0] != '\0' || vid->uuid[0] != '\0') {
 		*label = xstrndup(vid->label, sizeof(vid->label));
 		*uuid  = xstrndup(vid->uuid, sizeof(vid->uuid));
-		dbg("found label '%s', uuid '%s' on %s", *label, *uuid, device);
+		dbg("found label '%s', uuid '%s'", *label, *uuid);
 		rv = 0;
 	}
  ret:
--- busybox.orig/util-linux/volume_id/volume_id.c	Tue May  5 17:03:35 2009
+++ busybox/util-linux/volume_id/volume_id.c	Mon Oct 26 06:24:06 2009
@@ -109,6 +109,9 @@
 #if ENABLE_FEATURE_VOLUMEID_EXT
 	volume_id_probe_ext,
 #endif
+#if ENABLE_FEATURE_VOLUMEID_BTRFS
+	volume_id_probe_btrfs,
+#endif
 #if ENABLE_FEATURE_VOLUMEID_REISERFS
 	volume_id_probe_reiserfs,
 #endif
--- busybox.orig/util-linux/volume_id/volume_id_internal.h	Tue May  5 17:03:35 2009
+++ busybox/util-linux/volume_id/volume_id_internal.h	Mon Oct 26 06:53:14 2009
@@ -184,6 +184,8 @@
 
 /* FS */
 
+int volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/);
+
 int volume_id_probe_cramfs(struct volume_id *id /*,uint64_t off*/);
 
 int volume_id_probe_ext(struct volume_id *id /*,uint64_t off*/);


_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic