From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH] gfs2_edit: Fix parsing the savemeta -z option
Date: Mon, 19 May 2014 15:47:58 +0100 [thread overview]
Message-ID: <1400510878-17983-1-git-send-email-anprice@redhat.com> (raw)
Specifying -z0 instead of -z 0 could confuse gfs2_edit to the point
where it would call ftruncate on the filesystem instead of the output
file. Fix up the -z parsing function to recognise when the space is
omitted and avoid calling ftruncate on the wrong file.
Signed-off-by: Andrew Price <anprice@redhat.com>
---
gfs2/edit/hexedit.c | 26 ++++++++++++++++----------
tests/edit.at | 7 +++++++
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 53a816d..0982f7b 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -2608,19 +2608,25 @@ static void usage(void)
*/
static void getgziplevel(char *argv[], int *i)
{
+ char *opt, *arg;
char *endptr;
- (*i)++;
- if (!strcasecmp(argv[*i], "-z")) {
- (*i)++;
- errno = 0;
- gziplevel = strtol(argv[*i], &endptr, 10);
- if (errno || endptr == argv[*i] || gziplevel < 0 || gziplevel > 9) {
- fprintf(stderr, "Compression level out of range: %s\n", argv[*i]);
- exit(-1);
- }
+
+ arg = argv[1 + *i];
+ if (strncmp(arg, "-z", 2)) {
+ return;
+ } else if (arg[2] != '\0') {
+ opt = &arg[2];
} else {
- (*i)--;
+ (*i)++;
+ opt = argv[1 + *i];
+ }
+ errno = 0;
+ gziplevel = strtol(opt, &endptr, 10);
+ if (errno || endptr == opt || gziplevel < 0 || gziplevel > 9) {
+ fprintf(stderr, "Compression level out of range: %s\n", opt);
+ exit(-1);
}
+ (*i)++;
}
/* ------------------------------------------------------------------------ */
diff --git a/tests/edit.at b/tests/edit.at
index 3428d64..e2a702c 100644
--- a/tests/edit.at
+++ b/tests/edit.at
@@ -11,5 +11,12 @@ Reading resource groups...Done. File system size: 4.1023GB
GFS_TGT_REGEN
AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
+AT_CLEANUP
+AT_SETUP([Savemeta/restoremeta, no compression])
+GFS_TGT_REGEN
+AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT $(($(gfs_max_blocks 4096)/2))], 0, [ignore], [ignore])
+AT_CHECK([gfs2_edit savemeta -z0 $GFS_TGT test.meta], 0, [ignore], [ignore])
+AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
AT_CLEANUP
--
1.9.0
reply other threads:[~2014-05-19 14:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1400510878-17983-1-git-send-email-anprice@redhat.com \
--to=anprice@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).