>From 64177cdfedc264d3cb1cc3b94adddd49c8781334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Fri, 22 Nov 2013 02:12:34 +0000 Subject: [PATCH] df: support outputting specified arguments directly * src/df.c (usage): Document the new 'name' parameter to the --output option. (get_dev): Add a new parameter to pass the specified argument from the command line through. Use '-' if a command line paramater is not being used. * doc/coreutils.texi (df invocation): Describe the new 'name' parameter. * tests/df/df-output.sh: Adjust accordingly. * NEWS: Mention the new feature. --- NEWS | 3 +++ doc/coreutils.texi | 2 ++ src/df.c | 33 +++++++++++++++++++++++---------- tests/df/df-output.sh | 4 ++-- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index b6dab62..a631517 100644 --- a/NEWS +++ b/NEWS @@ -49,6 +49,9 @@ GNU coreutils NEWS -*- outline -*- ** New features + df --output now accepts a 'name' 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 035f2e6..2c9ed8c 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -11210,6 +11210,8 @@ Number of available blocks. @item pcent Percentage of @var{used} divided by @var{size}. +@item name +The name if specified on the command line. @item target The mount point. @end table diff --git a/src/df.c b/src/df.c index 949fe2f..f9c3a24 100644 --- a/src/df.c +++ b/src/df.c @@ -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 */ + NAME_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 }, + + [NAME_FIELD] = { NAME_FIELD, + "name", OTHER_FLD, N_("Name"), 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,name,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 NAME_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* name, 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 (! name) + name = "-"; /* unspecified */ + char *dev_name = xstrdup (disk); char *resolved_dev; @@ -1011,6 +1020,10 @@ get_dev (char const *disk, char const *mount_point, break; } + case NAME_FIELD: + cell = xstrdup (name); + 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', 'name' 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 a10f270..6513ce4 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% Name 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,name,target '.' >out || fail=1 sed -e '1 { s/ [ ]*/ /g q -- 1.7.7.6