Ondřej Vašík 4c4be9
diff -urNp coreutils-8.21-orig/doc/coreutils.texi coreutils-8.21/doc/coreutils.texi
Ondřej Vašík 4c4be9
--- coreutils-8.21-orig/doc/coreutils.texi	2013-02-11 10:37:28.000000000 +0100
Ondřej Vašík 4c4be9
+++ coreutils-8.21/doc/coreutils.texi	2013-02-15 10:15:26.497593689 +0100
Ondřej Vašík 4c4be9
@@ -10961,6 +10961,13 @@ pseudo-file-systems, such as automounter
Kamil Dudka d05927
 Scale sizes by @var{size} before printing them (@pxref{Block size}).
Kamil Dudka d05927
 For example, @option{-BG} prints sizes in units of 1,073,741,824 bytes.
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
Ondřej Vašík 4c4be9
diff -urNp coreutils-8.21-orig/src/df.c coreutils-8.21/src/df.c
Ondřej Vašík 4c4be9
--- coreutils-8.21-orig/src/df.c	2013-02-05 00:40:31.000000000 +0100
Ondřej Vašík 4c4be9
+++ coreutils-8.21/src/df.c	2013-02-15 10:26:41.158651782 +0100
Ondřej Vašík 4c4be9
@@ -116,6 +116,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
 
Ondřej Vašík 4c4be9
@@ -238,13 +241,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'},
Ondřej Vašík 4c4be9
@@ -500,7 +505,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
Ondřej Vašík bb33bc
@@ -1150,6 +1158,19 @@ get_point (const char *point, const stru
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;
Ondřej Vašík 4c4be9
@@ -1219,6 +1238,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\
Kamil Dudka d05927
       --total           produce a grand total\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 4c4be9
@@ -1305,6 +1325,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
             {
Ondřej Vašík 4c4be9
@@ -1408,6 +1431,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)
Ondřej Vašík 4c4be9
diff -urNp coreutils-8.21-orig/tests/df/direct.sh coreutils-8.21/tests/df/direct.sh
Ondřej Vašík 4c4be9
--- coreutils-8.21-orig/tests/df/direct.sh	1970-01-01 01:00:00.000000000 +0100
Ondřej Vašík 4c4be9
+++ coreutils-8.21/tests/df/direct.sh	2013-02-15 10:15:26.503644446 +0100
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