Skip to contentSkip to conversation

btrfs-progs: Use common unit parser for btrfs filesystem command

PATCH Applied Zhao Lei 2 participants 5 messages Sep 1, 2015

Subsystems (2)
lore
Share & tools
lore

Zhao Lei

author
#0 lore raw

v3 cover btrfs-progs: Use common unit parser for btrfs filesystem command

Changelog v2->v3:
Fix lacking of -T option in v2, pointed out by:
David Sterba <[email protected]>

Changelog v1->v2:
Keep short options for 'fi df' command, to keeps option compatibility with the standalone 'df' commmand, suggested-by:
David Sterba <[email protected]>

Zhao Lei (2):
btrfs-progs: Use common unit parser for btrfs filesystem command
btrfs-progs: Update manual for new unit arguments

 Documentation/btrfs-device.asciidoc     |  14 ++--
 Documentation/btrfs-filesystem.asciidoc |  14 ++--
 cmds-fi-usage.c                         |  63 +++--------------
 cmds-filesystem.c                       | 121 ++++----------------------------
 4 files changed, 32 insertions(+), 180 deletions(-)
Signature · 1 line
1.8.5.1
author
#1 lore raw

PATCH v3 1/2 btrfs-progs: Use common unit parser for btrfs filesystem command

Move to use get_unit_mode_from_arg() for cmds-filesystem.c, to make "btrfs filesystem df/show/usage"'s unit argument same.

Also have cleanup effect: 19 insertions(+), 181 deletions(-)

---
 cmds-fi-usage.c   |  63 ++++------------------------
 cmds-filesystem.c | 121 ++++++------------------------------------------------
 2 files changed, 20 insertions(+), 164 deletions(-)
cmds-fi-usage.c +8 -55
index adf1c27..ea967d1 100644
@@ -859,76 +859,29 @@ out:
 const char * const cmd_filesystem_usage_usage[] = {
 	"btrfs filesystem usage [options] <path> [<path>..]",
 	"Show detailed information about internal filesystem usage .",
-	"-b|--raw           raw numbers in bytes",
-	"-h|--human-readable",
-	"                   human friendly numbers, base 1024 (default)",
-	"-H                 human friendly numbers, base 1000",
-	"--iec              use 1024 as a base (KiB, MiB, GiB, TiB)",
-	"--si               use 1000 as a base (kB, MB, GB, TB)",
-	"-k|--kbytes        show sizes in KiB, or kB with --si",
-	"-m|--mbytes        show sizes in MiB, or MB with --si",
-	"-g|--gbytes        show sizes in GiB, or GB with --si",
-	"-t|--tbytes        show sizes in TiB, or TB with --si",
+	HELPINFO_OUTPUT_UNIT,
 	"-T                 show data in tabular format",
 	NULL
 };
 
 int cmd_filesystem_usage(int argc, char **argv)
 {
-	unsigned unit_mode = UNITS_DEFAULT;
 	int ret = 0;
-	int	i, more_than_one = 0;
-	int	tabular = 0;
+	unsigned unit_mode;
+	int i, more_than_one = 0;
+	int tabular = 0;
+
+	unit_mode = get_unit_mode_from_arg(&argc, argv, 0);
 
 	optind = 1;
 	while (1) {
 		int c;
-		static const struct option long_options[] = {
-			{ "raw", no_argument, NULL, 'b'},
-			{ "kbytes", no_argument, NULL, 'k'},
-			{ "mbytes", no_argument, NULL, 'm'},
-			{ "gbytes", no_argument, NULL, 'g'},
-			{ "tbytes", no_argument, NULL, 't'},
-			{ "si", no_argument, NULL, GETOPT_VAL_SI},
-			{ "iec", no_argument, NULL, GETOPT_VAL_IEC},
-			{ "human-readable", no_argument, NULL,
-				GETOPT_VAL_HUMAN_READABLE},
-			{ NULL, 0, NULL, 0 }
-		};
-
-		c = getopt_long(argc, argv, "bhHkmgtT", long_options, NULL);
 
+		c = getopt(argc, argv, "T");
 		if (c < 0)
 			break;
+
 		switch (c) {
-		case 'b':
-			unit_mode = UNITS_RAW;
-			break;
-		case 'k':
-			units_set_base(&unit_mode, UNITS_KBYTES);
-			break;
-		case 'm':
-			units_set_base(&unit_mode, UNITS_MBYTES);
-			break;
-		case 'g':
-			units_set_base(&unit_mode, UNITS_GBYTES);
-			break;
-		case 't':
-			units_set_base(&unit_mode, UNITS_TBYTES);
-			break;
-		case GETOPT_VAL_HUMAN_READABLE:
-		case 'h':
-			unit_mode = UNITS_HUMAN_BINARY;
-			break;
-		case 'H':
-			unit_mode = UNITS_HUMAN_DECIMAL;
-			break;
-		case GETOPT_VAL_SI:
-			units_set_mode(&unit_mode, UNITS_DECIMAL);
-			break;
-		case GETOPT_VAL_IEC:
-			units_set_mode(&unit_mode, UNITS_BINARY);
-			break;
 		case 'T':
 			tabular = 1;
 			break;
cmds-filesystem.c +12 -109

162 lines not on this page · raw message

Signature · 1 line
1.8.5.1
Applied
#2 lore raw
Quoted 6 lines · Zhao Lei

Move to use get_unit_mode_from_arg() for cmds-filesystem.c, to make "btrfs filesystem df/show/usage"'s unit argument same.

Also have cleanup effect: 19 insertions(+), 181 deletions(-)

Applied, thanks.

Quoted 14 lines
---
 cmds-fi-usage.c   |  63 ++++------------------------
 cmds-filesystem.c | 121 ++++++------------------------------------------------
 2 files changed, 20 insertions(+), 164 deletions(-)
cmds-fi-usage.c +0 -1
index adf1c27..ea967d1 100644
@@ -859,76 +859,29 @@ out:
 const char * const cmd_filesystem_usage_usage[] = {
 	"btrfs filesystem usage [options] <path> [<path>..]",
 	"Show detailed information about internal filesystem usage .",
-	"-b|--raw           raw numbers in bytes",

cmds-fi-usage.c out: · line 862

Quoted 10 lines
cmds-fi-usage.c +1 -9
-	"-h|--human-readable",
-	"                   human friendly numbers, base 1024 (default)",
-	"-H                 human friendly numbers, base 1000",
-	"--iec              use 1024 as a base (KiB, MiB, GiB, TiB)",
-	"--si               use 1000 as a base (kB, MB, GB, TB)",
-	"-k|--kbytes        show sizes in KiB, or kB with --si",
-	"-m|--mbytes        show sizes in MiB, or MB with --si",
-	"-g|--gbytes        show sizes in GiB, or GB with --si",
-	"-t|--tbytes        show sizes in TiB, or TB with --si",
+	HELPINFO_OUTPUT_UNIT,

HELPINFO_OUTPUT_UNIT_DF

author
#3 lore raw

PATCH v3 2/2 btrfs-progs: Update manual for new unit arguments

In reply to Zhao Lei

We changed unit arguments for btrfs commands, this patch updated relative documents for them.

---
 Documentation/btrfs-device.asciidoc     | 14 ++++++--------
 Documentation/btrfs-filesystem.asciidoc | 14 ++++++--------
 2 files changed, 12 insertions(+), 16 deletions(-)
Documentation/btrfs-device.asciidoc +6 -8
index 2827598..04bfde1 100644
@@ -106,23 +106,21 @@ Show detailed information about internal allocations in devices.
 +
 `Options`
 +
--b|--raw::::
+--raw::::
 raw numbers in bytes, without the 'B' suffix
--h|--human-readable::::
+--human-readable::::
 print human friendly numbers, base 1024, this is the default
--H::::
-print human friendly numbers, base 1000
 --iec::::
 select the 1024 base for the following options, according to the IEC standard
 --si::::
 select the 1000 base for the following options, according to the SI standard
--k|--kbytes::::
+--kbytes::::
 show sizes in KiB, or kB with --si
--m|--mbytes::::
+--mbytes::::
 show sizes in MiB, or MB with --si
--g|--gbytes::::
+--gbytes::::
 show sizes in GiB, or GB with --si
--t|--tbytes::::
+--tbytes::::
 show sizes in TiB, or TB with --si
 
 If conflicting options are passed, the last one takes precedence.
Documentation/btrfs-filesystem.asciidoc +6 -8
index 31cd51b..5d555fa 100644
@@ -160,23 +160,21 @@ Show detailed information about internal filesystem usage.
 +
 `Options`
 +
--b|--raw::::
+--raw::::
 raw numbers in bytes, without the 'B' suffix
--h|--human-readable::::
+--human-readable::::
 print human friendly numbers, base 1024, this is the default
--H::::
-print human friendly numbers, base 1000
 --iec::::
 select the 1024 base for the following options, according to the IEC standard
 --si::::
 select the 1000 base for the following options, according to the SI standard
--k|--kbytes::::
+--kbytes::::
 show sizes in KiB, or kB with --si
--m|--mbytes::::
+--mbytes::::
 show sizes in MiB, or MB with --si
--g|--gbytes::::
+--gbytes::::
 show sizes in GiB, or GB with --si
--t|--tbytes::::
+--tbytes::::
 show sizes in TiB, or TB with --si
 -T::::
 show data in tabular format
Signature · 1 line
1.8.5.1
#4 lore raw

Re: [PATCH v3 2/2] btrfs-progs: Update manual for new unit arguments

Quoted 2 lines · Zhao Lei

We changed unit arguments for btrfs commands, this patch updated relative documents for them.

Sorry, I must have missed that in the previous patches, the point is not to change the options. cmd_device_usage_usage should use th DF option variant. I'll fix that.