Ondřej Vašík 50a3ba
diff -urNp coreutils-8.11-orig/doc/coreutils.texi coreutils-8.11/doc/coreutils.texi
Ondřej Vašík 50a3ba
--- coreutils-8.11-orig/doc/coreutils.texi	2011-04-12 12:07:43.000000000 +0200
Ondřej Vašík 50a3ba
+++ coreutils-8.11/doc/coreutils.texi	2011-04-14 09:53:43.764309420 +0200
Ondřej Vašík 50a3ba
@@ -10409,6 +10409,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
 
Kamil Dudka d05927
+@itemx --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
+
Kamil Dudka d05927
 @itemx --total
Kamil Dudka d05927
 @opindex --total
Kamil Dudka d05927
 @cindex grand total of disk size, usage and available space
Ondřej Vašík 50a3ba
diff -urNp coreutils-8.11-orig/src/df.c coreutils-8.11/src/df.c
Ondřej Vašík 50a3ba
--- coreutils-8.11-orig/src/df.c	2011-04-12 12:07:43.000000000 +0200
Ondřej Vašík 50a3ba
+++ coreutils-8.11/src/df.c	2011-04-14 10:37:44.208308771 +0200
Ondřej Vašík 50a3ba
@@ -112,6 +112,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
+
Kamil Dudka d05927
 /* Grand total data. */
Kamil Dudka d05927
 static struct fs_usage grand_fsu;
Kamil Dudka d05927
 
Ondřej Vašík 50a3ba
@@ -166,13 +169,15 @@ static size_t nrows;
Kamil Dudka d05927
 enum
Kamil Dudka d05927
 {
Kamil Dudka d05927
   NO_SYNC_OPTION = CHAR_MAX + 1,
Kamil Dudka d05927
-  SYNC_OPTION
Kamil Dudka d05927
+  SYNC_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 50a3ba
@@ -259,7 +264,11 @@ get_header (void)
Ondřej Vašík 50a3ba
         }
Kamil Dudka d05927
 
Ondřej Vašík 50a3ba
       char *cell = NULL;
Ondřej Vašík 50a3ba
-      char const *header = _(headers[field][header_mode]);
Ondřej Vašík 50a3ba
+     
Ondřej Vašík 50a3ba
+      char const *header = (field == MNT_FIELD && direct_statfs)?
Ondřej Vašík d79f57
+                             _("File") :
Ondřej Vašík 50a3ba
+                             _(headers[field][header_mode]);
Ondřej Vašík 50a3ba
+
Ondřej Vašík 50a3ba
       if (!header)
Ondřej Vašík 50a3ba
         header = _(headers[field][DEFAULT_MODE]);
Kamil Dudka d05927
 
Ondřej Vašík 50a3ba
@@ -757,6 +766,17 @@ 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 50a3ba
+	  get_dev (NULL, resolved, NULL, NULL, false, false, NULL);
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 50a3ba
@@ -825,6 +845,7 @@ Mandatory arguments to long options are 
Ondřej Vašík 98ff9f
   -B, --block-size=SIZE  scale sizes by SIZE before printing them.  E.g.,\n\
Ondřej Vašík 98ff9f
                            `-BM' prints sizes in units of 1,048,576 bytes.\n\
Ondřej Vašík 98ff9f
                            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 58ba6d
   -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)\
Ondřej Vašík 58ba6d
 \n\
Ondřej Vašík 50a3ba
@@ -901,6 +922,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':
Kamil Dudka d05927
           inode_format = true;
Kamil Dudka d05927
           break;
Ondřej Vašík 50a3ba
@@ -961,6 +985,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 50a3ba
diff -urNp coreutils-8.11-orig/tests/df/direct coreutils-8.11/tests/df/direct
Ondřej Vašík 50a3ba
--- coreutils-8.11-orig/tests/df/direct	1970-01-01 01:00:00.000000000 +0100
Ondřej Vašík 50a3ba
+++ coreutils-8.11/tests/df/direct	2011-04-14 09:53:43.767400034 +0200
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
Ondřej Vašík 50a3ba
diff -urNp coreutils-8.11-orig/tests/Makefile.am coreutils-8.11/tests/Makefile.am
Ondřej Vašík 50a3ba
--- coreutils-8.11-orig/tests/Makefile.am	2011-04-14 09:53:13.666324768 +0200
Ondřej Vašík 50a3ba
+++ coreutils-8.11/tests/Makefile.am	2011-04-14 09:53:43.768432620 +0200
Ondřej Vašík 50a3ba
@@ -362,6 +362,7 @@ TESTS =						\
Ondřej Vašík 58ba6d
   dd/stderr					\
Ondřej Vašík 58ba6d
   dd/unblock					\
Ondřej Vašík 58ba6d
   dd/unblock-sync				\
Ondřej Vašík 58ba6d
+  df/direct					\
Ondřej Vašík 58ba6d
   df/total-verify				\
Ondřej Vašík 58ba6d
   du/2g						\
Ondřej Vašík 58ba6d
   du/8gb					\