Change default seek behavior: error out, allow to ignore errors with -E xseek.
authorAndrey Rys <rys@lynxlynx.ru>
Sat, 9 Feb 2019 07:15:16 +0000 (14:15 +0700)
committerAndrey Rys <rys@lynxlynx.ru>
Sat, 9 Feb 2019 07:15:16 +0000 (14:15 +0700)
VERSION
tfc_error.c
tfc_random.c
tfc_skein.c
tfc_vars.c
tfcrypt.c
tfcrypt.h

diff --git a/VERSION b/VERSION
index ec635144f60048986bc560c5576355344005e6e7..f599e28b8ab0d8c9c57a486c89c4a5132dcbd3b2 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-9
+10
index e1793fe0b5ed6e540886334bcb3a3e3272a10ff2..cb8ee057e7f25756e22dc3e512fb4aa94d0a7a11 100644 (file)
@@ -221,7 +221,8 @@ void usage(void)
        tfc_say("      Note that both sync and lsync work only with read errors!");
        tfc_say("  default error action is exit with printing status if not quiet.");
        tfc_say("  -E xall: turn on error actions above for all errors, not just EIO errors.");
-       tfc_say("    This must be a separate option given before usual -E how option.");
+       tfc_say("  -E xseek: ignore positioning and other seek related errors.");
+       tfc_say("    Multiple -E specifiers may be given in separate options.");
        tfc_say("  -O opts: set options (comma separated list):");
        tfc_say("    sync: request a synchronous I/O for a output,");
        tfc_say("    fsync: on each write() call a corresponding fsync(fd),");
index 7c7b0b911d1564b9284c0e2bbc498d4c47429d32..03f9dad78339d5c5c66ad30fe8b6f455b992167b 100644 (file)
@@ -130,7 +130,7 @@ void gen_write_bytes(const char *foutname, tfc_fsize offset, tfc_fsize nrbytes)
 
        if (offset) {
                if (lseek(fd, offset, SEEK_SET) == -1)
-                       xerror(YES, NO, NO, "%s: seek failed", foutname);
+                       xerror(ignore_seek_errors, NO, NO, "%s: seek failed", foutname);
        }
 
        if (ctr_mode == TFC_MODE_PLAIN) memset(srcblk, 0, sizeof(srcblk));
index fe86c20de71b1c595aa15e5e2d489223d1766d71..5d457deac828513156db13ced328d11feb6ef9e7 100644 (file)
@@ -68,7 +68,9 @@ tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize of
                        if (readto == NOFSIZE) goto _fail;
                }
                if (offset != 0 && offset != NOFSIZE) {
-                       if (lseek(fd, (off_t)offset, SEEK_SET) == -1) goto _fail;
+                       if (lseek(fd, (off_t)offset, SEEK_SET) == -1) {
+                               if (ignore_seek_errors == NO) goto _fail;
+                       }
                }
        }
 
index d7b4818783b3ca85f1650cdb1130c2eb3886f9cd..490193dc26013ddd7c59f0097c904530ef55ee74 100644 (file)
@@ -62,7 +62,7 @@ size_t sksum_turns;
 int do_edcrypt = TFC_DO_ENCRYPT, do_stop, quiet, error_action;
 int counter_opt, mackey_opt, do_mac, do_outfmt = TFC_OUTFMT_B64, rawkey;
 int idx, write_flags;
-tfc_yesno catch_all_errors, password, overwrite_source, do_fsync, do_pad, do_tfcrypt1;
+tfc_yesno catch_all_errors, ignore_seek_errors, password, overwrite_source, do_fsync, do_pad, do_tfcrypt1;
 tfc_yesno do_preserve_time, do_stats_in_gibs, do_statline_dynamic = YES, do_less_stats;
 tfc_yesno no_repeat, do_full_hexdump = YES, verbose, statline_was_shown;
 char *srcfname = TFC_STDIN_NAME, *dstfname = TFC_STDOUT_NAME, *do_mac_file, *counter_file, *sksum_hashlist_file;
index df62420769d0b07b0db2a72a424cb72f6885d081..363e3c4825c8735dcae93c7e10cf338fbcb49056 100644 (file)
--- a/tfcrypt.c
+++ b/tfcrypt.c
@@ -171,6 +171,10 @@ int main(int argc, char **argv)
                                        catch_all_errors = YES;
                                        break;
                                }
+                               if (!strcmp(optarg, "xseek")) {
+                                       ignore_seek_errors = YES;
+                                       break;
+                               }
                                if (!strcmp(optarg, "exit"))
                                        error_action = TFC_ERRACT_EXIT;
                                else if (!strncmp(optarg, "cont", 4))
@@ -695,7 +699,7 @@ _ctrskip1:
                if (counter_opt == TFC_CTR_HEAD && ctr_mode != TFC_MODE_ECB)
                        iseek += ctrsz;
                if (lseek(sfd, iseek, SEEK_SET) == -1)
-                       xerror(YES, NO, NO, "%s: seek failed", srcfname);
+                       xerror(ignore_seek_errors, NO, NO, "%s: seek failed", srcfname);
        }
 
        if (ctr_mode == TFC_MODE_PLAIN) goto _plain;
@@ -938,7 +942,7 @@ _plain:
 
        if (oseek) {
                if (lseek(dfd, oseek, SEEK_SET) == -1)
-                       xerror(YES, NO, NO, "%s: seek failed", dstfname);
+                       xerror(ignore_seek_errors, NO, NO, "%s: seek failed", dstfname);
        }
 
        for (x = 1; x < NSIG; x++) signal(x, SIG_IGN);
index bf0d6d66e82886e4ee03e8ea3b160026d262f78d..fddb1ae3ebadfb5bdfbd5b96350001c487e1386a 100644 (file)
--- a/tfcrypt.h
+++ b/tfcrypt.h
@@ -151,7 +151,7 @@ extern size_t sksum_turns;
 extern int do_edcrypt, do_stop, quiet, error_action;
 extern int counter_opt, mackey_opt, do_mac, do_outfmt, rawkey;
 extern int idx, write_flags;
-extern tfc_yesno catch_all_errors, password, overwrite_source, do_fsync, do_pad, do_tfcrypt1;
+extern tfc_yesno catch_all_errors, ignore_seek_errors, password, overwrite_source, do_fsync, do_pad, do_tfcrypt1;
 extern tfc_yesno do_preserve_time, do_stats_in_gibs, do_statline_dynamic, do_less_stats;
 extern tfc_yesno no_repeat, do_full_hexdump, verbose, statline_was_shown;
 extern char *srcfname, *dstfname, *do_mac_file, *counter_file, *sksum_hashlist_file;