From 495218104a5a2b700067466761dc5cfd59e6a597 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 14 Dec 2021 01:18:39 -0500 Subject: [PATCH] fd: FS_IOC_SETFLAGS takes an int* argument not a long* According to ioctl_iflags(2): The type of the argument given to the FS_IOC_GETFLAGS and FS_IOC_SETFLAGS operations is int *, notwithstanding the implication in the kernel source file include/uapi/linux/fs.h that the argument is long *. So this code doesn't work on be64 machines. Also, Valgrind complains about it. Signed-off-by: Zygo Blaxell --- lib/fd.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/fd.cc b/lib/fd.cc index e6d0430..d147eeb 100644 --- a/lib/fd.cc +++ b/lib/fd.cc @@ -524,7 +524,14 @@ namespace crucible { void ioctl_iflags_set(int fd, int attr) { - DIE_IF_MINUS_ONE(ioctl(fd, FS_IOC_SETFLAGS, &attr)); + // This bit of nonsense brought to you by Valgrind. + union { + int attr; + long zero; + } u; + u.zero = 0; + u.attr = attr; + DIE_IF_MINUS_ONE(ioctl(fd, FS_IOC_SETFLAGS, &u.attr)); } string