From 00a303202cf013b1bb47a6b24b616c7c8b7c9d92 Mon Sep 17 00:00:00 2001 From: Noel Kuntze Date: Sun, 8 Aug 2021 02:13:24 +0200 Subject: [PATCH] s3: vfs_btrfs: Fix function btrfs_fget_compression --- source3/modules/vfs_btrfs.c | 73 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/source3/modules/vfs_btrfs.c b/source3/modules/vfs_btrfs.c index 789bc6d6e8a..1d43fcb2104 100644 --- a/source3/modules/vfs_btrfs.c +++ b/source3/modules/vfs_btrfs.c @@ -460,61 +460,60 @@ static NTSTATUS btrfs_fget_compression(struct vfs_handle_struct *handle, const char *p = NULL; int ret; long flags = 0; - int fd = -1; + int fd = fd = fsp_get_pathref_fd(fsp); NTSTATUS status; - if (!fsp->fsp_flags.is_pathref) { - ret = ioctl(fd, FS_IOC_GETFLAGS, &flags); - if (ret < 0) { - DBG_WARNING("FS_IOC_GETFLAGS failed: %s, fd %lld\n", - strerror(errno), (long long)fd); - return map_nt_error_from_unix(errno); + if (fsp->fsp_flags.is_pathref) { + if (!fsp->fsp_flags.have_proc_fds) { + return NT_STATUS_NOT_IMPLEMENTED; } - if (flags & FS_COMPR_FL) { - *_compression_fmt = COMPRESSION_FORMAT_LZNT1; - } else { - *_compression_fmt = COMPRESSION_FORMAT_NONE; + + fd = fsp_get_pathref_fd(fsp); + + p = sys_proc_fd_path(fd, buf, sizeof(buf)); + if (p == NULL) { + return NT_STATUS_NO_MEMORY; } - return NT_STATUS_OK; - } - if (!fsp->fsp_flags.have_proc_fds) { - return NT_STATUS_NOT_IMPLEMENTED; - } + fd = open(p, O_RDONLY); + if (fd == -1) { + DBG_ERR("/proc open of %s failed: %s\n", p, strerror(errno)); + return map_nt_error_from_unix(errno); + } - fd = fsp_get_pathref_fd(fsp); + ret = ioctl(fd, FS_IOC_GETFLAGS, &flags); + if (ret < 0) { + DEBUG(1, ("FS_IOC_GETFLAGS failed: %s, fd %lld\n", + strerror(errno), (long long)fd)); + status = map_nt_error_from_unix(errno); + } else { + if (flags & FS_COMPR_FL) { + *_compression_fmt = COMPRESSION_FORMAT_LZNT1; + } else { + *_compression_fmt = COMPRESSION_FORMAT_NONE; + } + status = NT_STATUS_OK; + } - p = sys_proc_fd_path(fd, buf, sizeof(buf)); - if (p == NULL) { - return NT_STATUS_NO_MEMORY; - } + if (fd != -1) { + close(fd); + } - fd = open(p, O_RDONLY); - if (fd == -1) { - DBG_ERR("/proc open of %s failed: %s\n", p, strerror(errno)); - return map_nt_error_from_unix(errno); + return status; } ret = ioctl(fd, FS_IOC_GETFLAGS, &flags); if (ret < 0) { - DEBUG(1, ("FS_IOC_GETFLAGS failed: %s, fd %lld\n", - strerror(errno), (long long)fd)); - status = map_nt_error_from_unix(errno); - goto err_close; + DBG_WARNING("FS_IOC_GETFLAGS failed: %s, fd %lld\n", + strerror(errno), (long long)fd); + return map_nt_error_from_unix(errno); } if (flags & FS_COMPR_FL) { *_compression_fmt = COMPRESSION_FORMAT_LZNT1; } else { *_compression_fmt = COMPRESSION_FORMAT_NONE; } - status = NT_STATUS_OK; - -err_close: - if (fd != -1) { - close(fd); - } - - return status; + return NT_STATUS_OK; } static NTSTATUS btrfs_set_compression(struct vfs_handle_struct *handle, -- 2.32.0