gfs2_edit: Fix parsing the savemeta -z option
PATCH 1/1 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 <[email protected]>
--- gfs2/edit/hexedit.c | 26 ++++++++++++++++---------- tests/edit.at | 7 +++++++ 2 files changed, 23 insertions(+), 10 deletions(-)
gfs2/edit/hexedit.c +16 -10
@@ -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)++; }/* ------------------------------------------------------------------------ */
tests/edit.at +7 -0
@@ -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
Signature · 1 line
1.9.0