btrfs-progs: replace open_file_or_dir with btrfs_open_fd2

For historical reasons the helpers [btrfs_]open_dir... return also
the 'DIR *dirstream' value when a directory is opened.

However this is never used. So avoid calling diropen() and return
only the fd.

Replace open_file_or_dir() with btrfs_open_fd2() removing any reference
to the unused/useless dirstream variables.  btrfs_open_fd2() is required
to avoid spurious error messages.

Signed-off-by: Goffredo Baroncelli <kreijack@libero.it>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Goffredo Baroncelli 2024-02-08 21:19:25 +01:00 committed by David Sterba
parent cafef41840
commit 6a08424a50
4 changed files with 8 additions and 12 deletions

View File

@ -1020,7 +1020,6 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,
int ret;
int fd;
int i;
DIR *dirstream = NULL;
unsigned unit_mode;
char *sortmode = NULL;
bool with_usage = true;
@ -1083,7 +1082,7 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,
path = argv[optind];
fd = open_file_or_dir(path, &dirstream);
fd = btrfs_open_fd2(path, false, true, false);
if (fd < 0) {
error("cannot access '%s': %m", path);
return 1;
@ -1187,7 +1186,7 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,
}
ret = print_list_chunks(&ctx, sortmode, unit_mode, with_usage, with_empty);
close_file_or_dir(fd, dirstream);
close(fd);
out_nomem:
free(ctx.stats);

View File

@ -1999,7 +1999,6 @@ static int cmd_scrub_limit(const struct cmd_struct *cmd, int argc, char **argv)
struct string_table *table = NULL;
int ret;
int fd = -1;
DIR *dirstream = NULL;
int cols, idx;
u64 opt_devid = 0;
bool devid_set = false;
@ -2060,7 +2059,7 @@ static int cmd_scrub_limit(const struct cmd_struct *cmd, int argc, char **argv)
return 1;
}
fd = open_file_or_dir(argv[optind], &dirstream);
fd = btrfs_open_fd2(argv[optind], false, true, false);
if (fd < 0)
return 1;
@ -2182,7 +2181,7 @@ static int cmd_scrub_limit(const struct cmd_struct *cmd, int argc, char **argv)
out:
if (table)
table_free(table);
close_file_or_dir(fd, dirstream);
close(fd);
return !!ret;
}

View File

@ -1566,7 +1566,6 @@ static int cmd_subvolume_show(const struct cmd_struct *cmd, int argc, char **arg
char *fullpath = NULL;
int fd = -1;
int ret = 1;
DIR *dirstream1 = NULL;
int by_rootid = 0;
int by_uuid = 0;
u64 rootid_arg = 0;
@ -1624,7 +1623,7 @@ static int cmd_subvolume_show(const struct cmd_struct *cmd, int argc, char **arg
goto out;
}
fd = open_file_or_dir(fullpath, &dirstream1);
fd = btrfs_open_fd2(fullpath, false, true, false);
if (fd < 0) {
error("can't access '%s'", fullpath);
goto out;
@ -1762,7 +1761,7 @@ out2:
out:
free(subvol_path);
close_file_or_dir(fd, dirstream1);
close(fd);
free(fullpath);
return !!ret;
}

View File

@ -211,7 +211,6 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args,
struct btrfs_ioctl_dev_info_args *di_args;
struct btrfs_ioctl_dev_info_args tmp;
char mp[PATH_MAX];
DIR *dirstream = NULL;
memset(fi_args, 0, sizeof(*fi_args));
@ -251,7 +250,7 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args,
}
/* at this point path must not be for a block device */
fd = open_file_or_dir(path, &dirstream);
fd = btrfs_open_fd2(path, false, true, false);
if (fd < 0) {
ret = -errno;
goto out;
@ -317,7 +316,7 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args,
}
out:
close_file_or_dir(fd, dirstream);
close(fd);
return ret;
}