DIR *dirstream = NULL;
char *buf = NULL;
char *xattr_name = NULL;
+ int open_flags = value ? O_RDWR : O_RDONLY;
- fd = open_file_or_dir(object, &dirstream);
+ fd = open_file_or_dir3(object, &dirstream, open_flags);
if (fd == -1) {
ret = -errno;
fprintf(stderr, "ERROR: open %s failed. %s\n",
return strtoull(s, NULL, 10) * mult;
}
-int open_file_or_dir(const char *fname, DIR **dirstream)
+int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags)
{
int ret;
struct stat st;
return -1;
fd = dirfd(*dirstream);
} else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
- fd = open(fname, O_RDWR);
+ fd = open(fname, open_flags);
} else {
/*
* we set this on purpose, in case the caller output
return fd;
}
+int open_file_or_dir(const char *fname, DIR **dirstream)
+{
+ return open_file_or_dir3(fname, dirstream, O_RDWR);
+}
+
void close_file_or_dir(int fd, DIR *dirstream)
{
if (dirstream)
u64 parse_size(char *s);
u64 arg_strtou64(const char *str);
int open_file_or_dir(const char *fname, DIR **dirstream);
+int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags);
void close_file_or_dir(int fd, DIR *dirstream);
int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
struct btrfs_ioctl_dev_info_args **di_ret);