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