1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include "volume_id_internal.h"
18
19#define SB_LABEL_SIZE 32
20#define SB_JOURNAL_BUCKETS 256U
21
22static const char bcache_magic[] ALIGN1 = {
23 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca,
24 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81
25};
26
27struct bcache_super_block {
28 uint64_t csum;
29 uint64_t offset;
30 uint64_t version;
31
32 uint8_t magic[16];
33
34 uint8_t uuid[16];
35 union {
36 uint8_t set_uuid[16];
37 uint64_t set_magic;
38 };
39 uint8_t label[SB_LABEL_SIZE];
40
41 uint64_t flags;
42 uint64_t seq;
43 uint64_t pad[8];
44
45 union {
46 struct {
47
48 uint64_t nbuckets;
49
50 uint16_t block_size;
51 uint16_t bucket_size;
52
53 uint16_t nr_in_set;
54 uint16_t nr_this_dev;
55 };
56 struct {
57
58 uint64_t data_offset;
59
60
61
62
63
64
65 };
66 };
67
68 uint32_t last_mount;
69
70 uint16_t first_bucket;
71 union {
72 uint16_t njournal_buckets;
73 uint16_t keys;
74 };
75 uint64_t d[SB_JOURNAL_BUCKETS];
76};
77
78
79#define BCACHE_SB_MAGIC bcache_magic
80
81#define BCACHE_SB_MAGIC_LEN sizeof (bcache_magic)
82
83#define BCACHE_SB_OFF 0x1000
84
85#define BCACHE_SB_KBOFF (BCACHE_SB_OFF >> 10)
86
87#define BCACHE_SB_MAGIC_OFF offsetof (struct bcache_super_block, magic)
88
89int FAST_FUNC volume_id_probe_bcache(struct volume_id *id )
90{
91 struct bcache_super_block *sb;
92
93 sb = volume_id_get_buffer(id, BCACHE_SB_OFF, sizeof(*sb));
94 if (sb == NULL)
95 return -1;
96
97 if (memcmp(sb->magic, BCACHE_SB_MAGIC, BCACHE_SB_MAGIC_LEN) != 0)
98 return -1;
99
100 volume_id_set_label_string(id, sb->label, SB_LABEL_SIZE);
101 volume_id_set_uuid(id, sb->uuid, UUID_DCE);
102 IF_FEATURE_BLKID_TYPE(id->type = "bcache";)
103
104 return 0;
105}
106