From d161680e7afb7ae01593ffc5deb6c02bbc08ed19 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 Sep 2020 19:01:41 +0200 Subject: [PATCH] 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. --- src/basic/quota-util.c | 2 +- src/gpt-auto-generator/gpt-auto-generator.c | 2 +- src/partition/growfs.c | 4 ++++ src/shared/sleep-config.c | 2 ++ src/volatile-root/volatile-root.c | 2 +- 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 d1c90266a8..16086c8b86 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 8c1a84d981..3f34ad3f7c 100644 --- a/src/partition/growfs.c +++ b/src/partition/growfs.c @@ -97,6 +97,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), @@ -217,6 +219,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);