aboutsummaryrefslogtreecommitdiff
path: root/util-linux/volume_id
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-02 00:12:35 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-02 00:12:35 +0100
commitd784b65be71f8ddae433ab9bee4e2ad953097716 (patch)
tree83f4f73bffd17c23e09317a64a4e6137d971d08b /util-linux/volume_id
parent893009644fb0e4854193e664f512b96fa5590041 (diff)
downloadbusybox-d784b65be71f8ddae433ab9bee4e2ad953097716.tar.gz
btrfs.c: check first two superblocks, for additional robustness
function old new delta volume_id_probe_btrfs 94 142 +48 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/volume_id')
-rw-r--r--util-linux/volume_id/btrfs.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/util-linux/volume_id/btrfs.c b/util-linux/volume_id/btrfs.c
index 53bac7438..777b80923 100644
--- a/util-linux/volume_id/btrfs.c
+++ b/util-linux/volume_id/btrfs.c
@@ -80,19 +80,26 @@ struct btrfs_super_block {
int FAST_FUNC volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/)
{
-#define off ((uint64_t) (64 * 1024))
+ // btrfs has superblocks at 64K, 64M and 256G
+ // minimum btrfs size is 256M
+ // so we never step out the device if we analyze
+ // the first and the second superblocks
struct btrfs_super_block *sb;
+ unsigned off = 64;
- dbg("btrfs: probing at offset 0x%llx", (unsigned long long) off);
+ while (off < 64*1024*1024) {
+ off *= 1024;
+ dbg("btrfs: probing at offset 0x%x", off);
- sb = volume_id_get_buffer(id, off, sizeof(*sb));
- if (sb == NULL)
- return -1;
+ sb = volume_id_get_buffer(id, off, sizeof(*sb));
+ if (sb == NULL)
+ return -1;
- if (memcmp(sb->magic, BTRFS_MAGIC, 8) != 0)
- return -1;
+ if (memcmp(sb->magic, BTRFS_MAGIC, 8) != 0)
+ return -1;
+ }
- // N.B.: btrfs supports 256-byte labels
+ // N.B.: btrfs natively supports 256 (>VOLUME_ID_LABEL_SIZE) size labels
volume_id_set_label_string(id, sb->label, VOLUME_ID_LABEL_SIZE);
volume_id_set_uuid(id, sb->fsid, UUID_DCE);