diff options
author | Goffredo Baroncelli <kreijack@inwind.it> | 2024-02-08 21:19:23 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2024-02-20 12:19:09 +0100 |
commit | 50770da81ecdca5811a608ea60a98cde16d5be19 (patch) | |
tree | f53fb5216e806513f2df429c435b955d47530144 | |
parent | 900f21b4f1612bc861f6254ace8368c6b6120698 (diff) | |
download | btrfs-progs-50770da81ecdca5811a608ea60a98cde16d5be19.tar.gz |
btrfs-progs: replace open_file_or_dir3 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_dir3() with btrfs_open_fd2() removing any reference
to the unused/useless dirstream variables. btrfs_open_fd2() is needed
because sometime the callers need to set the RDONLY/RDWRITE mode, and to
avoid spurious messages.
Signed-off-by: Goffredo Baroncelli <kreijack@libero.it>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | cmds/filesystem.c | 8 | ||||
-rw-r--r-- | cmds/property.c | 5 |
2 files changed, 5 insertions, 8 deletions
diff --git a/cmds/filesystem.c b/cmds/filesystem.c index fc78c557..ba4d3293 100644 --- a/cmds/filesystem.c +++ b/cmds/filesystem.c @@ -1013,7 +1013,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, @@ -1151,8 +1150,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; @@ -1186,7 +1184,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) { @@ -1198,7 +1196,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; } |