aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGoffredo Baroncelli <kreijack@inwind.it>2024-02-08 21:19:26 +0100
committerDavid Sterba <dsterba@suse.com>2024-02-20 12:19:14 +0100
commit89867394e5e0ea931696a986cf4e0e45a1442edb (patch)
tree04b486888d39a421c5cf5a413a33c0841c841603
parent6a08424a50397c7e46dd928085e45aa0add0c21b (diff)
downloadbtrfs-progs-89867394e5e0ea931696a986cf4e0e45a1442edb.tar.gz
btrfs-progs: remove open_file_or_dir3 from du_add_file
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 the last reference to btrfs_open_file_or_dir3() with btrfs_open_fd2(). Signed-off-by: Goffredo Baroncelli <kreijack@libero.it> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--cmds/filesystem-du.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/cmds/filesystem-du.c b/cmds/filesystem-du.c
index 4982123d..5667b488 100644
--- a/cmds/filesystem-du.c
+++ b/cmds/filesystem-du.c
@@ -456,7 +456,7 @@ static int du_add_file(const char *filename, int dirfd,
ret = sprintf(pathp, "/%s", filename);
pathp += ret;
- fd = open_file_or_dir3(path, &dirstream, O_RDONLY);
+ fd = btrfs_open_fd2(path, false, false, false);
if (fd < 0) {
ret = -errno;
goto out;
@@ -489,6 +489,12 @@ static int du_add_file(const char *filename, int dirfd,
} else if (S_ISDIR(st.st_mode)) {
struct rb_root *root = shared_extents;
+ dirstream = fdopendir(fd);
+ if (!dirstream) {
+ ret = -errno;
+ goto out_close;
+ }
+
/*
* We collect shared extents in an rb_root, the top
* level caller will not pass a root down, so use the
@@ -542,7 +548,15 @@ static int du_add_file(const char *filename, int dirfd,
*ret_shared = file_shared;
out_close:
- close_file_or_dir(fd, dirstream);
+ /*
+ * If dirstream is not NULL, it is derived from fd, so it is enough to
+ * close the former.
+ */
+ if (dirstream)
+ closedir(dirstream);
+ else
+ close(fd);
+
out:
/* reset path to just before this element */
pathp = pathtmp;