Whamcloud - gitweb
e2undo: add "-o offset" option to specify the filesystem offset
authorMarcus Huewe <suse-tux@gmx.de>
Thu, 12 May 2016 19:36:00 +0000 (15:36 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 12 May 2016 19:36:00 +0000 (15:36 -0400)
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 <suse-tux@gmx.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/e2undo.8.in
misc/e2undo.c

index 1b7dee3..da8b918 100644 (file)
@@ -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
index 7c7326a..4ea78cc 100644 (file)
@@ -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);