Write/read new magic header and fix version number in configure.ac

This commit is contained in:
Con Kolivas 2011-03-11 23:29:56 +11:00
parent 39e07fc4e5
commit a10d423596
3 changed files with 28 additions and 4 deletions

View file

@ -1,7 +1,7 @@
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--## ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--## ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
m4_define([v_maj], [0]) m4_define([v_maj], [0])
m4_define([v_min], [6) m4_define([v_min], [6])
m4_define([v_mic], [00]) m4_define([v_mic], [00])
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--## ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
m4_define([v_v], m4_join([], v_min, v_mic)) m4_define([v_v], m4_join([], v_min, v_mic))

27
lrzip.c
View file

@ -34,6 +34,7 @@
#ifdef HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
#include <sys/time.h>
#include "md5.h" #include "md5.h"
#include "rzip.h" #include "rzip.h"
@ -43,8 +44,9 @@
void write_magic(rzip_control *control, int fd_in, int fd_out) void write_magic(rzip_control *control, int fd_in, int fd_out)
{ {
struct timeval tv;
struct stat st; struct stat st;
char magic[24]; char magic[40];
int i; int i;
memset(magic, 0, sizeof(magic)); 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. * crc is still stored for compatibility with 0.5 versions.
*/ */
magic[21] = 1; 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))) if (unlikely(lseek(fd_out, 0, SEEK_SET)))
fatal("Failed to seek to BOF to write Magic Header\n"); 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) void read_magic(rzip_control *control, int fd_in, i64 *expected_size)
{ {
char magic[24]; char magic[40];
uint32_t v; uint32_t v;
int md5, i; int md5, i;
memset(magic, 0, 40);
if (unlikely(read(fd_in, magic, sizeof(magic)) != sizeof(magic))) if (unlikely(read(fd_in, magic, sizeof(magic)) != sizeof(magic)))
fatal("Failed to read magic header\n"); 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); *expected_size = ntohl(v);
memcpy(&v, &magic[10], 4); memcpy(&v, &magic[10], 4);
*expected_size |= ((i64)ntohl(v)) << 32; *expected_size |= ((i64)ntohl(v)) << 32;
} else } else {
memcpy(expected_size, &magic[6], 8); 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 */ /* restore LZMA compression flags only if stored */
if ((int) magic[16]) { if ((int) magic[16]) {

View file

@ -177,6 +177,9 @@ struct rzip_control {
i64 st_size; i64 st_size;
long page_size; long page_size;
int fd_out; int fd_out;
int encrypt;
i64 secs;
i64 usecs;
md5_ctx ctx; md5_ctx ctx;
i64 md5_read; // How far into the file the md5 has done so far i64 md5_read; // How far into the file the md5 has done so far
}; };