Merging upstream version 1.8.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
95e76700ee
commit
3ab3342c4f
21 changed files with 729 additions and 460 deletions
|
@ -1,6 +1,6 @@
|
|||
/* Plzip - Parallel compressor compatible with lzip
|
||||
/* Plzip - Massively parallel implementation of lzip
|
||||
Copyright (C) 2009 Laszlo Ersek.
|
||||
Copyright (C) 2009-2018 Antonio Diaz Diaz.
|
||||
Copyright (C) 2009-2019 Antonio Diaz Diaz.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -34,7 +34,46 @@
|
|||
#include <lzlib.h>
|
||||
|
||||
#include "lzip.h"
|
||||
#include "file_index.h"
|
||||
#include "lzip_index.h"
|
||||
|
||||
|
||||
// This code is based on a patch by Hannes Domani, ssbssa@yahoo.de
|
||||
// to be able to compile plzip under MS Windows (with MINGW compiler).
|
||||
#if defined(__MSVCRT__) && defined(WITH_MINGW)
|
||||
#include <windows.h>
|
||||
#warning "Parallel I/O is not guaranteed to work on Windows."
|
||||
|
||||
ssize_t pread( int fd, void *buf, size_t count, uint64_t offset )
|
||||
{
|
||||
OVERLAPPED o = {0,0,0,0,0};
|
||||
HANDLE fh = (HANDLE)_get_osfhandle(fd);
|
||||
DWORD bytes;
|
||||
BOOL ret;
|
||||
|
||||
if( fh == INVALID_HANDLE_VALUE ) { errno = EBADF; return -1; }
|
||||
o.Offset = offset & 0xffffffff;
|
||||
o.OffsetHigh = (offset >> 32) & 0xffffffff;
|
||||
ret = ReadFile( fh, buf, (DWORD)count, &bytes, &o );
|
||||
if( !ret ) { errno = EIO; return -1; }
|
||||
return (ssize_t)bytes;
|
||||
}
|
||||
|
||||
ssize_t pwrite( int fd, const void *buf, size_t count, uint64_t offset )
|
||||
{
|
||||
OVERLAPPED o = {0,0,0,0,0};
|
||||
HANDLE fh = (HANDLE)_get_osfhandle(fd);
|
||||
DWORD bytes;
|
||||
BOOL ret;
|
||||
|
||||
if( fh == INVALID_HANDLE_VALUE ) { errno = EBADF; return -1; }
|
||||
o.Offset = offset & 0xffffffff;
|
||||
o.OffsetHigh = (offset >> 32) & 0xffffffff;
|
||||
ret = WriteFile(fh, buf, (DWORD)count, &bytes, &o);
|
||||
if( !ret ) { errno = EIO; return -1; }
|
||||
return (ssize_t)bytes;
|
||||
}
|
||||
|
||||
#endif // __MSVCRT__
|
||||
|
||||
|
||||
// Returns the number of bytes really read.
|
||||
|
@ -95,7 +134,7 @@ namespace {
|
|||
|
||||
struct Worker_arg
|
||||
{
|
||||
const File_index * file_index;
|
||||
const Lzip_index * lzip_index;
|
||||
const Pretty_print * pp;
|
||||
int worker_id;
|
||||
int num_workers;
|
||||
|
@ -108,8 +147,8 @@ struct Worker_arg
|
|||
// write the produced data to file.
|
||||
extern "C" void * dworker( void * arg )
|
||||
{
|
||||
const Worker_arg & tmp = *(Worker_arg *)arg;
|
||||
const File_index & file_index = *tmp.file_index;
|
||||
const Worker_arg & tmp = *(const Worker_arg *)arg;
|
||||
const Lzip_index & lzip_index = *tmp.lzip_index;
|
||||
const Pretty_print & pp = *tmp.pp;
|
||||
const int worker_id = tmp.worker_id;
|
||||
const int num_workers = tmp.num_workers;
|
||||
|
@ -124,12 +163,12 @@ extern "C" void * dworker( void * arg )
|
|||
LZ_decompress_errno( decoder ) != LZ_ok )
|
||||
{ pp( "Not enough memory." ); cleanup_and_fail(); }
|
||||
|
||||
for( long i = worker_id; i < file_index.members(); i += num_workers )
|
||||
for( long i = worker_id; i < lzip_index.members(); i += num_workers )
|
||||
{
|
||||
long long data_pos = file_index.dblock( i ).pos();
|
||||
long long data_rest = file_index.dblock( i ).size();
|
||||
long long member_pos = file_index.mblock( i ).pos();
|
||||
long long member_rest = file_index.mblock( i ).size();
|
||||
long long data_pos = lzip_index.dblock( i ).pos();
|
||||
long long data_rest = lzip_index.dblock( i ).size();
|
||||
long long member_pos = lzip_index.mblock( i ).pos();
|
||||
long long member_rest = lzip_index.mblock( i ).size();
|
||||
|
||||
while( member_rest > 0 )
|
||||
{
|
||||
|
@ -180,7 +219,7 @@ extern "C" void * dworker( void * arg )
|
|||
if( rd == 0 ) break;
|
||||
}
|
||||
}
|
||||
show_progress( file_index.mblock( i ).size() );
|
||||
show_progress( lzip_index.mblock( i ).size() );
|
||||
}
|
||||
|
||||
delete[] obuffer; delete[] ibuffer;
|
||||
|
@ -197,26 +236,27 @@ extern "C" void * dworker( void * arg )
|
|||
// start the workers and wait for them to finish.
|
||||
int decompress( const unsigned long long cfile_size, int num_workers,
|
||||
const int infd, const int outfd, const Pretty_print & pp,
|
||||
const int debug_level, const bool ignore_trailing,
|
||||
const int debug_level, const int in_slots,
|
||||
const int out_slots, const bool ignore_trailing,
|
||||
const bool loose_trailing, const bool infd_isreg )
|
||||
{
|
||||
if( !infd_isreg )
|
||||
return dec_stream( cfile_size, num_workers, infd, outfd, pp,
|
||||
debug_level, ignore_trailing, loose_trailing );
|
||||
return dec_stream( cfile_size, num_workers, infd, outfd, pp, debug_level,
|
||||
in_slots, out_slots, ignore_trailing, loose_trailing );
|
||||
|
||||
const File_index file_index( infd, ignore_trailing, loose_trailing );
|
||||
if( file_index.retval() == 1 )
|
||||
const Lzip_index lzip_index( infd, ignore_trailing, loose_trailing );
|
||||
if( lzip_index.retval() == 1 )
|
||||
{
|
||||
lseek( infd, 0, SEEK_SET );
|
||||
return dec_stream( cfile_size, num_workers, infd, outfd, pp,
|
||||
debug_level, ignore_trailing, loose_trailing );
|
||||
return dec_stream( cfile_size, num_workers, infd, outfd, pp, debug_level,
|
||||
in_slots, out_slots, ignore_trailing, loose_trailing );
|
||||
}
|
||||
if( file_index.retval() != 0 )
|
||||
{ show_file_error( pp.name(), file_index.error().c_str() );
|
||||
return file_index.retval(); }
|
||||
if( lzip_index.retval() != 0 )
|
||||
{ show_file_error( pp.name(), lzip_index.error().c_str() );
|
||||
return lzip_index.retval(); }
|
||||
|
||||
if( num_workers > file_index.members() )
|
||||
num_workers = file_index.members();
|
||||
if( num_workers > lzip_index.members() )
|
||||
num_workers = lzip_index.members();
|
||||
if( verbosity >= 1 ) pp();
|
||||
show_progress( 0, cfile_size, &pp ); // init
|
||||
|
||||
|
@ -225,7 +265,8 @@ int decompress( const unsigned long long cfile_size, int num_workers,
|
|||
struct stat st;
|
||||
if( fstat( outfd, &st ) != 0 || !S_ISREG( st.st_mode ) ||
|
||||
lseek( outfd, 0, SEEK_CUR ) < 0 )
|
||||
return dec_stdout( num_workers, infd, outfd, pp, debug_level, file_index );
|
||||
return dec_stdout( num_workers, infd, outfd, pp, debug_level, out_slots,
|
||||
lzip_index );
|
||||
}
|
||||
|
||||
Worker_arg * worker_args = new( std::nothrow ) Worker_arg[num_workers];
|
||||
|
@ -234,7 +275,7 @@ int decompress( const unsigned long long cfile_size, int num_workers,
|
|||
{ pp( "Not enough memory." ); cleanup_and_fail(); }
|
||||
for( int i = 0; i < num_workers; ++i )
|
||||
{
|
||||
worker_args[i].file_index = &file_index;
|
||||
worker_args[i].lzip_index = &lzip_index;
|
||||
worker_args[i].pp = &pp;
|
||||
worker_args[i].worker_id = i;
|
||||
worker_args[i].num_workers = num_workers;
|
||||
|
@ -257,9 +298,9 @@ int decompress( const unsigned long long cfile_size, int num_workers,
|
|||
|
||||
if( verbosity >= 2 )
|
||||
{
|
||||
if( verbosity >= 4 ) show_header( file_index.dictionary_size( 0 ) );
|
||||
const unsigned long long in_size = file_index.cdata_size();
|
||||
const unsigned long long out_size = file_index.udata_size();
|
||||
if( verbosity >= 4 ) show_header( lzip_index.dictionary_size( 0 ) );
|
||||
const unsigned long long in_size = lzip_index.cdata_size();
|
||||
const unsigned long long out_size = lzip_index.udata_size();
|
||||
if( out_size == 0 || in_size == 0 )
|
||||
std::fputs( "no data compressed. ", stderr );
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue