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.
This commit is contained in:
Lennart Poettering 2020-09-07 19:01:41 +02:00
parent 67f0ac8c79
commit d161680e7a
5 changed files with 9 additions and 3 deletions

View File

@ -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);

View File

@ -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");

View File

@ -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)

View File

@ -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);

View File

@ -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);