This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] guard fallocate[64] syscall on availability of__NR_fallocate
- From: Ryan Arnold <rsa at us dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Date: Tue, 17 Mar 2009 13:28:02 -0500
- Subject: [PATCH] guard fallocate[64] syscall on availability of__NR_fallocate
- Reply-to: rsa at us dot ibm dot com
Hi,
The following patch allows us to continue to build GLIBC on systems
where our headers unistd.h lacks a definition for __NR_fallocate, i.e.
pre-2.6.23 kernel system.
I copied the guard methodology that is in posix_fallocate[64]() but
changed the non-supported case to return errno ENOSYS rather than an
internal version. Perhaps this should be errno EOPNOTSUPP?
Regards,
Ryan
2009-03-17 Ryan S. Arnold <rsa@us.ibm.com>
* sysdeps/unix/sysv/linux/fallocate.c (fallocate): return ENOSYS if
!defined __ASSUME_FALLOCATE and !defined __NR_fallocate.
* sysdeps/unix/sysv/linux/fallocate64.c (fallocate64): Same.
--- glibc/sysdeps/unix/sysv/linux/fallocate.c 2009-03-17 13:00:59.000000000 -0500
+++ glibc.new/sysdeps/unix/sysv/linux/fallocate.c 2009-03-17 11:41:29.000000000 -0500
@@ -20,12 +20,36 @@
#include <fcntl.h>
#include <sysdep.h>
+#if !defined __ASSUME_FALLOCATE && defined __NR_fallocate
+int __have_fallocate2 attribute_hidden
+#endif
/* Reserve storage for the data of the file associated with FD. */
int
fallocate (int fd, int mode, __off_t offset, __off_t len)
{
- return INLINE_SYSCALL (fallocate, 6, fd, mode,
- __LONG_LONG_PAIR (offset >> 31, offset),
- __LONG_LONG_PAIR (len >> 31, len));
+#ifdef __NR_fallocate
+# ifndef __ASSUME_FALLOCATE
+ if (__builtin_expect (__have_fallocate2 >= 0, 1))
+# endif
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int res = INTERNAL_SYSCALL (fallocate, err, 6, fd, mode,
+ __LONG_LONG_PAIR (offset >> 31, offset),
+ __LONG_LONG_PAIR (len >> 31, len));
+
+ if (! INTERNAL_SYSCALL_ERROR_P (res, err))
+ return 0;
+
+# ifndef __ASSUME_FALLOCATE
+ if (__builtin_expect (INTERNAL_SYSCALL_ERRNO (res, err) == ENOSYS, 0))
+ __have_fallocate2 = -1;
+ else
+# endif
+ if (INTERNAL_SYSCALL_ERRNO (res, err) != EOPNOTSUPP)
+ return INTERNAL_SYSCALL_ERRNO (res, err);
+ }
+#endif
+ __set_errno(ENOSYS);
+ return -1;
}
--- glibc/sysdeps/unix/sysv/linux/fallocate64.c 2009-03-17 13:00:59.000000000 -0500
+++ glibc.new/sysdeps/unix/sysv/linux/fallocate64.c 2009-03-17 11:54:14.000000000 -0500
@@ -20,14 +20,39 @@
#include <fcntl.h>
#include <sysdep.h>
+#if !defined __ASSUME_FALLOCATE && defined __NR_fallocate
+/* Defined in fallocate.c. */
+extern int __have_fallocate2 attribute_hidden;
+#endif
/* Reserve storage for the data of the file associated with FD. */
int
__fallocate64_l64 (int fd, int mode, __off64_t offset, __off64_t len)
{
- return INLINE_SYSCALL (fallocate, 6, fd, mode,
- __LONG_LONG_PAIR ((long int) (offset >> 32),
- (long int) offset),
- __LONG_LONG_PAIR ((long int) (len >> 32),
- (long int) len));
+#ifdef __NR_fallocate
+# ifndef __ASSUME_FALLOCATE
+ if (__builtin_expect (__have_fallocate2 >= 0, 1))
+# endif
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int res = INTERNAL_SYSCALL (fallocate, err, 6, fd, mode,
+ __LONG_LONG_PAIR ((long int) (offset >> 32),
+ (long int) offset),
+ __LONG_LONG_PAIR ((long int) (len >> 32),
+ (long int) len));
+
+ if (! INTERNAL_SYSCALL_ERROR_P (res, err))
+ return 0;
+
+# ifndef __ASSUME_FALLOCATE
+ if (__builtin_expect (INTERNAL_SYSCALL_ERRNO (res, err) == ENOSYS, 0))
+ __have_fallocate2 = -1;
+ else
+# endif
+ if (INTERNAL_SYSCALL_ERRNO (res, err) != EOPNOTSUPP)
+ return INTERNAL_SYSCALL_ERRNO (res, err);
+ }
+#endif
+ __set_errno(ENOSYS);
+ return -1;
}