From: Dieter Ries <lists@dieterries.net>
To: Ian Kumlien <pomac@demius.net>
Cc: linux-btrfs@vger.kernel.org, David Sterba <dsterba@suse.cz>
Subject: Re: [PATCH 2/6] Btrfs-progs: add btrfsck functionality to btrfs
Date: Sun, 02 Jun 2013 17:47:38 +0200 [thread overview]
Message-ID: <51AB691A.90605@dieterries.net> (raw)
In-Reply-To: <1360283822-23452-3-git-send-email-pomac@demius.net>
[-- Attachment #1: Type: text/plain, Size: 963 bytes --]
Hi everybody,
Am 08.02.2013 01:36, schrieb Ian Kumlien:
> diff --git a/cmds-check.c b/cmds-check.c
> index 71e98de..8e4cce0 100644
> --- a/cmds-check.c
> +++ b/cmds-check.c
[...]
> @@ -3574,7 +3579,8 @@ int main(int ac, char **av)
> (unsigned long long)bytenr);
> break;
> case '?':
> - print_usage();
> + case 'h':
> + usage(cmd_check_usage);
> }
> if (option_index == 1) {
> printf("enabling repair mode\n");
For this to have any effect, 'h' must be added to getopt_long(), see
attached patch 1.
However, this results in btrfsck -h and --help doing different things:
--help prints the usage message to stdout and exits with exit(0).
-h prints the usage message to stderr and exits with exit(129).
I made a patch to fix this, see attached patch 2.
What it doesn't fix though is, that -h/--help and -? don't do the same
thing. This is more complicated, as getop_long returns '?' for unknown
options.
Cheers,
Dieter
[-- Attachment #2: 0001-Btrfs-progs-Fix-btrfsck-btrfs-check-h.patch --]
[-- Type: text/x-patch, Size: 758 bytes --]
>From 11aabdb018aed3c5b6a1616178883fd879152856 Mon Sep 17 00:00:00 2001
From: Dieter Ries <mail@dieterries.net>
Date: Sun, 2 Jun 2013 17:30:09 +0200
Subject: [PATCH 1/2] Btrfs-progs: Fix 'btrfsck/btrfs check -h'
For the '-h' option to be usable, getopts_long() has to know it.
Signed-off-by: Dieter Ries <mail@dieterries.net>
---
cmds-check.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmds-check.c b/cmds-check.c
index 1e5e005..ff9298d 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4065,7 +4065,7 @@ int cmd_check(int argc, char **argv)
while(1) {
int c;
- c = getopt_long(argc, argv, "as:", long_options,
+ c = getopt_long(argc, argv, "ahs:", long_options,
&option_index);
if (c < 0)
break;
--
1.8.1.3
[-- Attachment #3: 0002-Btrfs-progs-Fix-help-to-h-inconsistency-in-btrfsck-b.patch --]
[-- Type: text/x-patch, Size: 2207 bytes --]
>From 52d9e47bfa0936a14baa48e8ad6ecdd820295809 Mon Sep 17 00:00:00 2001
From: Dieter Ries <mail@dieterries.net>
Date: Sun, 2 Jun 2013 17:32:15 +0200
Subject: [PATCH 2/2] Btrfs-progs: Fix '--help' to '-h' inconsistency in
btrfsck/btrfs check
This patch fixes the following inconsistency between calling
btrfsck/btrfs check with the -h or --help options:
--help prints the usage message to stdout and exits with exit(0).
-h prints the usage message to stderr and exits with exit(129).
To achieve this, usage_command_usagestr() is made avalilable via
commands.h.
Signed-off-by: Dieter Ries <mail@dieterries.net>
---
cmds-check.c | 5 ++++-
commands.h | 2 ++
help.c | 2 +-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/cmds-check.c b/cmds-check.c
index ff9298d..093c859 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4078,8 +4078,11 @@ int cmd_check(int argc, char **argv)
(unsigned long long)bytenr);
break;
case '?':
- case 'h':
usage(cmd_check_usage);
+ break;
+ case 'h':
+ usage_command_usagestr(cmd_check_usage, "check", 1, 0);
+ exit(0);
}
if (option_index == 1) {
printf("enabling repair mode\n");
diff --git a/commands.h b/commands.h
index 15c616d..814452f 100644
--- a/commands.h
+++ b/commands.h
@@ -73,6 +73,8 @@ extern const char * const generic_cmd_help_usage[];
void usage(const char * const *usagestr);
void usage_command(const struct cmd_struct *cmd, int full, int err);
void usage_command_group(const struct cmd_group *grp, int all, int err);
+void usage_command_usagestr(const char * const *usagestr,
+ const char *token, int full, int err);
void help_unknown_token(const char *arg, const struct cmd_group *grp);
void help_ambiguous_token(const char *arg, const struct cmd_group *grp);
diff --git a/help.c b/help.c
index 6d04293..effb72e 100644
--- a/help.c
+++ b/help.c
@@ -102,7 +102,7 @@ static int usage_command_internal(const char * const *usagestr,
return ret;
}
-static void usage_command_usagestr(const char * const *usagestr,
+void usage_command_usagestr(const char * const *usagestr,
const char *token, int full, int err)
{
FILE *outf = err ? stderr : stdout;
--
1.8.1.3
next prev parent reply other threads:[~2013-06-02 15:57 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-08 0:36 Btrfs-progs: Merge btrfs-restore, btrfsck, btrfs-select-super, btrfs-dump-super and btrfs-debug-tree in to btrfs Ian Kumlien
2013-02-08 0:36 ` [PATCH 1/6] Btrfs-progs: Rename btrfsck.c -> cmds-check.c Ian Kumlien
2013-02-08 0:36 ` [PATCH 2/6] Btrfs-progs: add btrfsck functionality to btrfs Ian Kumlien
2013-02-08 17:39 ` Goffredo Baroncelli
2013-02-08 18:17 ` Ian Kumlien
2013-02-08 23:07 ` David Sterba
2013-02-08 23:37 ` Ian Kumlien
2013-02-12 16:39 ` David Sterba
2013-02-12 17:37 ` Filipe Brandenburger
2013-02-12 18:01 ` Goffredo Baroncelli
2013-02-12 22:52 ` David Sterba
2013-02-12 23:07 ` Goffredo Baroncelli
2013-06-02 15:47 ` Dieter Ries [this message]
2013-11-13 17:13 ` David Sterba
2013-11-14 9:25 ` Ilya Dryomov
2013-11-14 12:49 ` David Sterba
2013-11-14 12:56 ` Ian Kumlien
2013-02-08 0:36 ` [PATCH 3/6] Btrfs-progs: move btrfs-select-super.c Ian Kumlien
2013-02-08 0:37 ` [PATCH 4/6] Btrfs-progs: move debug-tree.c -> cmds-rescue-debug-tree.c Ian Kumlien
2013-02-08 0:37 ` [PATCH 5/6] Btrfs-progs: restore.c -> cmds-restore.c Ian Kumlien
2013-02-08 0:37 ` [PATCH 6/6] Btrfs-progs: add the rescue section to btrfs Ian Kumlien
2013-02-08 17:39 ` Goffredo Baroncelli
2013-02-08 18:07 ` Ian Kumlien
2013-02-08 19:57 ` Ilya Dryomov
2013-02-08 20:48 ` Hugo Mills
2013-02-08 22:30 ` David Sterba
2013-02-12 15:26 ` David Sterba
2013-02-08 17:40 ` Btrfs-progs: Merge btrfs-restore, btrfsck, btrfs-select-super, btrfs-dump-super and btrfs-debug-tree in " Goffredo Baroncelli
2013-02-08 18:05 ` Ian Kumlien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51AB691A.90605@dieterries.net \
--to=lists@dieterries.net \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=pomac@demius.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.