From: Marcus Huewe Date: Thu, 12 May 2016 19:36:00 +0000 (-0400) Subject: e2undo: add "-o offset" option to specify the filesystem offset X-Git-Tag: v1.43~6 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=6930537d528c00c81d76a301936b198e16b460d9;p=tools%2Fe2fsprogs.git e2undo: add "-o offset" option to specify the filesystem offset This is useful if the filesystem is located at an arbitrary offset instead of the beginning of a device or file. Signed-off-by: Marcus Huewe Signed-off-by: Theodore Ts'o --- diff --git a/misc/e2undo.8.in b/misc/e2undo.8.in index 1b7dee3..da8b918 100644 --- a/misc/e2undo.8.in +++ b/misc/e2undo.8.in @@ -46,6 +46,11 @@ Display a usage message. .B \-n Dry-run; do not actually write blocks back to the filesystem. .TP +.BI \-o " offset" +Specify the filesystem's +.I offset +(in bytes) from the beginning of the device or file. +.TP .B \-v Report which block we're currently replaying. .SH AUTHOR diff --git a/misc/e2undo.c b/misc/e2undo.c index 7c7326a..4ea78cc 100644 --- a/misc/e2undo.c +++ b/misc/e2undo.c @@ -292,6 +292,8 @@ int main(int argc, char *argv[]) __u32 key_crc, blk_crc, hdr_crc; blk64_t lblk; ext2_filsys fs; + __u64 offset; + char opt_offset_string[40] = { 0 }; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); @@ -303,7 +305,7 @@ int main(int argc, char *argv[]) add_error_table(&et_ext2_error_table); prg_name = argv[0]; - while ((c = getopt(argc, argv, "fhnvz:")) != EOF) { + while ((c = getopt(argc, argv, "fhno:vz:")) != EOF) { switch (c) { case 'f': force = 1; @@ -314,6 +316,16 @@ int main(int argc, char *argv[]) case 'n': dry_run = 1; break; + case 'o': + offset = strtoull(optarg, &buf, 0); + if (*buf) { + com_err(prg_name, 0, + _("illegal offset - %s"), optarg); + exit(1); + } + /* used to indicate that an offset was specified */ + opt_offset_string[0] = 1; + break; case 'v': verbose = 1; break; @@ -423,6 +435,17 @@ int main(int argc, char *argv[]) exit(1); } + if (*opt_offset_string) { + retval = snprintf(opt_offset_string, sizeof(opt_offset_string), + "offset=%llu", offset); + if (retval >= sizeof(opt_offset_string)) { + /* should not happen... */ + com_err(prg_name, 0, _("specified offset is too large")); + exit(1); + } + io_channel_set_options(channel, opt_offset_string); + } + if (!force && check_filesystem(&undo_ctx, channel)) exit(1);