From: Andrey Rys Date: Sat, 9 Feb 2019 07:15:16 +0000 (+0700) Subject: Change default seek behavior: error out, allow to ignore errors with -E xseek. X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=630fb7d8dc740715cdc52114d736d64bf14f0798;p=tfcrypt.git Change default seek behavior: error out, allow to ignore errors with -E xseek. --- diff --git a/VERSION b/VERSION index ec63514..f599e28 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9 +10 diff --git a/tfc_error.c b/tfc_error.c index e1793fe..cb8ee05 100644 --- a/tfc_error.c +++ b/tfc_error.c @@ -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),"); diff --git a/tfc_random.c b/tfc_random.c index 7c7b0b9..03f9dad 100644 --- a/tfc_random.c +++ b/tfc_random.c @@ -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)); diff --git a/tfc_skein.c b/tfc_skein.c index fe86c20..5d457de 100644 --- a/tfc_skein.c +++ b/tfc_skein.c @@ -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; + } } } diff --git a/tfc_vars.c b/tfc_vars.c index d7b4818..490193d 100644 --- a/tfc_vars.c +++ b/tfc_vars.c @@ -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; diff --git a/tfcrypt.c b/tfcrypt.c index df62420..363e3c4 100644 --- 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); diff --git a/tfcrypt.h b/tfcrypt.h index bf0d6d6..fddb1ae 100644 --- 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;