blob: 5813035f3f4465334f09399055963199f227fc62 [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
2 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
3 *
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
6 */
7#include <stdio.h>
8#include <stdlib.h>
9#include <unistd.h>
10#include <string.h>
11#include <stdint.h>
12
13#include "superblocks.h"
14
15struct btrfs_super_block {
16 uint8_t csum[32];
17 uint8_t fsid[16];
18 uint64_t bytenr;
19 uint64_t flags;
20 uint8_t magic[8];
21 uint64_t generation;
22 uint64_t root;
23 uint64_t chunk_root;
24 uint64_t log_root;
25 uint64_t log_root_transid;
26 uint64_t total_bytes;
27 uint64_t bytes_used;
28 uint64_t root_dir_objectid;
29 uint64_t num_devices;
30 uint32_t sectorsize;
31 uint32_t nodesize;
32 uint32_t leafsize;
33 uint32_t stripesize;
34 uint32_t sys_chunk_array_size;
35 uint64_t chunk_root_generation;
36 uint64_t compat_flags;
37 uint64_t compat_ro_flags;
38 uint64_t incompat_flags;
39 uint16_t csum_type;
40 uint8_t root_level;
41 uint8_t chunk_root_level;
42 uint8_t log_root_level;
43 struct btrfs_dev_item {
44 uint64_t devid;
45 uint64_t total_bytes;
46 uint64_t bytes_used;
47 uint32_t io_align;
48 uint32_t io_width;
49 uint32_t sector_size;
50 uint64_t type;
51 uint64_t generation;
52 uint64_t start_offset;
53 uint32_t dev_group;
54 uint8_t seek_speed;
55 uint8_t bandwidth;
56 uint8_t uuid[16];
57 uint8_t fsid[16];
58 } __attribute__ ((__packed__)) dev_item;
59 uint8_t label[256];
60} __attribute__ ((__packed__));
61
62static int probe_btrfs(blkid_probe pr, const struct blkid_idmag *mag)
63{
64 struct btrfs_super_block *bfs;
65
66 if (mag->kboff > 64 && blkid_probe_ignore_backup(pr)) {
67 DBG(DEBUG_LOWPROBE, printf("btrfs: found backup superblock, ignore\n"));
68 return 1;
69 }
70
71 bfs = blkid_probe_get_sb(pr, mag, struct btrfs_super_block);
72 if (!bfs)
73 return -1;
74
75 if (*bfs->label)
76 blkid_probe_set_label(pr,
77 (unsigned char *) bfs->label,
78 sizeof(bfs->label));
79
80 blkid_probe_set_uuid(pr, bfs->fsid);
81 blkid_probe_set_uuid_as(pr, bfs->dev_item.uuid, "UUID_SUB");
82
83 return 0;
84}
85
86const struct blkid_idinfo btrfs_idinfo =
87{
88 .name = "btrfs",
89 .usage = BLKID_USAGE_FILESYSTEM,
90 .probefunc = probe_btrfs,
91 .minsz = 1024 * 1024,
92 .magics =
93 {
94 { .magic = "_BHRfS_M", .len = 8, .sboff = 0x40, .kboff = 64 },
95 { .magic = "_BHRfS_M", .len = 8, .sboff = 0x40, .kboff = 64 * 1024 },
96 { .magic = "_BHRfS_M", .len = 8, .sboff = 0x40, .kboff = 256 * 1024 * 1024 },
97 { NULL }
98 }
99};
100