2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
5 * Copyright (C) 2009 Vladimir Dronnikov <dronnikov@gmail.com>
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.
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.
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
22 //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_BTRFS) += btrfs.o
24 //config:config FEATURE_VOLUMEID_BTRFS
25 //config: bool "btrfs filesystem"
27 //config: depends on VOLUMEID
29 #include "volume_id_internal.h"
31 #define BTRFS_UUID_SIZE 16
32 #define BTRFS_LABEL_SIZE 256
33 #define BTRFS_CSUM_SIZE 32
34 #define BTRFS_FSID_SIZE 16
36 #define BTRFS_MAGIC "_BHRfS_M"
38 struct btrfs_dev_item {
47 uint64_t start_offset;
51 uint8_t uuid[BTRFS_UUID_SIZE];
52 uint8_t fsid[BTRFS_UUID_SIZE];
55 struct btrfs_super_block {
56 uint8_t csum[BTRFS_CSUM_SIZE];
57 uint8_t fsid[BTRFS_FSID_SIZE]; // UUID
65 uint64_t log_root_transid;
68 uint64_t root_dir_objectid;
74 uint32_t sys_chunk_array_size;
75 uint64_t chunk_root_generation;
76 uint64_t compat_flags;
77 uint64_t compat_ro_flags;
78 uint64_t incompat_flags;
81 uint8_t chunk_root_level;
82 uint8_t log_root_level;
83 struct btrfs_dev_item dev_item;
84 uint8_t label[BTRFS_LABEL_SIZE]; // LABEL
88 int FAST_FUNC volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/)
90 // btrfs has superblocks at 64K, 64M and 256G
91 // minimum btrfs size is 256M
92 // so we never step out the device if we analyze
93 // the first and the second superblocks
94 struct btrfs_super_block *sb;
97 while (off < 64*1024*1024) {
99 dbg("btrfs: probing at offset 0x%x", off);
101 sb = volume_id_get_buffer(id, off, sizeof(*sb));
105 if (memcmp(sb->magic, BTRFS_MAGIC, 8) != 0)
109 // N.B.: btrfs natively supports 256 (>VOLUME_ID_LABEL_SIZE) size labels
110 volume_id_set_label_string(id, sb->label, VOLUME_ID_LABEL_SIZE);
111 volume_id_set_uuid(id, sb->fsid, UUID_DCE);
112 IF_FEATURE_BLKID_TYPE(id->type = "btrfs";)