@@ -1003,7 +1003,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,
@@ -1141,8 +1140,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;
@@ -1176,7 +1174,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) {
@@ -1188,7 +1186,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)
@@ -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;
}