Fix fd_hist check occurring too early on decompress.

fsync after flushing buffer.
Remove unnecessary memset after anonymous mmap.
Do test malloc before compression backend to see how big a chunk can be passed.
This commit is contained in:
Con Kolivas 2010-11-02 13:50:15 +11:00
parent c0ac813f6d
commit 9c00229ee1
3 changed files with 17 additions and 4 deletions

5
main.c
View file

@ -291,12 +291,13 @@ static void decompress_file(void)
if (!NO_SET_PERMS)
preserve_perms(fd_in, fd_out);
if (fd_hist == -1)
fatal("Failed to open history file %s\n", control.outfile);
} else
fd_out = open_tmpoutfile();
fd_hist = open(control.outfile, O_RDONLY);
if (fd_hist == -1)
fatal("Failed to open history file %s\n", control.outfile);
read_magic(fd_in, &expected_size);
print_progress("Decompressing...");

2
rzip.c
View file

@ -583,8 +583,6 @@ static void rzip_chunk(struct rzip_state *st, int fd_in, int fd_out, i64 offset,
continue;
}
print_maxverbose("Preallocated %lld ram...\n", prealloc_size);
if (!memset(buf, 0, prealloc_size))
fatal("Failed to memset in rzip_chunk\n");
if (!STDIN) {
/* STDIN will use this already allocated ram */
if (munmap(buf, prealloc_size) != 0)

View file

@ -600,6 +600,7 @@ void *open_stream_out(int f, int n, i64 limit)
{
unsigned cwindow = control.window;
struct stream_info *sinfo;
uchar *testmalloc;
int i;
sinfo = malloc(sizeof(*sinfo));
@ -642,6 +643,18 @@ void *open_stream_out(int f, int n, i64 limit)
return NULL;
}
/* Find the largest we can make the window based on ability to malloc
* ram. We need enough for the 2 streams and for the compression
* backend at most, being conservative. */
retest_malloc:
testmalloc = malloc(sinfo->bufsize * (n + 1));
if (!testmalloc) {
sinfo->bufsize = sinfo->bufsize / 10 * 9;
goto retest_malloc;
}
free(testmalloc);
print_maxverbose("Succeeded to malloc for compression bufsize of %lld\n", sinfo->bufsize);
for (i = 0; i < n; i++) {
sinfo->s[i].buf = malloc(sinfo->bufsize);
if (!sinfo->s[i].buf)
@ -783,6 +796,7 @@ static int flush_buffer(struct stream_info *sinfo, int stream)
if (write_buf(sinfo->fd, sinfo->s[stream].buf, c_len) != 0)
return -1;
fsync(sinfo->fd);
sinfo->cur_pos += c_len;
sinfo->s[stream].buflen = 0;