]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
blockdev-list: pick up read_only property
authorLennart Poettering <lennart@amutable.com>
Thu, 23 Apr 2026 06:58:48 +0000 (08:58 +0200)
committerLennart Poettering <lennart@amutable.com>
Sun, 26 Apr 2026 19:21:49 +0000 (21:21 +0200)
src/shared/blockdev-list.c
src/shared/blockdev-list.h

index d856b1cb48cac196b48a90328e5c67ab506775e2..19aa2b48e48f2b0e069c44311de94da68a727806 100644 (file)
@@ -189,10 +189,17 @@ int blockdev_list(BlockDevListFlags flags, BlockDevice **ret_devices, size_t *re
                 }
 
                 _cleanup_free_ char *model = NULL, *vendor = NULL, *subsystem = NULL;
+                int ro = -1;
                 if (FLAGS_SET(flags, BLOCKDEV_LIST_METADATA)) {
                         (void) blockdev_get_prop(dev, "ID_MODEL_FROM_DATABASE", "ID_MODEL", &model);
                         (void) blockdev_get_prop(dev, "ID_VENDOR_FROM_DATABASE", "ID_VENDOR", &vendor);
                         (void) blockdev_get_subsystem(dev, &subsystem);
+
+                        r = device_get_sysattr_bool(dev, "ro");
+                        if (r < 0)
+                                log_device_debug_errno(dev, r, "Failed to acquire read-only flag of device '%s', ignoring: %m", node);
+                        else
+                                ro = r;
                 }
 
                 if (ret_devices) {
@@ -216,6 +223,7 @@ int blockdev_list(BlockDevListFlags flags, BlockDevice **ret_devices, size_t *re
                                 .model = TAKE_PTR(model),
                                 .vendor = TAKE_PTR(vendor),
                                 .subsystem = TAKE_PTR(subsystem),
+                                .read_only = ro,
                         };
 
                 } else {
index 845f336be5b654d9e676671e36c6a0f894b8c4d4..d82345435f7e23ff8a059ae881ef59919e5da3c7 100644 (file)
@@ -10,7 +10,7 @@ typedef enum BlockDevListFlags {
         BLOCKDEV_LIST_REQUIRE_LUKS               = 1 << 3, /* Only consider block devices with LUKS superblocks */
         BLOCKDEV_LIST_IGNORE_ROOT                = 1 << 4, /* Ignore the block device we are currently booted from */
         BLOCKDEV_LIST_IGNORE_EMPTY               = 1 << 5, /* Ignore disks of zero size (usually drives without a medium) */
-        BLOCKDEV_LIST_METADATA                   = 1 << 6, /* Fill in model, vendor, subsystem */
+        BLOCKDEV_LIST_METADATA                   = 1 << 6, /* Fill in model, vendor, subsystem, read_only */
 } BlockDevListFlags;
 
 typedef struct BlockDevice {
@@ -21,11 +21,13 @@ typedef struct BlockDevice {
         char *subsystem;
         uint64_t diskseq;
         uint64_t size;     /* in bytes */
+        int read_only;
 } BlockDevice;
 
 #define BLOCK_DEVICE_NULL (BlockDevice) { \
                 .diskseq = UINT64_MAX,    \
                 .size = UINT64_MAX,       \
+                .read_only = -1,          \
         }
 
 void block_device_done(BlockDevice *d);