This is the mail archive of the libc-ports@sources.redhat.com mailing list for the libc-ports 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]

Clean up MIPS ftruncate64/truncate64


The minimum kernel version for glibc on MIPS is currently 2.6.12.

The only conditionals in MIPS code in glibc that can be removed
because of assuming at least a 2.6.12 kernel are those around
ftruncate64 and truncate64.  Nothing actually defines
__ASSUME_TRUNCATE64_SYSCALL for MIPS.  The situation with
truncate/ftruncate syscalls is, and has been since at least 2.6.12
(likely long before then):

* o32 has both 32-bit truncate/ftruncate syscalls, and 64-bit
  truncate64/ftruncate64 syscalls.

* n32 and n64 have only truncate/ftruncate, which are 64-bit.

The glibc situation, before this patch, was:

* n32 gets the syscalls from syscalls.list (with truncate64 and
  ftruncate64 being aliases of the truncate and ftruncate functions).

* n64 gets the MIPS ftruncate64.c and truncate64.c in the case where
  __NR_ftruncate64 and __NR_truncate64 are not defined (where they
  include a generic implementation that checks the offset can be
  converted to off_t before calling ftruncate or truncate).  This is
  harmless, but suboptimal.

* o32 gets the MIPS ftruncate64.c and truncate64.c, which use the
  ftruncate64 and truncate64 syscalls but also have compatibility code
  that will never be used with current kernels; again, this is
  harmless but suboptimal.

I've applied this patch to clean this area up.  Both n32 and n64 now
get ftruncate and truncate with ftruncate64 and truncate64 aliases
from syscalls.list.  The MIPS ftruncate64.c and truncate64.c are moved
into the mips32/ directory, now being only for o32, and have the
compatibility code removed.

diff --git a/ChangeLog.mips b/ChangeLog.mips
index db16b4b..b5fdbda 100644
--- a/ChangeLog.mips
+++ b/ChangeLog.mips
@@ -1,3 +1,28 @@
+2012-05-19  Joseph Myers  <joseph@codesourcery.com>
+
+	* sysdeps/unix/sysv/linux/mips/ftruncate64.c: Move to ...
+	* sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c: ... here.
+	(kernel-features.h): Don't include.
+	[__NR_ftruncate64]: Make code unconditional.
+	[!__NR_ftruncate64]: Remove conditional code.
+	[!__ASSUME_TRUNCATE64_SYSCALL]: Likewise.
+	* sysdeps/unix/sysv/linux/mips/truncate64.c: Move to ...
+	* sysdeps/unix/sysv/linux/mips/mips32/truncate64.c: ... here.
+	(kernel-features.h): Don't include.
+	[__NR_truncate64]: Make code unconditional.
+	[!__NR_truncate64]: Remove conditional code.
+	[!__ASSUME_TRUNCATE64_SYSCALL]: Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips64/syscalls.list (ftruncate):
+	Add syscall.
+	(truncate): Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list
+	(ftruncate): Remove syscall.
+	(truncate): Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips64/n32/ftruncate64.c: Move to ...
+	* sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c: ... here.
+	* sysdeps/unix/sysv/linux/mips/mips64/n32/truncate64.c: Move to ...
+	* sysdeps/unix/sysv/linux/mips/mips64/truncate64.c: ... here.
+
 2012-05-16  Joseph Myers  <joseph@codesourcery.com>
 
 	* sysdeps/unix/sysv/linux/mips/bits/stat.h (struct stat)
diff --git a/sysdeps/unix/sysv/linux/mips/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/ftruncate64.c
deleted file mode 100644
index 982650c..0000000
--- a/sysdeps/unix/sysv/linux/mips/ftruncate64.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* Copyright (C) 1997,1998,1999,2000,2001,2002,2003,2005,2006
-	Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <endian.h>
-#include <unistd.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <kernel-features.h>
-
-#ifdef __NR_ftruncate64
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-/* The variable is shared between all wrappers around *truncate64 calls.  */
-extern int __have_no_truncate64;
-#endif
-
-/* Truncate the file FD refers to to LENGTH bytes.  */
-int
-__ftruncate64 (int fd, off64_t length)
-{
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-  if (! __have_no_truncate64)
-#endif
-    {
-      unsigned int low = length & 0xffffffff;
-      unsigned int high = length >> 32;
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-      int saved_errno = errno;
-#endif
-      int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
-				   __LONG_LONG_PAIR (high, low));
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-      if (result != -1 || errno != ENOSYS)
-#endif
-	return result;
-
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-      __set_errno (saved_errno);
-      __have_no_truncate64 = 1;
-#endif
-    }
-
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-  if ((off_t) length != length)
-    {
-      __set_errno (EINVAL);
-      return -1;
-    }
-  return __ftruncate (fd, (off_t) length);
-#endif
-}
-weak_alias (__ftruncate64, ftruncate64)
-
-#else
-/* Use the generic implementation.  */
-# include <misc/ftruncate64.c>
-#endif
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
new file mode 100644
index 0000000..9838182
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/mips/mips32/ftruncate64.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 1997-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+/* Truncate the file FD refers to to LENGTH bytes.  */
+int
+__ftruncate64 (int fd, off64_t length)
+{
+  unsigned int low = length & 0xffffffff;
+  unsigned int high = length >> 32;
+  int result = INLINE_SYSCALL (ftruncate64, 4, fd, 0,
+			       __LONG_LONG_PAIR (high, low));
+  return result;
+}
+weak_alias (__ftruncate64, ftruncate64)
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/truncate64.c b/sysdeps/unix/sysv/linux/mips/mips32/truncate64.c
new file mode 100644
index 0000000..3fad93f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/mips/mips32/truncate64.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 1997-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/types.h>
+#include <endian.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Truncate the file FD refers to to LENGTH bytes.  */
+int
+truncate64 (const char *path, off64_t length)
+{
+  unsigned int low = length & 0xffffffff;
+  unsigned int high = length >> 32;
+  int result = INLINE_SYSCALL (truncate64, 4, CHECK_STRING (path), 0,
+			       __LONG_LONG_PAIR (high, low));
+  return result;
+}
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
new file mode 100644
index 0000000..6e25b02
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/mips/mips64/ftruncate64.c
@@ -0,0 +1 @@
+/* Empty.  */
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/ftruncate64.c b/sysdeps/unix/sysv/linux/mips/mips64/n32/ftruncate64.c
deleted file mode 100644
index 6e25b02..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/ftruncate64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* Empty.  */
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list b/sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list
index 0d37a9b..7ad5523 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list
@@ -2,8 +2,6 @@
 
 readahead	-	readahead	i:iii	__readahead	readahead
 sync_file_range	-	sync_file_range	Ci:iiii	sync_file_range
-ftruncate	-	ftruncate	i:ii	__ftruncate	ftruncate ftruncate64 __ftruncate64
-truncate	-	truncate	i:si	truncate	truncate64
 
 prlimit64	EXTRA	prlimit64	i:iipp	prlimit64
 
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/truncate64.c b/sysdeps/unix/sysv/linux/mips/mips64/n32/truncate64.c
deleted file mode 100644
index 6e25b02..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/truncate64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* Empty.  */
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list b/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list
index cac273c..867323a 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/mips/mips64/syscalls.list
@@ -2,6 +2,9 @@
 
 lseek		-	lseek		Ci:iii	__libc_lseek	__lseek lseek __llseek llseek __libc_lseek64 __lseek64 lseek64
 
+ftruncate	-	ftruncate	i:ii	__ftruncate	ftruncate ftruncate64 __ftruncate64
+truncate	-	truncate	i:si	truncate	truncate64
+
 # Semaphore and shm system calls.  msgctl, shmctl, and semctl have C
 # wrappers (to set __IPC_64).
 msgget		-	msgget		i:ii	__msgget	msgget
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/truncate64.c b/sysdeps/unix/sysv/linux/mips/mips64/truncate64.c
new file mode 100644
index 0000000..6e25b02
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/mips/mips64/truncate64.c
@@ -0,0 +1 @@
+/* Empty.  */
diff --git a/sysdeps/unix/sysv/linux/mips/truncate64.c b/sysdeps/unix/sysv/linux/mips/truncate64.c
deleted file mode 100644
index 7c11b63..0000000
--- a/sysdeps/unix/sysv/linux/mips/truncate64.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* Copyright (C) 1997,1998,1999,2000,2002,2003,2005,2006
-   	Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sys/types.h>
-#include <endian.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-#include <bp-checks.h>
-
-#include <kernel-features.h>
-
-#ifdef __NR_truncate64
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-/* The variable is shared between all wrappers around *truncate64 calls.  */
-int __have_no_truncate64;
-#endif
-
-/* Truncate the file FD refers to to LENGTH bytes.  */
-int
-truncate64 (const char *path, off64_t length)
-{
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-  if (! __have_no_truncate64)
-#endif
-    {
-      unsigned int low = length & 0xffffffff;
-      unsigned int high = length >> 32;
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-      int saved_errno = errno;
-#endif
-      int result = INLINE_SYSCALL (truncate64, 4, CHECK_STRING (path), 0,
-				   __LONG_LONG_PAIR (high, low));
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-      if (result != -1 || errno != ENOSYS)
-#endif
-	return result;
-
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-      __set_errno (saved_errno);
-      __have_no_truncate64 = 1;
-#endif
-    }
-
-#ifndef __ASSUME_TRUNCATE64_SYSCALL
-  if ((off_t) length != length)
-    {
-      __set_errno (EINVAL);
-      return -1;
-    }
-  return truncate (path, (off_t) length);
-#endif
-}
-
-#else
-/* Use the generic implementation.  */
-# include <misc/truncate64.c>
-#endif

-- 
Joseph S. Myers
joseph@codesourcery.com


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