]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: add bcachefs support
authorThomas Weißschuh <thomas@t-8ch.de>
Mon, 12 Apr 2021 12:01:14 +0000 (14:01 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Thu, 19 Jan 2023 19:16:55 +0000 (19:16 +0000)
https://bcachefs.org/

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libblkid/src/superblocks/bcache.c
libblkid/src/superblocks/superblocks.c
libblkid/src/superblocks/superblocks.h
tests/expected/blkid/low-probe-bcachefs [new file with mode: 0644]
tests/expected/blkid/low-probe-bcachefs-2 [new file with mode: 0644]
tests/ts/blkid/images-fs/bcachefs-2.img.xz [new file with mode: 0644]
tests/ts/blkid/images-fs/bcachefs.img.xz [new file with mode: 0644]

index c0626082c7c5c779a77355d6379a97f750efabdb..0b9b74b1dbd9052b2b4865d44e2ae3e18a2f4616 100644 (file)
@@ -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 }
+       }
+};
index f1c230779ff52ce7ed49e86fa2a751dec29f270b..c7789a15be29ae7ab20e2802a8b76d888a94cef2 100644 (file)
@@ -109,6 +109,7 @@ static const struct blkid_idinfo *idinfos[] =
        &jmraid_idinfo,
 
        &bcache_idinfo,
+       &bcachefs_idinfo,
        &bluestore_idinfo,
        &drbd_idinfo,
        &drbdmanage_idinfo,
index dd0ba2b51eabb84827cec6471e0af4437232fce6..a99005861d38c1a772b9a79097ad6567c732e783 100644 (file)
@@ -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 (file)
index 0000000..e409705
--- /dev/null
@@ -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 (file)
index 0000000..c37fadb
--- /dev/null
@@ -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 (file)
index 0000000..2103170
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 (file)
index 0000000..6ef0e50
Binary files /dev/null and b/tests/ts/blkid/images-fs/bcachefs.img.xz differ