* [PATCH v3 0/2] btrfs-progs: Use common unit parser for btrfs filesystem command
@ 2015-09-01 7:12 Zhao Lei
2015-09-01 7:12 ` [PATCH v3 1/2] " Zhao Lei
2015-09-01 7:12 ` [PATCH v3 2/2] btrfs-progs: Update manual for new unit arguments Zhao Lei
0 siblings, 2 replies; 5+ messages in thread
From: Zhao Lei @ 2015-09-01 7:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Zhao Lei
Changelog v2->v3:
Fix lacking of -T option in v2, pointed out by:
David Sterba <dsterba@suse.cz>
Changelog v1->v2:
Keep short options for 'fi df' command, to keeps option compatibility
with the standalone 'df' commmand, suggested-by:
David Sterba <dsterba@suse.cz>
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
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(-)
--
1.8.5.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/2] btrfs-progs: Use common unit parser for btrfs filesystem command
2015-09-01 7:12 [PATCH v3 0/2] btrfs-progs: Use common unit parser for btrfs filesystem command Zhao Lei
@ 2015-09-01 7:12 ` Zhao Lei
2015-09-01 9:53 ` David Sterba
2015-09-01 7:12 ` [PATCH v3 2/2] btrfs-progs: Update manual for new unit arguments Zhao Lei
1 sibling, 1 reply; 5+ messages in thread
From: Zhao Lei @ 2015-09-01 7:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: 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(-)
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
cmds-fi-usage.c | 63 ++++------------------------
cmds-filesystem.c | 121 ++++++------------------------------------------------
2 files changed, 20 insertions(+), 164 deletions(-)
diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
index adf1c27..ea967d1 100644
--- a/cmds-fi-usage.c
+++ b/cmds-fi-usage.c
@@ -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;
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index fa555b0..8822695 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -121,19 +121,10 @@ static const char * const filesystem_cmd_group_usage[] = {
};
static const char * const cmd_filesystem_df_usage[] = {
- "btrfs filesystem df [options] <path>",
- "Show space usage information for a mount point",
- "-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",
- NULL
+ "btrfs filesystem df [options] <path>",
+ "Show space usage information for a mount point",
+ HELPINFO_OUTPUT_UNIT_DF,
+ NULL
};
static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
@@ -205,64 +196,14 @@ static int cmd_filesystem_df(int argc, char **argv)
int fd;
char *path;
DIR *dirstream = NULL;
- unsigned unit_mode = UNITS_DEFAULT;
+ unsigned unit_mode;
- 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, "bhHkmgt", long_options, NULL);
- 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;
- default:
- usage(cmd_filesystem_df_usage);
- }
- }
+ unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
- if (check_argc_exact(argc, optind + 1))
+ if (argc != 2 || argv[1][0] == '-')
usage(cmd_filesystem_df_usage);
- path = argv[optind];
+ path = argv[1];
fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
@@ -820,14 +761,7 @@ static const char * const cmd_filesystem_show_usage[] = {
"Show the structure of a filesystem",
"-d|--all-devices show only disks under /dev containing btrfs filesystem",
"-m|--mounted show only mounted btrfs",
- "--raw raw numbers in bytes",
- "--human-readable human friendly numbers, base 1024 (default)",
- "--iec use 1024 as a base (KiB, MiB, GiB, TiB)",
- "--si use 1000 as a base (kB, MB, GB, TB)",
- "--kbytes show sizes in KiB, or kB with --si",
- "--mbytes show sizes in MiB, or MB with --si",
- "--gbytes show sizes in GiB, or GB with --si",
- "--tbytes show sizes in TiB, or TB with --si",
+ HELPINFO_OUTPUT_UNIT,
"If no argument is given, structure of all present filesystems is shown.",
NULL
};
@@ -845,23 +779,16 @@ static int cmd_filesystem_show(int argc, char **argv)
char path[PATH_MAX];
__u8 fsid[BTRFS_FSID_SIZE];
char uuid_buf[BTRFS_UUID_UNPARSED_SIZE];
- unsigned unit_mode = UNITS_DEFAULT;
+ unsigned unit_mode;
int found = 0;
+ unit_mode = get_unit_mode_from_arg(&argc, argv, 0);
+
while (1) {
int c;
static const struct option long_options[] = {
{ "all-devices", no_argument, NULL, 'd'},
{ "mounted", no_argument, NULL, 'm'},
- { "raw", no_argument, NULL, GETOPT_VAL_RAW},
- { "kbytes", no_argument, NULL, GETOPT_VAL_KBYTES},
- { "mbytes", no_argument, NULL, GETOPT_VAL_MBYTES},
- { "gbytes", no_argument, NULL, GETOPT_VAL_GBYTES},
- { "tbytes", no_argument, NULL, GETOPT_VAL_TBYTES},
- { "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 }
};
@@ -875,30 +802,6 @@ static int cmd_filesystem_show(int argc, char **argv)
case 'm':
where = BTRFS_SCAN_MOUNTED;
break;
- case GETOPT_VAL_RAW:
- units_set_mode(&unit_mode, UNITS_RAW);
- break;
- case GETOPT_VAL_KBYTES:
- units_set_base(&unit_mode, UNITS_KBYTES);
- break;
- case GETOPT_VAL_MBYTES:
- units_set_base(&unit_mode, UNITS_MBYTES);
- break;
- case GETOPT_VAL_GBYTES:
- units_set_base(&unit_mode, UNITS_GBYTES);
- break;
- case GETOPT_VAL_TBYTES:
- units_set_base(&unit_mode, UNITS_TBYTES);
- 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 GETOPT_VAL_HUMAN_READABLE:
- units_set_mode(&unit_mode, UNITS_HUMAN_BINARY);
- break;
default:
usage(cmd_filesystem_show_usage);
}
--
1.8.5.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] btrfs-progs: Update manual for new unit arguments
2015-09-01 7:12 [PATCH v3 0/2] btrfs-progs: Use common unit parser for btrfs filesystem command Zhao Lei
2015-09-01 7:12 ` [PATCH v3 1/2] " Zhao Lei
@ 2015-09-01 7:12 ` Zhao Lei
2015-09-01 9:44 ` David Sterba
1 sibling, 1 reply; 5+ messages in thread
From: Zhao Lei @ 2015-09-01 7:12 UTC (permalink / raw)
To: linux-btrfs; +Cc: Zhao Lei
We changed unit arguments for btrfs commands, this patch updated
relative documents for them.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
Documentation/btrfs-device.asciidoc | 14 ++++++--------
Documentation/btrfs-filesystem.asciidoc | 14 ++++++--------
2 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/Documentation/btrfs-device.asciidoc b/Documentation/btrfs-device.asciidoc
index 2827598..04bfde1 100644
--- a/Documentation/btrfs-device.asciidoc
+++ b/Documentation/btrfs-device.asciidoc
@@ -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.
diff --git a/Documentation/btrfs-filesystem.asciidoc b/Documentation/btrfs-filesystem.asciidoc
index 31cd51b..5d555fa 100644
--- a/Documentation/btrfs-filesystem.asciidoc
+++ b/Documentation/btrfs-filesystem.asciidoc
@@ -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
--
1.8.5.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] btrfs-progs: Update manual for new unit arguments
2015-09-01 7:12 ` [PATCH v3 2/2] btrfs-progs: Update manual for new unit arguments Zhao Lei
@ 2015-09-01 9:44 ` David Sterba
0 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2015-09-01 9:44 UTC (permalink / raw)
To: Zhao Lei; +Cc: linux-btrfs
On Tue, Sep 01, 2015 at 03:12:07PM +0800, Zhao Lei wrote:
> 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] btrfs-progs: Use common unit parser for btrfs filesystem command
2015-09-01 7:12 ` [PATCH v3 1/2] " Zhao Lei
@ 2015-09-01 9:53 ` David Sterba
0 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2015-09-01 9:53 UTC (permalink / raw)
To: Zhao Lei; +Cc: linux-btrfs
On Tue, Sep 01, 2015 at 03:12:06PM +0800, Zhao Lei wrote:
> 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(-)
>
> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Applied, thanks.
> ---
> cmds-fi-usage.c | 63 ++++------------------------
> cmds-filesystem.c | 121 ++++++------------------------------------------------
> 2 files changed, 20 insertions(+), 164 deletions(-)
>
> diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
> index adf1c27..ea967d1 100644
> --- a/cmds-fi-usage.c
> +++ b/cmds-fi-usage.c
> @@ -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,
HELPINFO_OUTPUT_UNIT_DF
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-09-01 9:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-01 7:12 [PATCH v3 0/2] btrfs-progs: Use common unit parser for btrfs filesystem command Zhao Lei
2015-09-01 7:12 ` [PATCH v3 1/2] " Zhao Lei
2015-09-01 9:53 ` David Sterba
2015-09-01 7:12 ` [PATCH v3 2/2] btrfs-progs: Update manual for new unit arguments Zhao Lei
2015-09-01 9:44 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.