diff mbox series

[7/9] Killing dirstream: replace open_file_or_dir with btrfs_open_fd2

Message ID fa0072bf75d989568f544697d96afd14cd4b8a27.1702148009.git.kreijack@inwind.it (mailing list archive)
State New, archived
Headers show
Series Remove unused dirstream variable | expand

Commit Message

Goffredo Baroncelli Dec. 9, 2023, 6:53 p.m. UTC
From: Goffredo Baroncelli <kreijack@inwind.it>

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

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

This patch 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 spourious error messages.

Signed-off-by: Goffredo Baroncelli <kreijack@libero.it>
---
 cmds/inspect.c   | 5 ++---
 cmds/subvolume.c | 5 ++---
 common/utils.c   | 5 ++---
 3 files changed, 6 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/cmds/inspect.c b/cmds/inspect.c
index 4d4e24d2..268a902a 100644
--- a/cmds/inspect.c
+++ b/cmds/inspect.c
@@ -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);
diff --git a/cmds/subvolume.c b/cmds/subvolume.c
index cc1a660b..b6653a40 100644
--- a/cmds/subvolume.c
+++ b/cmds/subvolume.c
@@ -1492,7 +1492,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;
@@ -1550,7 +1549,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;
@@ -1688,7 +1687,7 @@  out2:
 
 out:
 	free(subvol_path);
-	close_file_or_dir(fd, dirstream1);
+	close(fd);
 	free(fullpath);
 	return !!ret;
 }
diff --git a/common/utils.c b/common/utils.c
index 0c2fa8fe..3b86c9f3 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -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;
 }