summaryrefslogtreecommitdiffstats
path: root/src/shared/blockdev-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-09-18 09:18:53 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-09-18 15:54:20 +0200
commitc07186ec03e888bce8d7929554d4141db6e6824e (patch)
treecbf19698cfdd194b46ec408fccfd1ed31eb4b977 /src/shared/blockdev-util.c
parentdissect-image: lazily deactivate decrypted DM volumes (diff)
downloadsystemd-c07186ec03e888bce8d7929554d4141db6e6824e.tar.xz
systemd-c07186ec03e888bce8d7929554d4141db6e6824e.zip
blockdev-util: split-out block_device_is_whole_disk()
No functional changes, just preparation for later commits.
Diffstat (limited to '')
-rw-r--r--src/shared/blockdev-util.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c
index e5abb524d5..829abba675 100644
--- a/src/shared/blockdev-util.c
+++ b/src/shared/blockdev-util.c
@@ -20,6 +20,26 @@
#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);