summaryrefslogtreecommitdiff
path: root/util-linux/volume_id/btrfs.c
diff options
context:
space:
mode:
authorVladimir Dronnikov <dronnikov@gmail.com>2009-11-01 23:05:09 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-01 23:05:09 +0100
commit662e8b79d011d022c40c717501b727c1480a105f (patch)
tree5eeaa6d5b67b12869669c31672553ff3314b43fd /util-linux/volume_id/btrfs.c
parente62a2463ecd4189c5097f5d96fff83300a387c60 (diff)
downloadbusybox-w32-662e8b79d011d022c40c717501b727c1480a105f.tar.gz
busybox-w32-662e8b79d011d022c40c717501b727c1480a105f.tar.bz2
busybox-w32-662e8b79d011d022c40c717501b727c1480a105f.zip
volume_id: add support for btrfs
function old new delta volume_id_probe_btrfs - 96 +96 fs2 48 52 +4 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 100/0) Total: 100 bytes Signed-off-by: Vladimir Dronnikov <dronnikov@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/volume_id/btrfs.c')
-rw-r--r--util-linux/volume_id/btrfs.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/util-linux/volume_id/btrfs.c b/util-linux/volume_id/btrfs.c
new file mode 100644
index 000000000..98f150793
--- /dev/null
+++ b/util-linux/volume_id/btrfs.c
@@ -0,0 +1,100 @@
1/*
2 * volume_id - reads filesystem label and uuid
3 *
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
5 * Copyright (C) 2009 Vladimir Dronnikov <dronnikov@gmail.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include "volume_id_internal.h"
23
24#define BTRFS_UUID_SIZE 16
25#define BTRFS_LABEL_SIZE 256
26#define BTRFS_CSUM_SIZE 32
27#define BTRFS_FSID_SIZE 16
28
29#define BTRFS_MAGIC "_BHRfS_M"
30
31struct btrfs_dev_item {
32 uint64_t devid;
33 uint64_t total_bytes;
34 uint64_t bytes_used;
35 uint32_t io_align;
36 uint32_t io_width;
37 uint32_t sector_size;
38 uint64_t type;
39 uint64_t generation;
40 uint64_t start_offset;
41 uint32_t dev_group;
42 uint8_t seek_speed;
43 uint8_t bandwidth;
44 uint8_t uuid[BTRFS_UUID_SIZE];
45 uint8_t fsid[BTRFS_UUID_SIZE];
46} PACKED;
47
48struct btrfs_super_block {
49 uint8_t csum[BTRFS_CSUM_SIZE];
50 uint8_t fsid[BTRFS_FSID_SIZE]; // UUID
51 uint64_t bytenr;
52 uint64_t flags;
53 uint8_t magic[8];
54 uint64_t generation;
55 uint64_t root;
56 uint64_t chunk_root;
57 uint64_t log_root;
58 uint64_t log_root_transid;
59 uint64_t total_bytes;
60 uint64_t bytes_used;
61 uint64_t root_dir_objectid;
62 uint64_t num_devices;
63 uint32_t sectorsize;
64 uint32_t nodesize;
65 uint32_t leafsize;
66 uint32_t stripesize;
67 uint32_t sys_chunk_array_size;
68 uint64_t chunk_root_generation;
69 uint64_t compat_flags;
70 uint64_t compat_ro_flags;
71 uint64_t incompat_flags;
72 uint16_t csum_type;
73 uint8_t root_level;
74 uint8_t chunk_root_level;
75 uint8_t log_root_level;
76 struct btrfs_dev_item dev_item;
77 uint8_t label[BTRFS_LABEL_SIZE]; // LABEL
78 // ...
79} PACKED;
80
81int volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/)
82{
83#define off ((uint64_t) (64 * 1024))
84 struct btrfs_super_block *sb;
85
86 dbg("btrfs: probing at offset 0x%llx", (unsigned long long) off);
87
88 sb = volume_id_get_buffer(id, off, sizeof(*sb));
89 if (sb == NULL)
90 return -1;
91
92 if (memcmp(sb->magic, BTRFS_MAGIC, 8) != 0)
93 return -1;
94
95 // N.B.: btrfs supports 256-byte labels
96 volume_id_set_label_string(id, sb->label, VOLUME_ID_LABEL_SIZE);
97 volume_id_set_uuid(id, sb->fsid, UUID_DCE);
98
99 return 0;
100}