Blame SOURCES/coreutils-df-direct.patch

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