coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] maint: use stat-size module from gnulib


From: James Youngman
Subject: [PATCH] maint: use stat-size module from gnulib
Date: Sat, 11 Jun 2011 16:28:34 +0100

* gnulib: Update to latest.
* src/system.h: Definitions of ST_* macros have moved into the
gnulib module stat-size (specifically, the header file
stat-size.h), so remove them from here.
* src/truncate.c: Include stat-size.h.
* src/stat.c: Likewise.
* src/shred.c: Likewise.
* src/ls.c: Likewise.
* src/du.c: Likewise.
* src/ioblksize.h: New file.  Move definition of io_blksize out of
system.h so that system.h does not have to include stat-size.h.
* src/cat.c: Include ioblksize.h.
* src/split.c: Likewise.
* src/copy.c: Include both stat-size.h and ioblksize.h.
* src/Makefile.am (noinst_HEADERS): Add ioblksize.h.
---
 bootstrap.conf  |    1 +
 gnulib          |    2 +-
 src/Makefile.am |    1 +
 src/cat.c       |    1 +
 src/copy.c      |    2 +
 src/du.c        |    1 +
 src/ioblksize.h |   66 +++++++++++++++++++++++++++++++
 src/ls.c        |    1 +
 src/shred.c     |    1 +
 src/split.c     |    1 +
 src/stat.c      |    1 +
 src/system.h    |  116 -------------------------------------------------------
 src/truncate.c  |    1 +
 13 files changed, 78 insertions(+), 117 deletions(-)
 create mode 100644 src/ioblksize.h

diff --git a/bootstrap.conf b/bootstrap.conf
index 4168ee2..23f7abb 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -196,6 +196,7 @@ gnulib_modules="
   sigaction
   ssize_t
   stat-macros
+  stat-size
   stat-time
   stdbool
   stdlib-safer
diff --git a/gnulib b/gnulib
index 9d196fa..9fc77bc 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 9d196fad055a448c5732a8e950cc044b353d2615
+Subproject commit 9fc77bc59374e21e1174742df416af186a368e14
diff --git a/src/Makefile.am b/src/Makefile.am
index 908cd33..516e1e5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -149,6 +149,7 @@ noinst_HEADERS =    \
   find-mount-point.h   \
   fs.h                 \
   group-list.h         \
+  ioblksize.h          \
   ls.h                 \
   operand2sig.h                \
   prog-fprintf.h       \
diff --git a/src/cat.c b/src/cat.c
index 6df3eb0..c44296c 100644
--- a/src/cat.c
+++ b/src/cat.c
@@ -33,6 +33,7 @@
 #include <sys/ioctl.h>
 
 #include "system.h"
+#include "ioblksize.h"
 #include "error.h"
 #include "fadvise.h"
 #include "full-write.h"
diff --git a/src/copy.c b/src/copy.c
index 801a474..1025fe1 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -47,9 +47,11 @@
 #include "hash.h"
 #include "hash-triple.h"
 #include "ignore-value.h"
+#include "ioblksize.h"
 #include "quote.h"
 #include "same.h"
 #include "savedir.h"
+#include "stat-size.h"
 #include "stat-time.h"
 #include "utimecmp.h"
 #include "utimens.h"
diff --git a/src/du.c b/src/du.c
index 71275a2..fba7f7d 100644
--- a/src/du.c
+++ b/src/du.c
@@ -37,6 +37,7 @@
 #include "human.h"
 #include "quote.h"
 #include "quotearg.h"
+#include "stat-size.h"
 #include "stat-time.h"
 #include "stdio--.h"
 #include "xfts.h"
diff --git a/src/ioblksize.h b/src/ioblksize.h
new file mode 100644
index 0000000..eaeced3
--- /dev/null
+++ b/src/ioblksize.h
@@ -0,0 +1,66 @@
+/* I/O block size definitions for coreutils
+   Copyright (C) 1989, 1991-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Include this file _after_ system headers if possible.  */
+
+/* sys/stat.h will already have been included by system.h. */
+#include "stat-size.h"
+
+
+/* As of Mar 2009, 32KiB is determined to be the minimium
+   blksize to best minimize system call overhead.
+   This can be tested with this script with the results
+   shown for a 1.7GHz pentium-m with 2GB of 400MHz DDR2 RAM:
+
+   for i in $(seq 0 10); do
+     size=$((8*1024**3)) #ensure this is big enough
+     bs=$((1024*2**$i))
+     printf "%7s=" $bs
+     dd bs=$bs if=/dev/zero of=/dev/null count=$(($size/$bs)) 2>&1 |
+     sed -n 's/.* \([0-9.]* [GM]B\/s\)/\1/p'
+   done
+
+      1024=734 MB/s
+      2048=1.3 GB/s
+      4096=2.4 GB/s
+      8192=3.5 GB/s
+     16384=3.9 GB/s
+     32768=5.2 GB/s
+     65536=5.3 GB/s
+    131072=5.5 GB/s
+    262144=5.7 GB/s
+    524288=5.7 GB/s
+   1048576=5.8 GB/s
+
+   Note that this is to minimize system call overhead.
+   Other values may be appropriate to minimize file system
+   or disk overhead.  For example on my current GNU/Linux system
+   the readahead setting is 128KiB which was read using:
+
+   file="."
+   device=$(df -P --local "$file" | tail -n1 | cut -d' ' -f1)
+   echo $(( $(blockdev --getra $device) * 512 ))
+
+   However there isn't a portable way to get the above.
+   In the future we could use the above method if available
+   and default to io_blksize() if not.
+ */
+enum { IO_BUFSIZE = 32*1024 };
+static inline size_t
+io_blksize (struct stat sb)
+{
+  return MAX (IO_BUFSIZE, ST_BLKSIZE (sb));
+}
diff --git a/src/ls.c b/src/ls.c
index 80fdb80..a167254 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -94,6 +94,7 @@
 #include "obstack.h"
 #include "quote.h"
 #include "quotearg.h"
+#include "stat-size.h"
 #include "stat-time.h"
 #include "strftime.h"
 #include "xstrtol.h"
diff --git a/src/shred.c b/src/shred.c
index ecb27b8..a2365b0 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -100,6 +100,7 @@
 #include "quotearg.h"          /* For quotearg_colon */
 #include "randint.h"
 #include "randread.h"
+#include "stat-size.h"
 
 /* Default number of times to overwrite.  */
 enum { DEFAULT_PASSES = 3 };
diff --git a/src/split.c b/src/split.c
index 95a2ccc..2962b68 100644
--- a/src/split.c
+++ b/src/split.c
@@ -35,6 +35,7 @@
 #include "fcntl--.h"
 #include "full-read.h"
 #include "full-write.h"
+#include "ioblksize.h"
 #include "quote.h"
 #include "safe-read.h"
 #include "sig2str.h"
diff --git a/src/stat.c b/src/stat.c
index 4e6e1c3..c479726 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -67,6 +67,7 @@
 #include "mountlist.h"
 #include "quote.h"
 #include "quotearg.h"
+#include "stat-size.h"
 #include "stat-time.h"
 #include "strftime.h"
 #include "find-mount-point.h"
diff --git a/src/system.h b/src/system.h
index 47aad02..95ef2c3 100644
--- a/src/system.h
+++ b/src/system.h
@@ -133,77 +133,6 @@ enum
 /* include here for SIZE_MAX.  */
 #include <inttypes.h>
 
-/* Get or fake the disk device blocksize.
-   Usually defined by sys/param.h (if at all).  */
-#if !defined DEV_BSIZE && defined BSIZE
-# define DEV_BSIZE BSIZE
-#endif
-#if !defined DEV_BSIZE && defined BBSIZE /* SGI */
-# define DEV_BSIZE BBSIZE
-#endif
-#ifndef DEV_BSIZE
-# define DEV_BSIZE 4096
-#endif
-
-/* Extract or fake data from a `struct stat'.
-   ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes.
-   ST_NBLOCKS: Number of blocks in the file, including indirect blocks.
-   ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS.  */
-#ifndef HAVE_STRUCT_STAT_ST_BLOCKS
-# define ST_BLKSIZE(statbuf) DEV_BSIZE
-# if defined _POSIX_SOURCE || !defined BSIZE /* fileblocks.c uses BSIZE.  */
-#  define ST_NBLOCKS(statbuf) \
-  ((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 
0))
-# else /* !_POSIX_SOURCE && BSIZE */
-#  define ST_NBLOCKS(statbuf) \
-  (S_ISREG ((statbuf).st_mode) \
-   || S_ISDIR ((statbuf).st_mode) \
-   ? st_blocks ((statbuf).st_size) : 0)
-# endif /* !_POSIX_SOURCE && BSIZE */
-#else /* HAVE_STRUCT_STAT_ST_BLOCKS */
-/* Some systems, like Sequents, return st_blksize of 0 on pipes.
-   Also, when running `rsh hpux11-system cat any-file', cat would
-   determine that the output stream had an st_blksize of 2147421096.
-   Conversely st_blksize can be 2 GiB (or maybe even larger) with XFS
-   on 64-bit hosts.  Somewhat arbitrarily, limit the `optimal' block
-   size to SIZE_MAX / 8 + 1.  (Dividing SIZE_MAX by only 4 wouldn't
-   suffice, since "cat" sometimes multiplies the result by 4.)  If
-   anyone knows of a system for which this limit is too small, please
-   report it as a bug in this code.  */
-# define ST_BLKSIZE(statbuf) ((0 < (statbuf).st_blksize \
-                               && (statbuf).st_blksize <= SIZE_MAX / 8 + 1) \
-                              ? (statbuf).st_blksize : DEV_BSIZE)
-# if defined hpux || defined __hpux__ || defined __hpux
-/* HP-UX counts st_blocks in 1024-byte units.
-   This loses when mixing HP-UX and BSD file systems with NFS.  */
-#  define ST_NBLOCKSIZE 1024
-# else /* !hpux */
-#  if defined _AIX && defined _I386
-/* AIX PS/2 counts st_blocks in 4K units.  */
-#   define ST_NBLOCKSIZE (4 * 1024)
-#  else /* not AIX PS/2 */
-#   if defined _CRAY
-#    define ST_NBLOCKS(statbuf) \
-  (S_ISREG ((statbuf).st_mode) \
-   || S_ISDIR ((statbuf).st_mode) \
-   ? (statbuf).st_blocks * ST_BLKSIZE (statbuf) / ST_NBLOCKSIZE : 0)
-#   endif /* _CRAY */
-#  endif /* not AIX PS/2 */
-# endif /* !hpux */
-#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
-
-#ifndef ST_NBLOCKS
-# define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
-#endif
-
-#ifndef ST_NBLOCKSIZE
-# ifdef S_BLKSIZE
-#  define ST_NBLOCKSIZE S_BLKSIZE
-# else
-#  define ST_NBLOCKSIZE 512
-# endif
-#endif
-
 /* Redirection and wildcarding when done by the utility itself.
    Generally a noop, but used in particular for native VMS. */
 #ifndef initialize_main
@@ -629,51 +558,6 @@ bad_cast (char const *s)
   return (char *) s;
 }
 
-/* As of Mar 2009, 32KiB is determined to be the minimium
-   blksize to best minimize system call overhead.
-   This can be tested with this script with the results
-   shown for a 1.7GHz pentium-m with 2GB of 400MHz DDR2 RAM:
-
-   for i in $(seq 0 10); do
-     size=$((8*1024**3)) #ensure this is big enough
-     bs=$((1024*2**$i))
-     printf "%7s=" $bs
-     dd bs=$bs if=/dev/zero of=/dev/null count=$(($size/$bs)) 2>&1 |
-     sed -n 's/.* \([0-9.]* [GM]B\/s\)/\1/p'
-   done
-
-      1024=734 MB/s
-      2048=1.3 GB/s
-      4096=2.4 GB/s
-      8192=3.5 GB/s
-     16384=3.9 GB/s
-     32768=5.2 GB/s
-     65536=5.3 GB/s
-    131072=5.5 GB/s
-    262144=5.7 GB/s
-    524288=5.7 GB/s
-   1048576=5.8 GB/s
-
-   Note that this is to minimize system call overhead.
-   Other values may be appropriate to minimize file system
-   or disk overhead.  For example on my current GNU/Linux system
-   the readahead setting is 128KiB which was read using:
-
-   file="."
-   device=$(df -P --local "$file" | tail -n1 | cut -d' ' -f1)
-   echo $(( $(blockdev --getra $device) * 512 ))
-
-   However there isn't a portable way to get the above.
-   In the future we could use the above method if available
-   and default to io_blksize() if not.
- */
-enum { IO_BUFSIZE = 32*1024 };
-static inline size_t
-io_blksize (struct stat sb)
-{
-  return MAX (IO_BUFSIZE, ST_BLKSIZE (sb));
-}
-
 void usage (int status) ATTRIBUTE_NORETURN;
 
 #define emit_cycle_warning(file_name)  \
diff --git a/src/truncate.c b/src/truncate.c
index b6c7762..eaa1b74 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -28,6 +28,7 @@
 #include "system.h"
 #include "error.h"
 #include "quote.h"
+#include "stat-size.h"
 #include "xstrtol.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]