This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] guard fallocate[64] syscall on availability of__NR_fallocate


On Tue, 2009-03-17 at 15:11 -0500, Ryan Arnold wrote:
> On Tue, 2009-03-17 at 13:28 -0500, Ryan Arnold wrote:
> 
> > +#if !defined __ASSUME_FALLOCATE && defined __NR_fallocate
> > +int __have_fallocate2 attribute_hidden
> 
> It was pointed out that I forgot a semi-colon.
> 
> I'm going to grab some newer headers and make sure the code in this
> guard compiles successfully.

I've tested and verified that both code paths compile and pass make
check.

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;
 }



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]