From a10d4235968e7eb71cb63283cdb282a743aec072 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 11 Mar 2011 23:29:56 +1100 Subject: [PATCH] Write/read new magic header and fix version number in configure.ac --- configure.ac | 2 +- lrzip.c | 27 ++++++++++++++++++++++++--- lrzip_private.h | 3 +++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 0e2efc3..7ae51ff 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--## ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--## m4_define([v_maj], [0]) -m4_define([v_min], [6) +m4_define([v_min], [6]) m4_define([v_mic], [00]) ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--## m4_define([v_v], m4_join([], v_min, v_mic)) diff --git a/lrzip.c b/lrzip.c index 08f372d..8fcdc0a 100644 --- a/lrzip.c +++ b/lrzip.c @@ -34,6 +34,7 @@ #ifdef HAVE_ERRNO_H #include #endif +#include #include "md5.h" #include "rzip.h" @@ -43,8 +44,9 @@ void write_magic(rzip_control *control, int fd_in, int fd_out) { + struct timeval tv; struct stat st; - char magic[24]; + char magic[40]; int i; memset(magic, 0, sizeof(magic)); @@ -68,6 +70,15 @@ void write_magic(rzip_control *control, int fd_in, int fd_out) * crc is still stored for compatibility with 0.5 versions. */ magic[21] = 1; + if (control->encrypt) + magic[22] = 1; + + if (unlikely(gettimeofday(&tv, NULL))) + fatal("Failed to gettimeofday in write_magic\n"); + control->secs = tv.tv_sec; + control->usecs = tv.tv_usec; + memcpy(&magic[23], &control->secs, 8); + memcpy(&magic[31], &control->usecs, 8); if (unlikely(lseek(fd_out, 0, SEEK_SET))) fatal("Failed to seek to BOF to write Magic Header\n"); @@ -78,10 +89,11 @@ void write_magic(rzip_control *control, int fd_in, int fd_out) void read_magic(rzip_control *control, int fd_in, i64 *expected_size) { - char magic[24]; + char magic[40]; uint32_t v; int md5, i; + memset(magic, 0, 40); if (unlikely(read(fd_in, magic, sizeof(magic)) != sizeof(magic))) fatal("Failed to read magic header\n"); @@ -99,8 +111,17 @@ void read_magic(rzip_control *control, int fd_in, i64 *expected_size) *expected_size = ntohl(v); memcpy(&v, &magic[10], 4); *expected_size |= ((i64)ntohl(v)) << 32; - } else + } else { memcpy(expected_size, &magic[6], 8); + if (control->major_version == 0 && control->minor_version > 5) { + if (magic[22] == 1) + control->encrypt = 1; + memcpy(&control->secs, &magic[23], 8); + memcpy(&control->usecs, &magic[31], 8); + print_maxverbose("Seconds %lld\n", control->secs); + print_maxverbose("Microseconds %lld\n", control->usecs); + } + } /* restore LZMA compression flags only if stored */ if ((int) magic[16]) { diff --git a/lrzip_private.h b/lrzip_private.h index ed5efb1..9935ee6 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -177,6 +177,9 @@ struct rzip_control { i64 st_size; long page_size; int fd_out; + int encrypt; + i64 secs; + i64 usecs; md5_ctx ctx; i64 md5_read; // How far into the file the md5 has done so far };