}
#endif
-static int maybe_resize_underlying_device(const char *mountpath, dev_t main_devno) {
+static int maybe_resize_underlying_device(
+ int mountfd,
+ const char *mountpath,
+ dev_t main_devno) {
+
_cleanup_free_ char *fstype = NULL, *devpath = NULL;
dev_t devno;
int r;
+ assert(mountfd >= 0);
+ assert(mountpath);
+
#if HAVE_LIBCRYPTSETUP
cryptsetup_enable_logging(NULL);
#endif
- r = get_block_device_harder(mountpath, &devno);
+ r = get_block_device_harder_fd(mountfd, &devno);
if (r < 0)
return log_error_errno(r, "Failed to determine underlying block device of \"%s\": %m",
mountpath);
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "\"%s\" is not a mount point: %m", arg_target);
- r = get_block_device(arg_target, &devno);
+ mountfd = open(arg_target, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
+ if (mountfd < 0)
+ return log_error_errno(errno, "Failed to open \"%s\": %m", arg_target);
+
+ r = get_block_device_fd(mountfd, &devno);
if (r == -EUCLEAN)
return btrfs_log_dev_root(LOG_ERR, r, arg_target);
if (r < 0)
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);
+ r = maybe_resize_underlying_device(mountfd, arg_target, devno);
if (r < 0)
return r;
- mountfd = open(arg_target, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
- if (mountfd < 0)
- return log_error_errno(errno, "Failed to open \"%s\": %m", arg_target);
-
r = device_path_make_major_minor(S_IFBLK, devno, &devpath);
if (r < 0)
return log_error_errno(r, "Failed to format device major/minor path: %m");