changeset 13891:4a1840e41e13

3327 Add -m flag to df Reviewed by: Richard Lowe <richlowe@richlowe.net> Reviewed by: Garrett D'Amore <garrett@damore.org> Approved by: Eric Schrock <eric.schrock@delpihx.com>
author Paul B. Henson <henson@acm.org>
date Fri, 30 Nov 2012 06:26:32 -0800
parents dbad2fa7c9bb
children 3e7a63d0e0ea
files usr/src/cmd/fs.d/df.c usr/src/man/man1m/df.1m
diffstat 2 files changed, 47 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/fs.d/df.c	Sat Nov 24 22:02:34 2012 +0000
+++ b/usr/src/cmd/fs.d/df.c	Fri Nov 30 06:26:32 2012 -0800
@@ -217,6 +217,7 @@
 static bool_int		h_option;
 static bool_int		k_option;
 static bool_int		l_option;
+static bool_int		m_option;
 static bool_int		n_option;
 static bool_int		t_option;
 static bool_int		o_option;
@@ -342,11 +343,13 @@
 {
 #ifdef  XPG4
 	errmsg(ERR_NONAME,
-	    "Usage: %s [-F FSType] [-abeghklntPVZ] [-o FSType-specific_options]"
+	    "Usage: %s [-F FSType] [-abeghklmntPVZ]"
+	    " [-o FSType-specific_options]"
 	    " [directory | block_device | resource]", program_name);
 #else
 	errmsg(ERR_NONAME,
-	    "Usage: %s [-F FSType] [-abeghklntVvZ] [-o FSType-specific_options]"
+	    "Usage: %s [-F FSType] [-abeghklmntVvZ]"
+	    " [-o FSType-specific_options]"
 	    " [directory | block_device | resource]", program_name);
 #endif
 	exit(1);
@@ -578,9 +581,9 @@
 	opterr = 0;	/* getopt shouldn't complain about unknown options */
 
 #ifdef XPG4
-	while ((arg = getopt(argc, argv, "F:o:abehkVtgnlPZ")) != EOF) {
+	while ((arg = getopt(argc, argv, "F:o:abehkVtgnlmPZ")) != EOF) {
 #else
-	while ((arg = getopt(argc, argv, "F:o:abehkVtgnlvZ")) != EOF) {
+	while ((arg = getopt(argc, argv, "F:o:abehkVtgnlmvZ")) != EOF) {
 #endif
 		if (arg == 'F') {
 			if (F_option)
@@ -611,6 +614,8 @@
 			SET_OPTION(k);
 		} else if (arg == 'l' && ! l_option) {
 			SET_OPTION(l);
+		} else if (arg == 'm' && ! m_option) {
+			SET_OPTION(m);
 		} else if (arg == 'n' && ! n_option) {
 			SET_OPTION(n);
 		} else if (arg == 't' && ! t_option) {
@@ -1107,6 +1112,19 @@
 		SET_OPTION(h);
 		return;
 	}
+	if (m_option) {
+		int arg = 'h';
+
+		(void) printf(gettext("%-*s %*s %*s %*s %-*s %s\n"),
+		    FILESYSTEM_WIDTH, TRANSLATE("Filesystem"),
+		    KBYTE_WIDTH, TRANSLATE("mbytes"),
+		    KBYTE_WIDTH, TRANSLATE("used"),
+		    KBYTE_WIDTH, TRANSLATE("avail"),
+		    CAPACITY_WIDTH, TRANSLATE("capacity"),
+		    TRANSLATE("Mounted on"));
+		SET_OPTION(h);
+		return;
+	}
 	/* Added for XCU4 compliance */
 	if (P_option) {
 		int arg = 'h';
@@ -1527,7 +1545,7 @@
 		return;
 	}
 
-	if (P_option && !k_option) {
+	if (P_option && !k_option && !m_option) {
 	(void) printf("%-*s %*s %*s %*s %-*s %-s\n",
 	    FILESYSTEM_WIDTH, file_system,
 	    KBYTE_WIDTH, number_to_string(total_blocks_buf,
@@ -1538,6 +1556,17 @@
 	    available_blocks, fsp->f_frsize, 512),
 	    CAPACITY_WIDTH, capacity_buf,
 	    DFR_MOUNT_POINT(dfrp));
+	} else if (m_option) {
+	(void) printf("%-*s %*s %*s %*s %-*s %-s\n",
+	    FILESYSTEM_WIDTH, file_system,
+	    KBYTE_WIDTH, number_to_string(total_blocks_buf,
+	    total_blocks, fsp->f_frsize, 1024*1024),
+	    KBYTE_WIDTH, number_to_string(used_blocks_buf,
+	    used_blocks, fsp->f_frsize, 1024*1024),
+	    KBYTE_WIDTH, number_to_string(available_blocks_buf,
+	    available_blocks, fsp->f_frsize, 1024*1024),
+	    CAPACITY_WIDTH,	capacity_buf,
+	    DFR_MOUNT_POINT(dfrp));
 	} else {
 	(void) printf("%-*s %*s %*s %*s %-*s %-s\n",
 	    FILESYSTEM_WIDTH, file_system,
@@ -1955,7 +1984,7 @@
 	} else if (g_option) {
 		dfo.dfo_func = g_output;
 		dfo.dfo_flags = DFO_STATVFS;
-	} else if (k_option || P_option || v_option) {
+	} else if (k_option || m_option || P_option || v_option) {
 		dfo.dfo_func = k_output;
 		dfo.dfo_flags = DFO_HEADER + DFO_STATVFS;
 	} else if (t_option) {
--- a/usr/src/man/man1m/df.1m	Sat Nov 24 22:02:34 2012 +0000
+++ b/usr/src/man/man1m/df.1m	Fri Nov 30 06:26:32 2012 -0800
@@ -16,14 +16,14 @@
 .SH SYNOPSIS
 .LP
 .nf
-\fB/usr/bin/df\fR [\fB-F\fR \fIFSType\fR] [\fB-abeghklntVvZ\fR]
+\fB/usr/bin/df\fR [\fB-F\fR \fIFSType\fR] [\fB-abeghklmntVvZ\fR]
      [\fB-o\fR \fIFSType-specific_options\fR]
      [\fIblock_device\fR | \fIdirectory\fR | \fIfile\fR | \fIresource\fR ...]
 .fi
 
 .LP
 .nf
-\fB/usr/xpg4/bin/df\fR [\fB-F\fR \fIFSType\fR] [\fB-abeghklnPtVZ\fR]
+\fB/usr/xpg4/bin/df\fR [\fB-F\fR \fIFSType\fR] [\fB-abeghklmnPtVZ\fR]
      [\fB-o\fR \fIFSType-specific_options\fR]
      [\fIblock_device\fR | \fIdirectory\fR | \fIfile\fR | \fIresource\fR ...]
 .fi
@@ -161,6 +161,16 @@
 .sp
 .ne 2
 .na
+\fB\fB-m\fR\fR
+.ad
+.sp .6
+.RS 4n
+Like -k, except prints the allocation in mbytes.
+.RE
+
+.sp
+.ne 2
+.na
 \fB\fB-n\fR\fR
 .ad
 .sp .6