diff mbox series

[5/9] Killing dirstream: replace open_file_or_dir3 with btrfs_open_fd2

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

Commit Message

Goffredo Baroncelli Feb. 8, 2024, 8:19 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_dir3() with btrfs_open_fd2() removing
any reference to the unused/useless dirstream variables.
btrfs_open_fd2() is needed because sometime the caller need
to set the RDONLY/RDWRITE mode, and to avoid spourios diagnosis messages.

Signed-off-by: Goffredo Baroncelli <kreijack@libero.it>
---
 cmds/filesystem.c | 8 +++-----
 cmds/property.c   | 5 ++---
 2 files changed, 5 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index d37b52a3..408ebe82 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -1004,7 +1004,6 @@  static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 	bool recursive = false;
 	int ret = 0;
 	int compress_type = BTRFS_COMPRESS_NONE;
-	DIR *dirstream;
 
 	/*
 	 * Kernel 4.19+ supports defragmention of files open read-only,
@@ -1142,8 +1141,7 @@  static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 		struct stat st;
 		int defrag_err = 0;
 
-		dirstream = NULL;
-		fd = open_file_or_dir3(argv[i], &dirstream, defrag_open_mode);
+		fd = btrfs_open_fd2(argv[i], false, defrag_open_mode==O_RDWR, false);
 		if (fd < 0) {
 			error("cannot open %s: %m", argv[i]);
 			ret = -errno;
@@ -1177,7 +1175,7 @@  static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 				error(
 "defrag range ioctl not supported in this kernel version, 2.6.33 and newer is required");
 				defrag_global_errors++;
-				close_file_or_dir(fd, dirstream);
+				close(fd);
 				break;
 			}
 			if (ret) {
@@ -1189,7 +1187,7 @@  static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 next:
 		if (ret)
 			defrag_global_errors++;
-		close_file_or_dir(fd, dirstream);
+		close(fd);
 	}
 
 	if (defrag_global_errors)
diff --git a/cmds/property.c b/cmds/property.c
index be9bdf63..e189e505 100644
--- a/cmds/property.c
+++ b/cmds/property.c
@@ -175,12 +175,11 @@  static int prop_compression(enum prop_object_type type,
 	int ret;
 	ssize_t sret;
 	int fd = -1;
-	DIR *dirstream = NULL;
 	char *buf = NULL;
 	char *xattr_name = NULL;
 	int open_flags = value ? O_RDWR : O_RDONLY;
 
-	fd = open_file_or_dir3(object, &dirstream, open_flags);
+	fd = btrfs_open_fd2(object, false, open_flags == O_RDWR, false);
 	if (fd == -1) {
 		ret = -errno;
 		error("failed to open %s: %m", object);
@@ -232,7 +231,7 @@  out:
 	free(xattr_name);
 	free(buf);
 	if (fd >= 0)
-		close_file_or_dir(fd, dirstream);
+		close(fd);
 
 	return ret;
 }