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