Blame SOURCES/coreutils-df-direct.patch

f5e30c
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
f5e30c
index a507280..400e135 100644
f5e30c
--- a/doc/coreutils.texi
f5e30c
+++ b/doc/coreutils.texi
f5e30c
@@ -11303,6 +11303,13 @@ some systems (notably SunOS), doing this yields more up to date results,
f5e30c
 but in general this option makes @command{df} much slower, especially when
f5e30c
 there are many or very busy file systems.
f5e30c
 
f5e30c
+@item --direct
f5e30c
+@opindex --direct
f5e30c
+@cindex direct statfs for a file
f5e30c
+Do not resolve mount point and show statistics directly for a file. It can be
f5e30c
+especially useful for NFS mount points if there is a boundary between two
f5e30c
+storage policies behind the mount point.
f5e30c
+
f5e30c
 @item --total
f5e30c
 @opindex --total
f5e30c
 @cindex grand total of disk size, usage and available space
f5e30c
diff --git a/src/df.c b/src/df.c
f5e30c
index 8f760db..a7385fd 100644
f5e30c
--- a/src/df.c
f5e30c
+++ b/src/df.c
f5e30c
@@ -120,6 +120,9 @@ static bool print_type;
f5e30c
 /* If true, print a grand total at the end.  */
f5e30c
 static bool print_grand_total;
f5e30c
 
f5e30c
+/* If true, show statistics for a file instead of mount point.  */
f5e30c
+static bool direct_statfs;
f5e30c
+
f5e30c
 /* Grand total data.  */
f5e30c
 static struct fs_usage grand_fsu;
f5e30c
 
f5e30c
@@ -247,13 +250,15 @@ enum
f5e30c
   NO_SYNC_OPTION = CHAR_MAX + 1,
f5e30c
   SYNC_OPTION,
f5e30c
   TOTAL_OPTION,
f5e30c
-  OUTPUT_OPTION
f5e30c
+  OUTPUT_OPTION,
f5e30c
+  DIRECT_OPTION
f5e30c
 };
f5e30c
 
f5e30c
 static struct option const long_options[] =
f5e30c
 {
f5e30c
   {"all", no_argument, NULL, 'a'},
f5e30c
   {"block-size", required_argument, NULL, 'B'},
f5e30c
+  {"direct", no_argument, NULL, DIRECT_OPTION},
f5e30c
   {"inodes", no_argument, NULL, 'i'},
f5e30c
   {"human-readable", no_argument, NULL, 'h'},
f5e30c
   {"si", no_argument, NULL, 'H'},
f5e30c
@@ -509,7 +514,10 @@ get_header (void)
f5e30c
   for (col = 0; col < ncolumns; col++)
f5e30c
     {
f5e30c
       char *cell = NULL;
f5e30c
-      char const *header = _(columns[col]->caption);
f5e30c
+      char const *header = (columns[col]->field == TARGET_FIELD
f5e30c
+                            && direct_statfs)?
f5e30c
+                            _("File") :
f5e30c
+                            _(columns[col]->caption);
f5e30c
 
f5e30c
       if (columns[col]->field == SIZE_FIELD
f5e30c
           && (header_mode == DEFAULT_MODE
f5e30c
@@ -1397,6 +1405,19 @@ get_point (const char *point, const struct stat *statp)
f5e30c
 static void
f5e30c
 get_entry (char const *name, struct stat const *statp)
f5e30c
 {
f5e30c
+  if (direct_statfs)
f5e30c
+    {
f5e30c
+      char *resolved = canonicalize_file_name (name);
f5e30c
+      if (resolved)
f5e30c
+	{
f5e30c
+         char *mp = find_mount_point (name, statp);
f5e30c
+	  get_dev (NULL, mp, resolved, NULL, NULL, false, false, NULL, false);
f5e30c
+         free(mp);
f5e30c
+	  free (resolved);
f5e30c
+	  return;
f5e30c
+	}
f5e30c
+    }
f5e30c
+
f5e30c
   if ((S_ISBLK (statp->st_mode) || S_ISCHR (statp->st_mode))
f5e30c
       && get_disk (name))
f5e30c
     return;
f5e30c
@@ -1467,6 +1488,7 @@ or all file systems by default.\n\
f5e30c
   -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,\n\
f5e30c
                            '-BM' prints sizes in units of 1,048,576 bytes;\n\
f5e30c
                            see SIZE format below\n\
f5e30c
+      --direct          show statistics for a file instead of mount point\n\
f5e30c
   -h, --human-readable  print sizes in powers of 1024 (e.g., 1023M)\n\
f5e30c
   -H, --si              print sizes in powers of 1000 (e.g., 1.1G)\n\
f5e30c
 "), stdout);
f5e30c
@@ -1557,6 +1579,9 @@ main (int argc, char **argv)
f5e30c
               xstrtol_fatal (e, oi, c, long_options, optarg);
f5e30c
           }
f5e30c
           break;
f5e30c
+        case DIRECT_OPTION:
f5e30c
+          direct_statfs = true;
f5e30c
+          break;
f5e30c
         case 'i':
f5e30c
           if (header_mode == OUTPUT_MODE)
f5e30c
             {
f5e30c
@@ -1653,6 +1678,13 @@ main (int argc, char **argv)
f5e30c
         }
f5e30c
     }
f5e30c
 
f5e30c
+  if (direct_statfs && show_local_fs)
f5e30c
+    {
f5e30c
+      error (0, 0, _("options --direct and --local (-l) are mutually "
f5e30c
+		     "exclusive"));
f5e30c
+      usage (EXIT_FAILURE);
f5e30c
+    }
f5e30c
+
f5e30c
   if (human_output_opts == -1)
f5e30c
     {
f5e30c
       if (posix_format)
f5e30c
diff --git a/tests/df/direct.sh b/tests/df/direct.sh
f5e30c
new file mode 100755
f5e30c
index 0000000..8e4cfb8
f5e30c
--- /dev/null
f5e30c
+++ b/tests/df/direct.sh
f5e30c
@@ -0,0 +1,55 @@
f5e30c
+#!/bin/sh
f5e30c
+# Ensure "df --direct" works as documented
f5e30c
+
f5e30c
+# Copyright (C) 2010 Free Software Foundation, Inc.
f5e30c
+
f5e30c
+# This program is free software: you can redistribute it and/or modify
f5e30c
+# it under the terms of the GNU General Public License as published by
f5e30c
+# the Free Software Foundation, either version 3 of the License, or
f5e30c
+# (at your option) any later version.
f5e30c
+
f5e30c
+# This program is distributed in the hope that it will be useful,
f5e30c
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
f5e30c
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f5e30c
+# GNU General Public License for more details.
f5e30c
+
f5e30c
+# You should have received a copy of the GNU General Public License
f5e30c
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
f5e30c
+
f5e30c
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
f5e30c
+print_ver_ df
f5e30c
+
f5e30c
+df || skip_ "df fails"
f5e30c
+
f5e30c
+DIR=`pwd` || framework_failure
f5e30c
+FILE="$DIR/file"
f5e30c
+touch "$FILE" || framework_failure
f5e30c
+echo "$FILE" > file_exp || framework_failure
f5e30c
+echo "Mounted on" > header_mounted_exp || framework_failure
f5e30c
+echo "File" > header_file_exp || framework_failure
f5e30c
+
f5e30c
+fail=0
f5e30c
+
f5e30c
+df --portability "$FILE" > df_out || fail=1
f5e30c
+df --portability --direct "$FILE" > df_direct_out || fail=1
f5e30c
+df --portability --direct --local "$FILE" > /dev/null 2>&1 && fail=1
f5e30c
+
f5e30c
+# check df header
f5e30c
+$AWK '{ if (NR==1) print $6 " " $7; }' df_out > header_mounted_out \
f5e30c
+  || framework_failure
f5e30c
+$AWK '{ if (NR==1) print $6; }' df_direct_out > header_file_out \
f5e30c
+  || framework_failure
f5e30c
+compare header_mounted_out header_mounted_exp || fail=1
f5e30c
+compare header_file_out header_file_exp || fail=1
f5e30c
+
f5e30c
+# check df output (without --direct)
f5e30c
+$AWK '{ if (NR==2) print $6; }' df_out > file_out \
f5e30c
+  || framework_failure
f5e30c
+compare file_out file_exp && fail=1
f5e30c
+
f5e30c
+# check df output (with --direct)
f5e30c
+$AWK '{ if (NR==2) print $6; }' df_direct_out > file_out \
f5e30c
+  || framework_failure
f5e30c
+compare file_out file_exp || fail=1
f5e30c
+
f5e30c
+Exit $fail