From: Lennart Poettering Date: Thu, 28 Aug 2025 08:56:06 +0000 (+0200) Subject: blockdev-list: also pick up block device size X-Git-Tag: v259-rc1~467^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e863e2dbb57d2d54e8ef2d6dd9a057b6a5e2977b;p=thirdparty%2Fsystemd.git blockdev-list: also pick up block device size --- diff --git a/src/shared/blockdev-list.c b/src/shared/blockdev-list.c index d61b86c0c01..3c54219393e 100644 --- a/src/shared/blockdev-list.c +++ b/src/shared/blockdev-list.c @@ -6,6 +6,7 @@ #include "ansi-color.h" #include "blockdev-list.h" #include "blockdev-util.h" +#include "device-private.h" #include "device-util.h" #include "strv.h" #include "terminal-util.h" @@ -93,12 +94,18 @@ int blockdev_list(BlockDevListFlags flags, BlockDevice **ret_devices, size_t *re } if (ret_devices) { - uint64_t diskseq = UINT64_MAX; + uint64_t diskseq = UINT64_MAX, size = UINT64_MAX; r = sd_device_get_diskseq(dev, &diskseq); if (r < 0) log_debug_errno(r, "Failed to acquire diskseq of device '%s', ignoring: %m", node); + r = device_get_sysattr_u64(dev, "size", &size); + if (r < 0) + log_debug_errno(r, "Failed to acquire size of device '%s', ignoring: %m", node); + else + size *= 512; /* the 'size' sysattr is always in multiples of 512, even on 4K sector block devices! */ + if (!GREEDY_REALLOC(l, n+1)) return log_oom(); @@ -110,6 +117,7 @@ int blockdev_list(BlockDevListFlags flags, BlockDevice **ret_devices, size_t *re .node = TAKE_PTR(m), .symlinks = TAKE_PTR(list), .diskseq = diskseq, + .size = size, }; } else { diff --git a/src/shared/blockdev-list.h b/src/shared/blockdev-list.h index c77952993e8..63e9fad10d9 100644 --- a/src/shared/blockdev-list.h +++ b/src/shared/blockdev-list.h @@ -14,6 +14,7 @@ typedef struct BlockDevice { char *node; char **symlinks; uint64_t diskseq; + uint64_t size; /* in bytes */ } BlockDevice; #define BLOCK_DEVICE_NULL (BlockDevice) { \