[klibc] [klibc:master] fcntl: Fix struct flock for 32-bit architectures

klibc-bot for Ben Hutchings ben at decadent.org.uk
Sun Jan 20 19:51:03 PST 2019


Commit-ID:  11bd4ea5f3d960c4d208180deae91d88aa940149
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=11bd4ea5f3d960c4d208180deae91d88aa940149
Author:     Ben Hutchings <ben at decadent.org.uk>
AuthorDate: Mon, 21 Jan 2019 03:39:34 +0000
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Mon, 21 Jan 2019 03:45:04 +0000

[klibc] fcntl: Fix struct flock for 32-bit architectures

In Linux 2.6.30 the definition of struct flock stopped using
off_t (which we define) in favour of __kernel_off_t.  This
meant we started using a 32-bit struct flock with 64-bit fcntl
numbers.

Disable the kernel's definition of struct flock and define
it ourselves with 64-bit offsets.

Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/include/fcntl.h | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/usr/include/fcntl.h b/usr/include/fcntl.h
index b08c7c8..ed703a6 100644
--- a/usr/include/fcntl.h
+++ b/usr/include/fcntl.h
@@ -11,17 +11,30 @@
 #include <sys/types.h>
 #if defined(__mips__) && ! defined(__mips64)
 # include <klibc/archfcntl.h>
+#elif _BITSIZE == 32
+/* We want a struct flock with 64-bit offsets, which we define below */
+# define HAVE_ARCH_STRUCT_FLOCK
 #endif
 #include <linux/fcntl.h>
 #include <bitsize.h>
 
-#if _BITSIZE == 32
+#if !defined(__mips__) && _BITSIZE == 32
 
-/* This is ugly, but "struct flock" has actually been defined with
-   a long off_t, so it's really "struct flock64".  It just happens
-   to work.  Gag.  Barf.
+/*
+ * <linux/fcntl.h> defines struct flock with offsets of type
+ * __kernel_off_t (= long) and struct flock64 with offsets of
+ * type __kernel_loff_t (= long long).  We want struct flock
+ * to have 64-bit offsets, so we define it here.
+ */
 
-   This happens to work on all 32-bit architectures except MIPS. */
+struct flock {
+	short  l_type;
+	short  l_whence;
+	__kernel_loff_t l_start;
+	__kernel_loff_t l_len;
+	__kernel_pid_t  l_pid;
+        __ARCH_FLOCK64_PAD
+};
 
 #ifdef F_GETLK64
 # undef F_GETLK


More information about the klibc mailing list