Blame SOURCES/coreutils-df-direct.patch

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