"-O ftrunc=": implement file truncations (without sanity checks).
authorAndrey Rys <rys@lynxlynx.ru>
Sat, 6 Apr 2019 11:49:54 +0000 (18:49 +0700)
committerAndrey Rys <rys@lynxlynx.ru>
Sat, 6 Apr 2019 11:49:54 +0000 (18:49 +0700)
VERSION
tfc_error.c
tfc_vars.c
tfcrypt.c
tfcrypt.h

diff --git a/VERSION b/VERSION
index 7273c0fa8c522b7eed7762a353d46f7768e9b6f2..6f4247a6255c99f420d1df558d68745592862ff7 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-25
+26
index 11c22bbb12ec519812d1d5e0403249ae034ada59..c4e51f169669b2684c480207a8412b07707bddd6 100644 (file)
@@ -256,6 +256,7 @@ void usage(void)
        tfc_say("    Internally this number is translated into number of %u byte blocks.", TFC_U(TF_BLOCK_SIZE));
        tfc_say("    oseek=val: seek destination file/device by these val bytes.");
        tfc_say("    count=val: process only these val bytes, both input and output.");
+       tfc_say("    ftrunc=val: truncate output file to these val bytes before closing it.");
        tfc_say("    xkey=val: take only val bytes from user keyfile.");
        tfc_say("    okey=val: seek the key before reading it (usually a device).");
        tfc_say("    xctr=val: specify size in bytes of initial counter prepended or read.");
index 15a0320694d5f6634a86d79a2d7da9934a559096..f62926453225f4d2aefcfa850b0a1d44a484b6d2 100644 (file)
@@ -41,7 +41,7 @@ tfc_byte tmpdata[TFC_TMPSIZE];
 
 char *randsource = TFC_DEFAULT_RANDSOURCE;
 
-tfc_fsize iseek_blocks, iseek, oseek, maxlen = NOFSIZE;
+tfc_fsize iseek_blocks, iseek, oseek, maxlen = NOFSIZE, ftrunc_dfd = NOFSIZE;
 tfc_fsize total_processed_src, total_processed_dst;
 tfc_fsize delta_processed;
 tfc_fsize genrandom_nr_bytes, genzero_nr_bytes;
index 5ed5bbf1979cad49d5ee15bc876495b82ebc822a..3534bb836c76b8ee3b9dbdca3215f728a9b2c731 100644 (file)
--- a/tfcrypt.c
+++ b/tfcrypt.c
@@ -376,6 +376,17 @@ _baddfname:
                                                if (counter_opt == TFC_CTR_HEAD)
                                                        maxlen += TF_BLOCK_SIZE;
                                        }
+                                       else if (!strncmp(s, "ftrunc", 6) && *(s+6) == '=') {
+                                               s += 7;
+                                               ftrunc_dfd = tfc_humanfsize(s, &stoi);
+                                               if (!str_empty(stoi)) {
+                                                       ftrunc_dfd = tfc_fnamesize(s, YES);
+                                                       ftrunc_dfd = tfc_modifysize(ftrunc_dfd, strchr(s, ':'));
+                                                       if (ftrunc_dfd == NOFSIZE) xerror(NO, YES, YES,
+                                                       "%s: invalid ftrunc value", s);
+                                               }
+                                               else ftrunc_dfd = tfc_modifysize(ftrunc_dfd, strchr(s, ':'));
+                                       }
                                        else if (!strncmp(s, "xkey", 4) && *(s+4) == '=') {
                                                s += 5;
                                                maxkeylen = tfc_humanfsize(s, &stoi);
@@ -1277,6 +1288,7 @@ _nomac:
 
        if (do_preserve_time) fcopy_matime(dfd, &s_stat);
        xclose(sfd);
+       if (ftrunc_dfd != NOFSIZE) if (ftruncate(dfd, (off_t)ftrunc_dfd) == -1) xerror(YES, NO, YES, "ftruncate(%d)", dfd);
        xclose(dfd);
 
        xexit(exitcode);
index f2cb89cefa99481a351297e428d9dc237e6ba70e..49073c96ad0d63fb63d97530a531ee247b77855b 100644 (file)
--- a/tfcrypt.h
+++ b/tfcrypt.h
@@ -138,7 +138,7 @@ extern tfc_byte srcblk[TFC_BLKSIZE], dstblk[TFC_BLKSIZE], *pblk;
 extern tfc_byte macvrfy[SKEIN_DIGEST_SIZE], macresult[SKEIN_DIGEST_SIZE];
 extern tfc_byte tmpdata[TFC_TMPSIZE];
 extern char *randsource;
-extern tfc_fsize iseek_blocks, iseek, oseek, maxlen;
+extern tfc_fsize iseek_blocks, iseek, oseek, maxlen, ftrunc_dfd;
 extern tfc_fsize total_processed_src, total_processed_dst;
 extern tfc_fsize delta_processed;
 extern tfc_fsize genrandom_nr_bytes, genzero_nr_bytes;