]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
blockdev-list: make BLOCKDEV_LIST_IGNORE_ROOT suppress all definitions of the root... 41814/head
authorLennart Poettering <lennart@amutable.com>
Thu, 23 Apr 2026 13:46:10 +0000 (15:46 +0200)
committerLennart Poettering <lennart@amutable.com>
Sun, 26 Apr 2026 19:45:28 +0000 (21:45 +0200)
There are various definitions of the root disk, let's suppress them all if
the flag is set. So far only the outermost is suppressed, which is a bit
weird, given it's "further away" from the rootfs.

src/shared/blockdev-list.c

index 19aa2b48e48f2b0e069c44311de94da68a727806..5b11c8169477f5b2a0e86363b15f33fc3dc43041 100644 (file)
@@ -8,6 +8,7 @@
 #include "blockdev-util.h"
 #include "device-private.h"
 #include "device-util.h"
+#include "devnum-util.h"
 #include "errno-util.h"
 #include "string-util.h"
 #include "strv.h"
@@ -99,14 +100,21 @@ int blockdev_list(BlockDevListFlags flags, BlockDevice **ret_devices, size_t *re
         size_t n = 0;
         CLEANUP_ARRAY(l, n, block_device_array_free);
 
-        dev_t root_devno = 0;
-        if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_ROOT))
-                if (blockdev_get_root(LOG_DEBUG, &root_devno) > 0) {
-                        r = block_get_whole_disk(root_devno, &root_devno);
+        dev_t root_devno = 0, whole_root_devno = 0;
+        if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_ROOT)) {
+                r = blockdev_get_root(LOG_DEBUG, &root_devno);
+                if (r < 0)
+                        log_debug_errno(r, "Failed to get block device of root device, ignoring: %m");
+                else if (r > 0) {
+                        r = block_get_whole_disk(root_devno, &whole_root_devno);
                         if (r < 0)
-                                log_debug_errno(r, "Failed to get whole block device of root device: %m");
+                                log_debug_errno(r, "Failed to get whole block device of root device, ignoring: %m");
                 }
 
+                /* It's fine if root_devno/whole_root_devno are zero here as devnum_set_and_equal() will
+                 * happily take that into account – it is in fact its primary raison d'etre. */
+        }
+
         if (sd_device_enumerator_new(&e) < 0)
                 return log_oom();
 
@@ -138,7 +146,8 @@ int blockdev_list(BlockDevListFlags flags, BlockDevice **ret_devices, size_t *re
                                 continue;
                         }
 
-                        if (devno == root_devno)
+                        if (devnum_set_and_equal(devno, root_devno) ||
+                            devnum_set_and_equal(devno, whole_root_devno))
                                 continue;
                 }