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