From: Thomas Weißschuh Date: Tue, 26 Sep 2023 07:43:35 +0000 (+0200) Subject: libblkid: (bcachefs) add support for sub-device labels X-Git-Tag: v2.39.3~14^2~1 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=fa9b5365861934faab9ba73bd405095f56f02e45;p=thirdparty%2Futil-linux.git libblkid: (bcachefs) add support for sub-device labels Signed-off-by: Thomas Weißschuh (cherry picked from commit da91337a8109beb461c889ffe32701d3cb95aee2) --- diff --git a/libblkid/src/superblocks/bcache.c b/libblkid/src/superblocks/bcache.c index 9581aba49d..d3afc41d90 100644 --- a/libblkid/src/superblocks/bcache.c +++ b/libblkid/src/superblocks/bcache.c @@ -89,6 +89,16 @@ struct bcachefs_sb_field_members { struct bcachefs_sb_member members[]; } __attribute__((packed)); +struct bcachefs_sb_disk_group { + uint8_t label[SB_LABEL_SIZE]; + uint64_t flags[2]; +} __attribute__((packed)); + +struct bcachefs_sb_field_disk_groups { + struct bcachefs_sb_field field; + struct bcachefs_sb_disk_group disk_groups[]; +} __attribute__((packed)); + enum bcachefs_sb_csum_type { BCACHEFS_SB_CSUM_TYPE_NONE = 0, BCACHEFS_SB_CSUM_TYPE_CRC32C = 1, @@ -160,6 +170,8 @@ struct bcachefs_super_block { #define BCACHEFS_SB_FIELDS_OFF offsetof(struct bcachefs_super_block, _start) /* tag value for members field */ #define BCACHEFS_SB_FIELD_TYPE_MEMBERS 1 +/* tag value for disk_groups field */ +#define BCACHEFS_SB_FIELD_TYPE_DISK_GROUPS 5 /* version splitting helpers */ #define BCH_VERSION_MAJOR(_v) ((uint16_t) ((_v) >> 10)) #define BCH_VERSION_MINOR(_v) ((uint16_t) ((_v) & ~(~0U << 10))) @@ -229,6 +241,22 @@ static void probe_bcachefs_sb_members(blkid_probe pr, blkid_probe_set_fssize(pr, sectors * BCACHEFS_SECTOR_SIZE); } +static void probe_bcachefs_sb_disk_groups(blkid_probe pr, + const struct bcachefs_super_block *bcs, + const struct bcachefs_sb_field *field, + uint8_t dev_idx) +{ + struct bcachefs_sb_field_disk_groups *disk_groups = + (struct bcachefs_sb_field_disk_groups *) field; + + if (BYTES(field) != offsetof(typeof(*disk_groups), disk_groups[bcs->nr_devices])) + return; + + blkid_probe_set_id_label(pr, "LABEL_SUB", + disk_groups->disk_groups[dev_idx].label, + sizeof(disk_groups->disk_groups[dev_idx].label)); +} + static int is_within_range(void *start, uint64_t size, void *end) { ptrdiff_t diff; @@ -268,6 +296,9 @@ static void probe_bcachefs_sb_fields(blkid_probe pr, const struct bcachefs_super if (type == BCACHEFS_SB_FIELD_TYPE_MEMBERS) probe_bcachefs_sb_members(pr, bcs, field, bcs->dev_idx); + if (type == BCACHEFS_SB_FIELD_TYPE_DISK_GROUPS) + probe_bcachefs_sb_disk_groups(pr, bcs, field, bcs->dev_idx); + field_addr += BYTES(field); } } diff --git a/tests/expected/blkid/low-probe-bcachefs-2 b/tests/expected/blkid/low-probe-bcachefs-2 index b6e220ea0a..8e10469cf8 100644 --- a/tests/expected/blkid/low-probe-bcachefs-2 +++ b/tests/expected/blkid/low-probe-bcachefs-2 @@ -3,10 +3,12 @@ ID_FS_FSBLOCKSIZE=512 ID_FS_FSSIZE=4194304 ID_FS_LABEL=Label ID_FS_LABEL_ENC=Label +ID_FS_LABEL_SUB=Device_Label +ID_FS_LABEL_SUB_ENC=Device\x20Label 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_UUID_SUB=0a3643b7-c515-47f8-a0ea-91fc38d043d1 -ID_FS_UUID_SUB_ENC=0a3643b7-c515-47f8-a0ea-91fc38d043d1 -ID_FS_VERSION=0.26 +ID_FS_UUID_SUB=525fa857-174a-4d3f-be33-6fe60441de7c +ID_FS_UUID_SUB_ENC=525fa857-174a-4d3f-be33-6fe60441de7c +ID_FS_VERSION=0.24 diff --git a/tests/ts/blkid/images-fs/bcachefs-2.img.xz b/tests/ts/blkid/images-fs/bcachefs-2.img.xz index e796c974cb..267df3f3ee 100644 Binary files a/tests/ts/blkid/images-fs/bcachefs-2.img.xz and b/tests/ts/blkid/images-fs/bcachefs-2.img.xz differ