Blame SOURCES/coreutils-df-direct.patch

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