]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
blockdev-util: split-out block_device_is_whole_disk()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 18 Sep 2022 07:18:53 +0000 (16:18 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 18 Sep 2022 13:54:20 +0000 (22:54 +0900)
No functional changes, just preparation for later commits.

src/shared/blockdev-util.c

index e5abb524d5ea6c4bf3c77ee265f2fad9a07dd375..829abba675835eecb63df93e5b1b15accd235b5c 100644 (file)
 #include "missing_magic.h"
 #include "parse-util.h"
 
+static int block_device_is_whole_disk(sd_device *dev) {
+        const char *s;
+        int r;
+
+        assert(dev);
+
+        r = sd_device_get_subsystem(dev, &s);
+        if (r < 0)
+                return r;
+
+        if (!streq(s, "block"))
+                return -ENOTBLK;
+
+        r = sd_device_get_devtype(dev, &s);
+        if (r < 0)
+                return r;
+
+        return streq(s, "disk");
+}
+
 int block_get_whole_disk(dev_t d, dev_t *ret) {
         char p[SYS_BLOCK_PATH_MAX("/partition")];
         _cleanup_free_ char *s = NULL;
@@ -518,18 +538,11 @@ int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret) {
         assert(dev);
         assert(ret);
 
-        r = sd_device_get_subsystem(dev, &s);
+        /* Refuse invocation on partition block device, insist on "whole" device */
+        r = block_device_is_whole_disk(dev);
         if (r < 0)
                 return r;
-
-        if (!streq(s, "block"))
-                return -ENOTBLK;
-
-        r = sd_device_get_devtype(dev, &s);
-        if (r < 0)
-                return r;
-
-        if (!streq(s, "disk")) /* Refuse invocation on partition block device, insist on "whole" device */
+        if (r == 0)
                 return -EINVAL;
 
         r = sd_device_enumerator_new(&e);