From: Thomas Weißschuh Date: Mon, 12 Apr 2021 12:01:14 +0000 (+0200) Subject: libblkid: add bcachefs support X-Git-Tag: v2.39-rc1~158 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=640941686948b81b516d730ef5a0bbf02260182a;p=thirdparty%2Futil-linux.git libblkid: add bcachefs support https://bcachefs.org/ Signed-off-by: Thomas Weißschuh --- diff --git a/libblkid/src/superblocks/bcache.c b/libblkid/src/superblocks/bcache.c index c0626082c7..0b9b74b1db 100644 --- a/libblkid/src/superblocks/bcache.c +++ b/libblkid/src/superblocks/bcache.c @@ -28,8 +28,23 @@ struct bcache_super_block { uint8_t uuid[16]; /* device identifier */ } __attribute__((packed)); +struct bcachefs_super_block { + uint8_t csum[16]; + uint16_t version; + uint16_t version_min; + uint16_t pad[2]; + uint8_t magic[16]; + uint8_t uuid[16]; + uint8_t user_uuid[16]; + uint8_t label[SB_LABEL_SIZE]; + uint64_t offset; + uint64_t seq; + uint16_t block_size; +} __attribute__((packed)); + /* magic string */ #define BCACHE_SB_MAGIC "\xc6\x85\x73\xf6\x4e\x1a\x45\xca\x82\x65\xf5\x7f\x48\xba\x6d\x81" +#define BCACHEFS_SB_MAGIC "\x18\x00\x18\x00\x00\x00\x00\x00\xc6\x85\x73\xf6\x4e\x1a\x45\xca" /* magic string len */ #define BCACHE_SB_MAGIC_LEN (sizeof(BCACHE_SB_MAGIC) - 1) /* super block offset */ @@ -42,6 +57,8 @@ struct bcache_super_block { #define BCACHE_SB_CSUMMED_START 8 /* end of checksummed data within superblock */ #define BCACHE_SB_CSUMMED_END 208 +/* granularity of offset and length fields within superblock */ +#define BCACHEFS_SECTOR_SIZE 512 static int bcache_verify_checksum(blkid_probe pr, const struct blkid_idmag *mag, const struct bcache_super_block *bcs) @@ -74,6 +91,28 @@ static int probe_bcache (blkid_probe pr, const struct blkid_idmag *mag) return BLKID_PROBE_OK; } +static int probe_bcachefs(blkid_probe pr, const struct blkid_idmag *mag) +{ + struct bcachefs_super_block *bcs; + uint64_t blocksize; + + bcs = blkid_probe_get_sb(pr, mag, struct bcachefs_super_block); + if (!bcs) + return errno ? -errno : BLKID_PROBE_NONE; + + if (le64_to_cpu(bcs->offset) != BCACHE_SB_OFF / BCACHEFS_SECTOR_SIZE) + return BLKID_PROBE_NONE; + + blkid_probe_set_uuid(pr, bcs->user_uuid); + blkid_probe_set_label(pr, bcs->label, sizeof(bcs->label)); + blkid_probe_sprintf_version(pr, "%d", le16_to_cpu(bcs->version)); + blocksize = le16_to_cpu(bcs->block_size); + blkid_probe_set_block_size(pr, blocksize * BCACHEFS_SECTOR_SIZE); + blkid_probe_set_wiper(pr, 0, BCACHE_SB_OFF); + + return BLKID_PROBE_OK; +} + const struct blkid_idinfo bcache_idinfo = { .name = "bcache", @@ -92,3 +131,25 @@ const struct blkid_idinfo bcache_idinfo = } }; +const struct blkid_idinfo bcachefs_idinfo = +{ + .name = "bcachefs", + .usage = BLKID_USAGE_FILESYSTEM, + .probefunc = probe_bcachefs, + .minsz = 256 * BCACHEFS_SECTOR_SIZE, + .magics = { + { + .magic = BCACHE_SB_MAGIC, + .len = BCACHE_SB_MAGIC_LEN, + .kboff = BCACHE_SB_KBOFF, + .sboff = BCACHE_SB_MAGIC_OFF, + }, + { + .magic = BCACHEFS_SB_MAGIC, + .len = BCACHE_SB_MAGIC_LEN, + .kboff = BCACHE_SB_KBOFF, + .sboff = BCACHE_SB_MAGIC_OFF, + }, + { NULL } + } +}; diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c index f1c230779f..c7789a15be 100644 --- a/libblkid/src/superblocks/superblocks.c +++ b/libblkid/src/superblocks/superblocks.c @@ -109,6 +109,7 @@ static const struct blkid_idinfo *idinfos[] = &jmraid_idinfo, &bcache_idinfo, + &bcachefs_idinfo, &bluestore_idinfo, &drbd_idinfo, &drbdmanage_idinfo, diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h index dd0ba2b51e..a99005861d 100644 --- a/libblkid/src/superblocks/superblocks.h +++ b/libblkid/src/superblocks/superblocks.h @@ -91,6 +91,7 @@ extern const struct blkid_idinfo nilfs2_idinfo; extern const struct blkid_idinfo exfat_idinfo; extern const struct blkid_idinfo f2fs_idinfo; extern const struct blkid_idinfo bcache_idinfo; +extern const struct blkid_idinfo bcachefs_idinfo; extern const struct blkid_idinfo mpool_idinfo; extern const struct blkid_idinfo vdo_idinfo; extern const struct blkid_idinfo stratis_idinfo; diff --git a/tests/expected/blkid/low-probe-bcachefs b/tests/expected/blkid/low-probe-bcachefs new file mode 100644 index 0000000000..e409705084 --- /dev/null +++ b/tests/expected/blkid/low-probe-bcachefs @@ -0,0 +1,8 @@ +ID_FS_BLOCK_SIZE=4096 +ID_FS_LABEL=Label +ID_FS_LABEL_ENC=Label +ID_FS_TYPE=bcachefs +ID_FS_USAGE=filesystem +ID_FS_UUID=46bd306f-80ad-4cd0-af4f-147e7d85f393 +ID_FS_UUID_ENC=46bd306f-80ad-4cd0-af4f-147e7d85f393 +ID_FS_VERSION=13 diff --git a/tests/expected/blkid/low-probe-bcachefs-2 b/tests/expected/blkid/low-probe-bcachefs-2 new file mode 100644 index 0000000000..c37fadb395 --- /dev/null +++ b/tests/expected/blkid/low-probe-bcachefs-2 @@ -0,0 +1,8 @@ +ID_FS_BLOCK_SIZE=512 +ID_FS_LABEL=Label +ID_FS_LABEL_ENC=Label +ID_FS_TYPE=bcachefs +ID_FS_USAGE=filesystem +ID_FS_UUID=4fa11b1e-75e6-4210-9167-34e1769c0fe1 +ID_FS_UUID_ENC=4fa11b1e-75e6-4210-9167-34e1769c0fe1 +ID_FS_VERSION=24 diff --git a/tests/ts/blkid/images-fs/bcachefs-2.img.xz b/tests/ts/blkid/images-fs/bcachefs-2.img.xz new file mode 100644 index 0000000000..21031703ec Binary files /dev/null and b/tests/ts/blkid/images-fs/bcachefs-2.img.xz differ diff --git a/tests/ts/blkid/images-fs/bcachefs.img.xz b/tests/ts/blkid/images-fs/bcachefs.img.xz new file mode 100644 index 0000000000..6ef0e5087f Binary files /dev/null and b/tests/ts/blkid/images-fs/bcachefs.img.xz differ