diff options
author | Pádraig Brady <P@draigBrady.com> | 2013-11-22 02:12:34 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2013-11-27 01:39:11 +0000 |
commit | 799e10f3619ea7949a4f606b2f29b662daf31e3c (patch) | |
tree | 6f7ad75a9639931e62a55bb2623fac149efc48f0 | |
parent | c3523181bd487539f308113620564756c29279cc (diff) | |
download | coreutils-799e10f3619ea7949a4f606b2f29b662daf31e3c.tar.xz |
df: add --output=file to directly output specified arguments
* src/df.c (usage): Document the new 'file' --output field.
(get_dev): Add a new parameter to pass the specified
argument from the command line through. Use '-' if a
command line parameter is not being used.
* doc/coreutils.texi (df invocation): Describe the new 'file' field.
* tests/df/df-output.sh: Adjust all fields test, and
add a specific test for --output=file.
* NEWS: Mention the new feature.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | doc/coreutils.texi | 2 | ||||
-rw-r--r-- | src/df.c | 33 | ||||
-rwxr-xr-x | tests/df/df-output.sh | 14 |
4 files changed, 40 insertions, 12 deletions
@@ -49,6 +49,9 @@ GNU coreutils NEWS -*- outline -*- ** New features + df --output now accepts a 'file' field, to propagate a specified + command line argument through to the output. + du accepts a new option: --inodes to show the number of inodes instead of the blocks used. diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 67feb125a..c7258ff5d 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -11213,6 +11213,8 @@ Number of available blocks. @item pcent Percentage of @var{used} divided by @var{size}. +@item file +The file name if specified on the command line. @item target The mount point. @end table @@ -143,7 +143,8 @@ typedef enum IUSED_FIELD, /* inodes used */ IAVAIL_FIELD, /* inodes available */ IPCENT_FIELD, /* inodes used in percent */ - TARGET_FIELD /* mount point */ + TARGET_FIELD, /* mount point */ + FILE_FIELD /* specified file name */ } display_field_t; /* Flag if a field contains a block, an inode or another value. */ @@ -199,11 +200,15 @@ static struct field_data_t field_data[] = { "ipcent", INODE_FLD, N_("IUse%"), 4, MBS_ALIGN_RIGHT, false }, [TARGET_FIELD] = { TARGET_FIELD, - "target", OTHER_FLD, N_("Mounted on"), 0, MBS_ALIGN_LEFT, false } + "target", OTHER_FLD, N_("Mounted on"), 0, MBS_ALIGN_LEFT, false }, + + [FILE_FIELD] = { FILE_FIELD, + "file", OTHER_FLD, N_("File"), 0, MBS_ALIGN_LEFT, false } }; static char const *all_args_string = - "source,fstype,itotal,iused,iavail,ipcent,size,used,avail,pcent,target"; + "source,fstype,itotal,iused,iavail,ipcent,size," + "used,avail,pcent,file,target"; /* Storage for the definition of output columns. */ static struct field_data_t **columns; @@ -403,6 +408,7 @@ decode_output_arg (char const *arg) case IAVAIL_FIELD: case IPCENT_FIELD: case TARGET_FIELD: + case FILE_FIELD: alloc_field (field, NULL); break; @@ -837,7 +843,7 @@ add_to_grand_total (struct field_values_t *bv, struct field_values_t *iv) when df is invoked with no non-option argument. See below for details. */ static void -get_dev (char const *disk, char const *mount_point, +get_dev (char const *disk, char const *mount_point, char const* file, char const *stat_file, char const *fstype, bool me_dummy, bool me_remote, const struct fs_usage *force_fsu, @@ -880,6 +886,9 @@ get_dev (char const *disk, char const *mount_point, if (! disk) disk = "-"; /* unknown */ + if (! file) + file = "-"; /* unspecified */ + char *dev_name = xstrdup (disk); char *resolved_dev; @@ -1011,6 +1020,10 @@ get_dev (char const *disk, char const *mount_point, break; } + case FILE_FIELD: + cell = xstrdup (file); + break; + case TARGET_FIELD: #ifdef HIDE_AUTOMOUNT_PREFIX /* Don't print the first directory name in MOUNT_POINT if it's an @@ -1054,7 +1067,7 @@ get_disk (char const *disk) if (best_match) { - get_dev (best_match->me_devname, best_match->me_mountdir, NULL, + get_dev (best_match->me_devname, best_match->me_mountdir, disk, NULL, best_match->me_type, best_match->me_dummy, best_match->me_remote, NULL, false); return true; @@ -1142,7 +1155,7 @@ get_point (const char *point, const struct stat *statp) } if (best_match) - get_dev (best_match->me_devname, best_match->me_mountdir, point, + get_dev (best_match->me_devname, best_match->me_mountdir, point, point, best_match->me_type, best_match->me_dummy, best_match->me_remote, NULL, false); else @@ -1155,7 +1168,7 @@ get_point (const char *point, const struct stat *statp) char *mp = find_mount_point (point, statp); if (mp) { - get_dev (NULL, mp, NULL, NULL, false, false, NULL, false); + get_dev (NULL, mp, point, NULL, NULL, false, false, NULL, false); free (mp); } } @@ -1186,7 +1199,7 @@ get_all_entries (void) filter_mount_list (); for (me = mount_list; me; me = me->me_next) - get_dev (me->me_devname, me->me_mountdir, NULL, me->me_type, + get_dev (me->me_devname, me->me_mountdir, NULL, NULL, me->me_type, me->me_dummy, me->me_remote, NULL, true); } @@ -1265,7 +1278,7 @@ or all file systems by default.\n\ fputs (_("\n\ FIELD_LIST is a comma-separated list of columns to be included. Valid\n\ field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',\n\ -'size', 'used', 'avail', 'pcent' and 'target' (see info page).\n\ +'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).\n\ "), stdout); emit_ancillary_info (); } @@ -1544,7 +1557,7 @@ main (int argc, char **argv) if (print_grand_total) get_dev ("total", (field_data[SOURCE_FIELD].used ? "-" : "total"), - NULL, NULL, false, false, &grand_fsu, false); + NULL, NULL, NULL, false, false, &grand_fsu, false); print_table (); } diff --git a/tests/df/df-output.sh b/tests/df/df-output.sh index a10f2706b..83cdc93ee 100755 --- a/tests/df/df-output.sh +++ b/tests/df/df-output.sh @@ -67,11 +67,11 @@ compare exp out || fail=1 # that --o (without argument) is identical to the full list. cat <<\EOF > exp || framework_failure_ -Filesystem Type Inodes IUsed IFree IUse% Size Used Avail Use% Mounted on +Filesystem Type Inodes IUsed IFree IUse% Size Used Avail Use% File Mounted on EOF df -h --o=source,fstype,itotal,iused,iavail,ipcent \ - --o=size,used,avail,pcent,target '.' >out || fail=1 + --o=size,used,avail,pcent,file,target '.' >out || fail=1 sed -e '1 { s/ [ ]*/ /g q @@ -127,4 +127,14 @@ compare exp out2 || fail=1 df --help > out || fail=1 grep ' --output' out >/dev/null || { fail=1; cat out; } +# Ensure that the FILE field contains the argument. +cat <<\EOF > exp || framework_failure_ +. +exp +EOF + +df --output=file '.' exp >out || fail=1 +sed '1d' out > out2 +compare exp out2 || fail=1 + Exit $fail |