Gitweb:
http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=a96c74f4...
Commit: a96c74f47ec41e85a5cd6eef969d7231831a2c37
Parent: fb76fa5d14ef8e8ae77af36a20dbfa84ea29579b
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon May 19 15:40:49 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon May 19 15:47:29 2014 +0100
gfs2_edit: Fix parsing the savemeta -z option
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(a)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