summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-09-07 19:01:41 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-09-11 19:57:22 +0200
commit5ce47fb4913b64e2d52a00a09b764161e1f6001b (patch)
treed087b7601c2ff91bcd151fd6da66f8e5e675fe38
parent8ea6ec18e785599e357eecebc44a726cccc126e3 (diff)
downloadsystemd-5ce47fb4913b64e2d52a00a09b764161e1f6001b.tar.gz
tree-wide: if get_block_device() returns zero devno, check for it in all cases
And add a comment for the existing cases where things aren't clear already. (cherry picked from commit d161680e7afb7ae01593ffc5deb6c02bbc08ed19)
-rw-r--r--src/basic/quota-util.c2
-rw-r--r--src/gpt-auto-generator/gpt-auto-generator.c2
-rw-r--r--src/partition/growfs.c4
-rw-r--r--src/shared/sleep-config.c2
-rw-r--r--src/volatile-root/volatile-root.c2
5 files changed, 9 insertions, 3 deletions
diff --git a/src/basic/quota-util.c b/src/basic/quota-util.c
index e048f5571f..96ea9ee364 100644
--- a/src/basic/quota-util.c
+++ b/src/basic/quota-util.c
@@ -34,7 +34,7 @@ int quotactl_path(int cmd, const char *path, int id, void *addr) {
r = get_block_device(path, &devno);
if (r < 0)
return r;
- if (devno == 0)
+ if (devno == 0) /* Doesn't have a block device */
return -ENODEV;
return quotactl_devno(cmd, devno, id, addr);
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index dfd5b32a02..24d28afc26 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -733,7 +733,7 @@ static int add_mounts(void) {
return btrfs_log_dev_root(LOG_ERR, r, "root file system");
if (r < 0)
return log_error_errno(r, "Failed to determine block device of root file system: %m");
- if (r == 0) {
+ if (r == 0) { /* Not backed by block device */
r = get_block_device_harder("/usr", &devno);
if (r == -EUCLEAN)
return btrfs_log_dev_root(LOG_ERR, r, "/usr");
diff --git a/src/partition/growfs.c b/src/partition/growfs.c
index ab1bc841f7..8f54489373 100644
--- a/src/partition/growfs.c
+++ b/src/partition/growfs.c
@@ -95,6 +95,8 @@ static int maybe_resize_underlying_device(const char *mountpath, dev_t main_devn
if (r < 0)
return log_error_errno(r, "Failed to determine underlying block device of \"%s\": %m",
mountpath);
+ if (devno == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ENODEV), "File system \"%s\" not backed by block device.", arg_target);
log_debug("Underlying device %d:%d, main dev %d:%d, %s",
major(devno), minor(devno),
@@ -215,6 +217,8 @@ static int run(int argc, char *argv[]) {
return btrfs_log_dev_root(LOG_ERR, r, arg_target);
if (r < 0)
return log_error_errno(r, "Failed to determine block device of \"%s\": %m", arg_target);
+ if (devno == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ENODEV), "File system \"%s\" not backed by block device.", arg_target);
r = maybe_resize_underlying_device(arg_target, devno);
if (r < 0)
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index 0dccc8f970..96c125b993 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -403,6 +403,8 @@ int find_hibernate_location(HibernateLocation **ret_hibernate_location) {
r = swap_device_to_device_id(swap, &swap_device);
if (r < 0)
return log_debug_errno(r, "%s: failed to query device number: %m", swap->device);
+ if (swap_device == 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(ENODEV), "%s: not backed by block device.", swap->device);
hibernate_location = hibernate_location_free(hibernate_location);
hibernate_location = new(HibernateLocation, 1);
diff --git a/src/volatile-root/volatile-root.c b/src/volatile-root/volatile-root.c
index e55864d6cc..6a08464245 100644
--- a/src/volatile-root/volatile-root.c
+++ b/src/volatile-root/volatile-root.c
@@ -175,7 +175,7 @@ static int run(int argc, char *argv[]) {
r = get_block_device_harder(path, &devt);
if (r < 0)
return log_error_errno(r, "Failed to determine device major/minor of %s: %m", path);
- else if (r > 0) {
+ else if (r > 0) { /* backed by block device */
_cleanup_free_ char *dn = NULL;
r = device_path_make_major_minor(S_IFBLK, devt, &dn);