740027
diff -urNp coreutils-8.21-orig/doc/coreutils.texi coreutils-8.21/doc/coreutils.texi
740027
--- coreutils-8.21-orig/doc/coreutils.texi	2013-02-11 10:37:28.000000000 +0100
740027
+++ coreutils-8.21/doc/coreutils.texi	2013-02-15 10:15:26.497593689 +0100
740027
@@ -10961,6 +10961,13 @@ pseudo-file-systems, such as automounter
740027
 Scale sizes by @var{size} before printing them (@pxref{Block size}).
740027
 For example, @option{-BG} prints sizes in units of 1,073,741,824 bytes.
740027
 
740027
+@item --direct
740027
+@opindex --direct
740027
+@cindex direct statfs for a file
740027
+Do not resolve mount point and show statistics directly for a file. It can be
740027
+especially useful for NFS mount points if there is a boundary between two
740027
+storage policies behind the mount point.
740027
+
740027
 @item --total
740027
 @opindex --total
740027
 @cindex grand total of disk size, usage and available space
740027
diff -urNp coreutils-8.21-orig/src/df.c coreutils-8.21/src/df.c
740027
--- coreutils-8.21-orig/src/df.c	2013-02-05 00:40:31.000000000 +0100
740027
+++ coreutils-8.21/src/df.c	2013-02-15 10:26:41.158651782 +0100
740027
@@ -116,6 +116,9 @@ static bool print_type;
740027
 /* If true, print a grand total at the end.  */
740027
 static bool print_grand_total;
740027
 
740027
+/* If true, show statistics for a file instead of mount point.  */
740027
+static bool direct_statfs;
740027
+
740027
 /* Grand total data.  */
740027
 static struct fs_usage grand_fsu;
740027
 
740027
@@ -238,13 +241,15 @@ enum
740027
   NO_SYNC_OPTION = CHAR_MAX + 1,
740027
   SYNC_OPTION,
740027
   TOTAL_OPTION,
740027
-  OUTPUT_OPTION
740027
+  OUTPUT_OPTION,
740027
+  DIRECT_OPTION
740027
 };
740027
 
740027
 static struct option const long_options[] =
740027
 {
740027
   {"all", no_argument, NULL, 'a'},
740027
   {"block-size", required_argument, NULL, 'B'},
740027
+  {"direct", no_argument, NULL, DIRECT_OPTION},
740027
   {"inodes", no_argument, NULL, 'i'},
740027
   {"human-readable", no_argument, NULL, 'h'},
740027
   {"si", no_argument, NULL, 'H'},
740027
@@ -500,7 +505,10 @@ get_header (void)
740027
   for (col = 0; col < ncolumns; col++)
740027
     {
740027
       char *cell = NULL;
740027
-      char const *header = _(columns[col]->caption);
740027
+      char const *header = (columns[col]->field == TARGET_FIELD
740027
+                            && direct_statfs)?
740027
+                            _("File") :
740027
+                            _(columns[col]->caption);
740027
 
740027
       if (columns[col]->field == SIZE_FIELD
740027
           && (header_mode == DEFAULT_MODE
740027
@@ -1150,6 +1158,19 @@ get_point (const char *point, const stru
740027
 static void
740027
 get_entry (char const *name, struct stat const *statp)
740027
 {
740027
+  if (direct_statfs)
740027
+    {
740027
+      char *resolved = canonicalize_file_name (name);
740027
+      if (resolved)
740027
+	{
740027
+         char *mp = find_mount_point (name, statp);
740027
+	  get_dev (NULL, mp, resolved, NULL, NULL, false, false, NULL, false);
740027
+         free(mp);
740027
+	  free (resolved);
740027
+	  return;
740027
+	}
740027
+    }
740027
+
740027
   if ((S_ISBLK (statp->st_mode) || S_ISCHR (statp->st_mode))
740027
       && get_disk (name))
740027
     return;
740027
@@ -1219,6 +1238,7 @@ or all file systems by default.\n\
740027
   -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,\n\
740027
                            '-BM' prints sizes in units of 1,048,576 bytes;\n\
740027
                            see SIZE format below\n\
740027
+      --direct          show statistics for a file instead of mount point\n\
740027
       --total           produce a grand total\n\
740027
   -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)\
740027
 \n\
740027
@@ -1305,6 +1325,9 @@ main (int argc, char **argv)
740027
               xstrtol_fatal (e, oi, c, long_options, optarg);
740027
           }
740027
           break;
740027
+        case DIRECT_OPTION:
740027
+          direct_statfs = true;
740027
+          break;
740027
         case 'i':
740027
           if (header_mode == OUTPUT_MODE)
740027
             {
740027
@@ -1408,6 +1431,13 @@ main (int argc, char **argv)
740027
         }
740027
     }
740027
 
740027
+  if (direct_statfs && show_local_fs)
740027
+    {
740027
+      error (0, 0, _("options --direct and --local (-l) are mutually "
740027
+		     "exclusive"));
740027
+      usage (EXIT_FAILURE);
740027
+    }
740027
+
740027
   if (human_output_opts == -1)
740027
     {
740027
       if (posix_format)
740027
diff -urNp coreutils-8.21-orig/tests/df/direct.sh coreutils-8.21/tests/df/direct.sh
740027
--- coreutils-8.21-orig/tests/df/direct.sh	1970-01-01 01:00:00.000000000 +0100
740027
+++ coreutils-8.21/tests/df/direct.sh	2013-02-15 10:15:26.503644446 +0100
740027
@@ -0,0 +1,55 @@
740027
+#!/bin/sh
740027
+# Ensure "df --direct" works as documented
740027
+
740027
+# Copyright (C) 2010 Free Software Foundation, Inc.
740027
+
740027
+# This program is free software: you can redistribute it and/or modify
740027
+# it under the terms of the GNU General Public License as published by
740027
+# the Free Software Foundation, either version 3 of the License, or
740027
+# (at your option) any later version.
740027
+
740027
+# This program is distributed in the hope that it will be useful,
740027
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
740027
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
740027
+# GNU General Public License for more details.
740027
+
740027
+# You should have received a copy of the GNU General Public License
740027
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
740027
+
740027
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
740027
+print_ver_ df
740027
+
740027
+df || skip_ "df fails"
740027
+
740027
+DIR=`pwd` || framework_failure
740027
+FILE="$DIR/file"
740027
+touch "$FILE" || framework_failure
740027
+echo "$FILE" > file_exp || framework_failure
740027
+echo "Mounted on" > header_mounted_exp || framework_failure
740027
+echo "File" > header_file_exp || framework_failure
740027
+
740027
+fail=0
740027
+
740027
+df --portability "$FILE" > df_out || fail=1
740027
+df --portability --direct "$FILE" > df_direct_out || fail=1
740027
+df --portability --direct --local "$FILE" > /dev/null 2>&1 && fail=1
740027
+
740027
+# check df header
740027
+$AWK '{ if (NR==1) print $6 " " $7; }' df_out > header_mounted_out \
740027
+  || framework_failure
740027
+$AWK '{ if (NR==1) print $6; }' df_direct_out > header_file_out \
740027
+  || framework_failure
740027
+compare header_mounted_out header_mounted_exp || fail=1
740027
+compare header_file_out header_file_exp || fail=1
740027
+
740027
+# check df output (without --direct)
740027
+$AWK '{ if (NR==2) print $6; }' df_out > file_out \
740027
+  || framework_failure
740027
+compare file_out file_exp && fail=1
740027
+
740027
+# check df output (with --direct)
740027
+$AWK '{ if (NR==2) print $6; }' df_direct_out > file_out \
740027
+  || framework_failure
740027
+compare file_out file_exp || fail=1
740027
+
740027
+Exit $fail