diff --git a/src/shared/blockdev-list.c b/src/shared/blockdev-list.c index d61b86c0c0..3c54219393 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 c77952993e..63e9fad10d 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) { \