2 * Copyright (C) 2013 Rolf Fokkens <rolf@fokkens.nl>
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
7 * Based on code fragments from bcache-tools by Kent Overstreet:
8 * http://evilpiepirate.org/git/bcache-tools.git
11 //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_BCACHE) += bcache.o
14 //config:config FEATURE_VOLUMEID_BCACHE
15 //config: bool "bcache filesystem"
17 //config: depends on VOLUMEID
22 #include "volume_id_internal.h"
24 #define SB_LABEL_SIZE 32
25 #define SB_JOURNAL_BUCKETS 256U
27 static const char bcache_magic
[] ALIGN1
= {
28 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca,
29 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81
32 struct bcache_super_block
{
34 uint64_t offset
; /* sector where this sb was written */
44 uint8_t label
[SB_LABEL_SIZE
];
53 uint64_t nbuckets
; /* device size */
55 uint16_t block_size
; /* sectors */
56 uint16_t bucket_size
; /* sectors */
66 * block_size from the cache device section is still used by
67 * backing devices, so don't add anything here until we fix
68 * things to not need it for backing devices anymore
73 uint32_t last_mount
; /* time_t */
75 uint16_t first_bucket
;
77 uint16_t njournal_buckets
;
80 uint64_t d
[SB_JOURNAL_BUCKETS
]; /* journal buckets */
84 #define BCACHE_SB_MAGIC bcache_magic
85 /* magic string len */
86 #define BCACHE_SB_MAGIC_LEN sizeof (bcache_magic)
87 /* super block offset */
88 #define BCACHE_SB_OFF 0x1000
89 /* supper block offset in kB */
90 #define BCACHE_SB_KBOFF (BCACHE_SB_OFF >> 10)
91 /* magic string offset within super block */
92 #define BCACHE_SB_MAGIC_OFF offsetof (struct bcache_super_block, magic)
94 int FAST_FUNC
volume_id_probe_bcache(struct volume_id
*id
/*,uint64_t off*/)
96 struct bcache_super_block
*sb
;
98 sb
= volume_id_get_buffer(id
, BCACHE_SB_OFF
, sizeof(*sb
));
102 if (memcmp(sb
->magic
, BCACHE_SB_MAGIC
, BCACHE_SB_MAGIC_LEN
) != 0)
105 volume_id_set_label_string(id
, sb
->label
, SB_LABEL_SIZE
);
106 volume_id_set_uuid(id
, sb
->uuid
, UUID_DCE
);
107 IF_FEATURE_BLKID_TYPE(id
->type
= "bcache";)