Fix stdin failing due to getting sizes all wrong.

Fix stdin compression values not being shown at end.
Fix inappropriate failure when lzma doesn't compress block.
This commit is contained in:
Con Kolivas 2010-12-12 17:40:58 +11:00
parent 981859fdba
commit 427df4cd4a
2 changed files with 7 additions and 2 deletions

6
rzip.c
View file

@ -663,7 +663,7 @@ static void mmap_stdin(uchar *buf, struct rzip_state *st)
buf = mremap(buf, st->chunk_size, total, 0); buf = mremap(buf, st->chunk_size, total, 0);
if (unlikely(buf == MAP_FAILED)) if (unlikely(buf == MAP_FAILED))
fatal("Failed to remap to smaller buf in mmap_stdin\n"); fatal("Failed to remap to smaller buf in mmap_stdin\n");
st->chunk_size = total; st->mmap_size = st->chunk_size = total;
st->stdin_eof = 1; st->stdin_eof = 1;
break; break;
} }
@ -782,6 +782,7 @@ void rzip_fd(int fd_in, int fd_out)
if (control.window) if (control.window)
control.max_chunk = MIN(control.max_chunk, control.window * CHUNK_MULTIPLE); control.max_chunk = MIN(control.max_chunk, control.window * CHUNK_MULTIPLE);
round_to_page(&control.max_chunk); round_to_page(&control.max_chunk);
control.max_mmap = MIN(control.max_mmap, control.max_chunk);
if (!STDIN) if (!STDIN)
st->chunk_size = MIN(control.max_chunk, len); st->chunk_size = MIN(control.max_chunk, len);
@ -829,6 +830,7 @@ retry:
fatal("Unable to mmap any ram\n"); fatal("Unable to mmap any ram\n");
goto retry; goto retry;
} }
st->chunk_size = st->mmap_size;
mmap_stdin(sb.buf_low, st); mmap_stdin(sb.buf_low, st);
} else { } else {
/* NOTE The buf is saved here for !STDIN mode */ /* NOTE The buf is saved here for !STDIN mode */
@ -906,6 +908,8 @@ retry:
close_streamout_threads(); close_streamout_threads();
gettimeofday(&current, NULL); gettimeofday(&current, NULL);
if (STDIN)
s.st_size = control.st_size;
chunkmbs = (s.st_size / 1024 / 1024) / ((double)(current.tv_sec-start.tv_sec)? : 1); chunkmbs = (s.st_size / 1024 / 1024) / ((double)(current.tv_sec-start.tv_sec)? : 1);
fstat(fd_out, &s2); fstat(fd_out, &s2);

View file

@ -336,7 +336,8 @@ retry:
* remain uncompressed */ * remain uncompressed */
print_verbose("Unable to allocate enough RAM for any sized compression window, falling back to bzip2 compression.\n"); print_verbose("Unable to allocate enough RAM for any sized compression window, falling back to bzip2 compression.\n");
return bzip2_compress_buf(cthread); return bzip2_compress_buf(cthread);
} } else if (lzma_ret == SZ_ERROR_OUTPUT_EOF)
return 0;
return -1; return -1;
} }