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