stat: report the correct block size for file system usage
authorPádraig Brady <P@draigBrady.com>
Tue, 15 May 2012 18:56:21 +0000 (19:56 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 15 May 2012 23:21:25 +0000 (00:21 +0100)
struct statfs has the f_frsize member since Linux 2.6,
so use that rather than f_bsize which can be different.
Note the related df change mentioned in NEWS is handled
in gnulib by using statvfs() rather than statfs()
on Linux > 2.6.36 (where statvfs doesn't hang) and the
same method as stat for Linux 2.6 kernels earlier than that.
stat(1) doesn't use statvfs() on GNU/Linux as the f_type
member isn't available there.
Note the change to not use statvfs() on GNU/Linux was introduced
in gnulib commit eda39b8 16-08-2003.

* m4/stat-prog.m4 (cu_PREREQ_STAT_PROG): Check for the f_frsize
member in the statfs structure.
* src/stat.c: Use (struct statfs).f_frsize if available.
* NEWS (Bug fixes): Mention this stat fix, and the related df fix
coming in the next gnulib update.
* THANKS.in: Add Nikolaus.

Reported and Tested by Nikolaus Rath

NEWS
THANKS.in
m4/stat-prog.m4
src/stat.c

diff --git a/NEWS b/NEWS
index f9e9c70..78e1d72 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   ls --color would mis-color relative-named symlinks in /
   [bug introduced in coreutils-8.17]
 
+  stat and df now report the correct file system usage,
+  in all situations on GNU/Linux, by correctly determining the block size.
+  [df bug since coreutils-5.0.91, stat bug since the initial implementation]
+
 
 * Noteworthy changes in release 8.17 (2012-05-10) [stable]
 
index 5c7dde8..f3a0c90 100644 (file)
--- a/THANKS.in
+++ b/THANKS.in
@@ -448,6 +448,7 @@ Nickolai Zeldovich                  nickolai@cs.stanford.edu
 Nicolas François                    nicolas.francois@centraliens.net
 Niklas Edmundsson                   nikke@acc.umu.se
 Nikola Milutinovic                  Nikola.Milutinovic@ev.co.yu
+Nikolaus Rath                       Nikolaus@rath.org
 Nima Nikzad                         nnikzad@ucla.edu
 Noah Friedman                       friedman@splode.com
 Noel Cragg                          noel@red-bean.com
index 30bacb4..ff59a28 100644 (file)
@@ -72,8 +72,8 @@ AC_INCLUDES_DEFAULT
       [AC_DEFINE([STRUCT_STATVFS_F_FSID_IS_INTEGER], [1],
          [Define to 1 if the f_fsid member of struct statvfs is an integer.])])
   else
-    AC_CHECK_MEMBERS([struct statfs.f_namelen, struct statfs.f_type],,,
-      [$statfs_includes])
+    AC_CHECK_MEMBERS([struct statfs.f_namelen, struct statfs.f_type,
+                     struct statfs.f_frsize],,, [$statfs_includes])
     if test $ac_cv_header_OS_h != yes; then
       AC_COMPILE_IFELSE(
         [AC_LANG_PROGRAM(
index c6747a6..d80c624 100644 (file)
@@ -126,7 +126,11 @@ statfs (char const *filename, struct fs_info *buf)
 # else
 #  define STRUCT_STATVFS struct statfs
 #  define STRUCT_STATXFS_F_FSID_IS_INTEGER STRUCT_STATFS_F_FSID_IS_INTEGER
-#  define STATFS_FRSIZE(S) 0
+#  if HAVE_STRUCT_STATFS_F_FRSIZE
+#   define STATFS_FRSIZE(S) ((S)->f_frsize)
+#  else
+#   define STATFS_FRSIZE(S) 0
+#  endif
 # endif
 #endif