2011-03-08 22:34:44 +01:00
|
|
|
/*
|
|
|
|
|
Copyright (C) 2006-2011 Con Kolivas
|
|
|
|
|
Copyright (C) 2011 Peter Hyman
|
|
|
|
|
Copyright (C) 1998-2003 Andrew Tridgell
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef LRZIP_PRIV_H
|
|
|
|
|
#define LRZIP_PRIV_H
|
|
|
|
|
|
|
|
|
|
#define NUM_STREAMS 2
|
|
|
|
|
#define STREAM_BUFSIZE (1024 * 1024 * 10)
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
2011-08-12 08:43:42 +02:00
|
|
|
#include <stdbool.h>
|
2011-08-13 08:21:45 +02:00
|
|
|
#include <stdarg.h>
|
2011-03-08 22:37:26 +01:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
|
# include <string.h>
|
|
|
|
|
#endif
|
2011-03-08 22:34:44 +01:00
|
|
|
|
2011-03-08 22:37:26 +01:00
|
|
|
#ifdef HAVE_MALLOC_H
|
|
|
|
|
# include <malloc.h>
|
2011-03-08 22:34:44 +01:00
|
|
|
#endif
|
|
|
|
|
|
2011-08-12 08:43:42 +02:00
|
|
|
#ifdef HAVE_ALLOCA_H
|
|
|
|
|
# include <alloca.h>
|
|
|
|
|
#elif defined __GNUC__
|
|
|
|
|
# define alloca __builtin_alloca
|
|
|
|
|
#elif defined _AIX
|
|
|
|
|
# define alloca __alloca
|
|
|
|
|
#elif defined _MSC_VER
|
|
|
|
|
# include <malloc.h>
|
|
|
|
|
# define alloca _alloca
|
|
|
|
|
#else
|
|
|
|
|
# include <stddef.h>
|
|
|
|
|
# ifdef __cplusplus
|
|
|
|
|
extern "C"
|
|
|
|
|
# endif
|
|
|
|
|
void *alloca (size_t);
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-08-13 08:21:45 +02:00
|
|
|
#ifndef MD5_DIGEST_SIZE
|
|
|
|
|
# define MD5_DIGEST_SIZE 16
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-08-12 08:43:42 +02:00
|
|
|
#define free(X) do { free((X)); (X) = NULL; } while (0)
|
|
|
|
|
|
|
|
|
|
#ifndef strdupa
|
|
|
|
|
# define strdupa(str) strcpy(alloca(strlen(str) + 1), str)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef strndupa
|
|
|
|
|
# define strndupa(str, len) strncpy(alloca(len + 1), str, len)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2011-03-08 22:34:44 +01:00
|
|
|
#ifndef uchar
|
|
|
|
|
#define uchar unsigned char
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef int32
|
|
|
|
|
#if (SIZEOF_INT == 4)
|
|
|
|
|
#define int32 int
|
|
|
|
|
#elif (SIZEOF_LONG == 4)
|
|
|
|
|
#define int32 long
|
|
|
|
|
#elif (SIZEOF_SHORT == 4)
|
|
|
|
|
#define int32 short
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef int16
|
|
|
|
|
#if (SIZEOF_INT == 2)
|
|
|
|
|
#define int16 int
|
|
|
|
|
#elif (SIZEOF_SHORT == 2)
|
|
|
|
|
#define int16 short
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef uint32
|
|
|
|
|
#define uint32 unsigned int32
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef uint16
|
|
|
|
|
#define uint16 unsigned int16
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
|
#define MIN(a, b) ((a) < (b)? (a): (b))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
|
#define MAX(a, b) ((a) > (b)? (a): (b))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if !HAVE_STRERROR
|
|
|
|
|
extern char *sys_errlist[];
|
|
|
|
|
#define strerror(i) sys_errlist[i]
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_ERRNO_H
|
|
|
|
|
extern int errno;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define likely(x) __builtin_expect(!!(x), 1)
|
|
|
|
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
|
|
|
|
|
|
|
|
typedef long long int i64;
|
|
|
|
|
typedef uint32_t u32;
|
|
|
|
|
|
|
|
|
|
typedef struct rzip_control rzip_control;
|
|
|
|
|
typedef struct md5_ctx md5_ctx;
|
|
|
|
|
|
2011-04-11 13:51:53 +02:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
|
|
|
|
|
defined(__APPLE__) || defined(__CYGWIN__)
|
2011-03-22 22:34:09 +01:00
|
|
|
#define mremap fake_mremap
|
2011-03-08 22:34:44 +01:00
|
|
|
#endif
|
|
|
|
|
|
2011-04-13 06:50:26 +02:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
|
# define MD5_RELIABLE (0)
|
|
|
|
|
#else
|
|
|
|
|
# define MD5_RELIABLE (1)
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-03-21 14:13:29 +01:00
|
|
|
#define bswap_32(x) \
|
|
|
|
|
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
|
|
|
|
|
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
|
|
|
|
|
|
|
|
|
|
# define bswap_64(x) \
|
|
|
|
|
((((x) & 0xff00000000000000ull) >> 56) \
|
|
|
|
|
| (((x) & 0x00ff000000000000ull) >> 40) \
|
|
|
|
|
| (((x) & 0x0000ff0000000000ull) >> 24) \
|
|
|
|
|
| (((x) & 0x000000ff00000000ull) >> 8) \
|
|
|
|
|
| (((x) & 0x00000000ff000000ull) << 8) \
|
|
|
|
|
| (((x) & 0x0000000000ff0000ull) << 24) \
|
|
|
|
|
| (((x) & 0x000000000000ff00ull) << 40) \
|
|
|
|
|
| (((x) & 0x00000000000000ffull) << 56))
|
|
|
|
|
|
2011-03-21 21:57:32 +01:00
|
|
|
#ifdef leto32h
|
|
|
|
|
# define le32toh(x) leto32h(x)
|
|
|
|
|
# define le64toh(x) leto64h(x)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef le32toh
|
2011-03-21 14:13:29 +01:00
|
|
|
# if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
|
# define htole32(x) (x)
|
|
|
|
|
# define le32toh(x) (x)
|
|
|
|
|
# define htole64(x) (x)
|
|
|
|
|
# define le64toh(x) (x)
|
|
|
|
|
# elif __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
|
# define htole32(x) bswap_32 (x)
|
|
|
|
|
# define le32toh(x) bswap_32 (x)
|
|
|
|
|
# define htole64(x) bswap_64 (x)
|
|
|
|
|
# define le64toh(x) bswap_64 (x)
|
|
|
|
|
#else
|
|
|
|
|
#error UNKNOWN BYTE ORDER
|
|
|
|
|
#endif
|
2011-03-21 21:57:32 +01:00
|
|
|
#endif
|
2011-03-21 14:13:29 +01:00
|
|
|
|
2011-03-08 22:34:44 +01:00
|
|
|
#define FLAG_SHOW_PROGRESS (1 << 0)
|
|
|
|
|
#define FLAG_KEEP_FILES (1 << 1)
|
|
|
|
|
#define FLAG_TEST_ONLY (1 << 2)
|
|
|
|
|
#define FLAG_FORCE_REPLACE (1 << 3)
|
|
|
|
|
#define FLAG_DECOMPRESS (1 << 4)
|
|
|
|
|
#define FLAG_NO_COMPRESS (1 << 5)
|
|
|
|
|
#define FLAG_LZO_COMPRESS (1 << 6)
|
|
|
|
|
#define FLAG_BZIP2_COMPRESS (1 << 7)
|
|
|
|
|
#define FLAG_ZLIB_COMPRESS (1 << 8)
|
|
|
|
|
#define FLAG_ZPAQ_COMPRESS (1 << 9)
|
|
|
|
|
#define FLAG_VERBOSITY (1 << 10)
|
|
|
|
|
#define FLAG_VERBOSITY_MAX (1 << 11)
|
|
|
|
|
#define FLAG_STDIN (1 << 12)
|
|
|
|
|
#define FLAG_STDOUT (1 << 13)
|
|
|
|
|
#define FLAG_INFO (1 << 14)
|
|
|
|
|
#define FLAG_UNLIMITED (1 << 15)
|
|
|
|
|
#define FLAG_HASH (1 << 16)
|
|
|
|
|
#define FLAG_MD5 (1 << 17)
|
|
|
|
|
#define FLAG_CHECK (1 << 18)
|
|
|
|
|
#define FLAG_KEEP_BROKEN (1 << 19)
|
|
|
|
|
#define FLAG_THRESHOLD (1 << 20)
|
2011-03-12 22:34:06 +01:00
|
|
|
#define FLAG_TMP_OUTBUF (1 << 21)
|
2011-03-14 04:47:26 +01:00
|
|
|
#define FLAG_TMP_INBUF (1 << 22)
|
2011-03-15 05:04:58 +01:00
|
|
|
#define FLAG_ENCRYPT (1 << 23)
|
2011-03-08 22:34:44 +01:00
|
|
|
|
|
|
|
|
#define NO_MD5 (!(HASH_CHECK) && !(HAS_MD5))
|
|
|
|
|
|
|
|
|
|
#define BITS32 (sizeof(long) == 4)
|
|
|
|
|
|
|
|
|
|
#define CTYPE_NONE 3
|
|
|
|
|
#define CTYPE_BZIP2 4
|
|
|
|
|
#define CTYPE_LZO 5
|
|
|
|
|
#define CTYPE_LZMA 6
|
|
|
|
|
#define CTYPE_GZIP 7
|
|
|
|
|
#define CTYPE_ZPAQ 8
|
|
|
|
|
|
2011-03-15 06:32:32 +01:00
|
|
|
#define PASS_LEN 512
|
2011-03-15 11:18:29 +01:00
|
|
|
#define HASH_LEN 64
|
2011-03-18 07:32:47 +01:00
|
|
|
#define SALT_LEN 8
|
2011-03-15 13:52:39 +01:00
|
|
|
#define CBC_LEN 16
|
2011-03-15 06:32:32 +01:00
|
|
|
|
2011-08-11 06:52:59 +02:00
|
|
|
#define one_g (1000 * 1024 * 1024)
|
|
|
|
|
|
2011-08-11 05:57:20 +02:00
|
|
|
#if defined(NOTHREAD) || !defined(_SC_NPROCESSORS_ONLN)
|
|
|
|
|
# define PROCESSORS (1)
|
|
|
|
|
#else
|
|
|
|
|
# define PROCESSORS (sysconf(_SC_NPROCESSORS_ONLN))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef _SC_PAGE_SIZE
|
|
|
|
|
# define PAGE_SIZE (sysconf(_SC_PAGE_SIZE))
|
|
|
|
|
#else
|
|
|
|
|
# define PAGE_SIZE (4096)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Determine how many times to hash the password when encrypting, based on
|
|
|
|
|
* the date such that we increase the number of loops according to Moore's
|
|
|
|
|
* law relative to when the data is encrypted. It is then stored as a two
|
|
|
|
|
* byte value in the header */
|
|
|
|
|
#define MOORE 1.835 // world constant [TIMES per YEAR]
|
|
|
|
|
#define ARBITRARY 1000000 // number of sha2 calls per one second in 2011
|
|
|
|
|
#define T_ZERO 1293840000 // seconds since epoch in 2011
|
|
|
|
|
|
|
|
|
|
#define SECONDS_IN_A_YEAR (365*86400)
|
|
|
|
|
#define MOORE_TIMES_PER_SECOND pow (MOORE, 1.0 / SECONDS_IN_A_YEAR)
|
|
|
|
|
#define ARBITRARY_AT_EPOCH (ARBITRARY * pow (MOORE_TIMES_PER_SECOND, -T_ZERO))
|
|
|
|
|
|
2011-08-11 09:06:32 +02:00
|
|
|
#define FLAG_VERBOSE (FLAG_VERBOSITY | FLAG_VERBOSITY_MAX)
|
|
|
|
|
#define FLAG_NOT_LZMA (FLAG_NO_COMPRESS | FLAG_LZO_COMPRESS | FLAG_BZIP2_COMPRESS | FLAG_ZLIB_COMPRESS | FLAG_ZPAQ_COMPRESS)
|
|
|
|
|
#define LZMA_COMPRESS (!(control->flags & FLAG_NOT_LZMA))
|
|
|
|
|
|
|
|
|
|
#define SHOW_PROGRESS (control->flags & FLAG_SHOW_PROGRESS)
|
|
|
|
|
#define KEEP_FILES (control->flags & FLAG_KEEP_FILES)
|
|
|
|
|
#define TEST_ONLY (control->flags & FLAG_TEST_ONLY)
|
|
|
|
|
#define FORCE_REPLACE (control->flags & FLAG_FORCE_REPLACE)
|
|
|
|
|
#define DECOMPRESS (control->flags & FLAG_DECOMPRESS)
|
|
|
|
|
#define NO_COMPRESS (control->flags & FLAG_NO_COMPRESS)
|
|
|
|
|
#define LZO_COMPRESS (control->flags & FLAG_LZO_COMPRESS)
|
|
|
|
|
#define BZIP2_COMPRESS (control->flags & FLAG_BZIP2_COMPRESS)
|
|
|
|
|
#define ZLIB_COMPRESS (control->flags & FLAG_ZLIB_COMPRESS)
|
|
|
|
|
#define ZPAQ_COMPRESS (control->flags & FLAG_ZPAQ_COMPRESS)
|
|
|
|
|
#define VERBOSE (control->flags & FLAG_VERBOSE)
|
|
|
|
|
#define VERBOSITY (control->flags & FLAG_VERBOSITY)
|
|
|
|
|
#define MAX_VERBOSE (control->flags & FLAG_VERBOSITY_MAX)
|
|
|
|
|
#define STDIN (control->flags & FLAG_STDIN)
|
|
|
|
|
#define STDOUT (control->flags & FLAG_STDOUT)
|
|
|
|
|
#define INFO (control->flags & FLAG_INFO)
|
|
|
|
|
#define UNLIMITED (control->flags & FLAG_UNLIMITED)
|
|
|
|
|
#define HASH_CHECK (control->flags & FLAG_HASH)
|
|
|
|
|
#define HAS_MD5 (control->flags & FLAG_MD5)
|
|
|
|
|
#define CHECK_FILE (control->flags & FLAG_CHECK)
|
|
|
|
|
#define KEEP_BROKEN (control->flags & FLAG_KEEP_BROKEN)
|
|
|
|
|
#define LZO_TEST (control->flags & FLAG_THRESHOLD)
|
|
|
|
|
#define TMP_OUTBUF (control->flags & FLAG_TMP_OUTBUF)
|
|
|
|
|
#define TMP_INBUF (control->flags & FLAG_TMP_INBUF)
|
|
|
|
|
#define ENCRYPT (control->flags & FLAG_ENCRYPT)
|
|
|
|
|
|
2011-03-08 22:34:44 +01:00
|
|
|
|
|
|
|
|
/* Structure to save state of computation between the single steps. */
|
|
|
|
|
struct md5_ctx
|
|
|
|
|
{
|
2011-03-13 12:19:28 +01:00
|
|
|
uint32_t A;
|
|
|
|
|
uint32_t B;
|
|
|
|
|
uint32_t C;
|
|
|
|
|
uint32_t D;
|
|
|
|
|
|
|
|
|
|
uint32_t total[2];
|
|
|
|
|
uint32_t buflen;
|
|
|
|
|
uint32_t buffer[32];
|
2011-03-08 22:34:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct rzip_control {
|
|
|
|
|
char *infile;
|
2011-08-13 08:21:45 +02:00
|
|
|
FILE *inFILE; // if a FILE is being read from
|
2011-03-08 22:34:44 +01:00
|
|
|
char *outname;
|
|
|
|
|
char *outfile;
|
2011-08-13 08:21:45 +02:00
|
|
|
FILE *outFILE; // if a FILE is being written to
|
2011-03-08 22:34:44 +01:00
|
|
|
char *outdir;
|
|
|
|
|
char *tmpdir; // when stdin, stdout, or test used
|
2011-03-21 13:09:39 +01:00
|
|
|
uchar *tmp_outbuf; // Temporary file storage for stdout
|
2011-03-12 04:13:28 +01:00
|
|
|
i64 out_ofs; // Output offset when tmp_outbuf in use
|
2011-03-14 00:07:51 +01:00
|
|
|
i64 hist_ofs; // History offset
|
2011-03-12 09:56:08 +01:00
|
|
|
i64 out_len; // Total length of tmp_outbuf
|
2011-03-12 22:16:46 +01:00
|
|
|
i64 out_maxlen; // The largest the tmp_outbuf can be used
|
2011-03-14 04:47:26 +01:00
|
|
|
i64 out_relofs; // Relative tmp_outbuf offset when stdout has been flushed
|
2011-03-21 13:09:39 +01:00
|
|
|
uchar *tmp_inbuf;
|
2011-03-14 04:47:26 +01:00
|
|
|
i64 in_ofs;
|
|
|
|
|
i64 in_len;
|
|
|
|
|
i64 in_maxlen;
|
2011-03-08 22:34:44 +01:00
|
|
|
FILE *msgout; //stream for output messages
|
2011-08-13 08:21:45 +02:00
|
|
|
FILE *msgerr; //stream for output errors
|
2011-08-11 11:44:16 +02:00
|
|
|
char *suffix;
|
2011-03-22 15:51:40 +01:00
|
|
|
uchar compression_level;
|
2011-03-08 22:34:44 +01:00
|
|
|
i64 overhead; // compressor overhead
|
2011-03-22 02:10:21 +01:00
|
|
|
i64 usable_ram; // the most ram we'll try to use on one activity
|
2011-03-08 22:34:44 +01:00
|
|
|
i64 maxram; // the largest chunk of ram to allocate
|
|
|
|
|
unsigned char lzma_properties[5]; // lzma properties, encoded
|
|
|
|
|
i64 window;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
i64 ramsize;
|
|
|
|
|
i64 max_chunk;
|
|
|
|
|
i64 max_mmap;
|
|
|
|
|
int threads;
|
2011-03-22 15:51:40 +01:00
|
|
|
char nice_val; // added for consistency
|
2011-03-20 12:22:54 +01:00
|
|
|
char major_version;
|
|
|
|
|
char minor_version;
|
2011-03-08 22:34:44 +01:00
|
|
|
i64 st_size;
|
|
|
|
|
long page_size;
|
2011-03-14 04:58:41 +01:00
|
|
|
int fd_in;
|
2011-03-08 22:34:44 +01:00
|
|
|
int fd_out;
|
2011-03-14 00:07:51 +01:00
|
|
|
int fd_hist;
|
2011-03-12 10:31:56 +01:00
|
|
|
i64 encloops;
|
2011-03-11 13:29:56 +01:00
|
|
|
i64 secs;
|
2011-08-11 09:41:22 +02:00
|
|
|
void (*pass_cb)(void *, char *, size_t); /* callback to get password in lib */
|
|
|
|
|
void *pass_data;
|
2011-03-21 10:56:36 +01:00
|
|
|
uchar salt[SALT_LEN];
|
2011-03-21 10:54:53 +01:00
|
|
|
uchar *salt_pass;
|
|
|
|
|
int salt_pass_len;
|
2011-03-15 11:18:29 +01:00
|
|
|
uchar *hash;
|
2011-03-12 01:17:11 +01:00
|
|
|
unsigned char eof;
|
2011-03-12 12:46:57 +01:00
|
|
|
unsigned char magic_written;
|
2011-03-08 22:34:44 +01:00
|
|
|
md5_ctx ctx;
|
2011-08-13 08:21:45 +02:00
|
|
|
uchar md5_resblock[MD5_DIGEST_SIZE];
|
2011-03-08 22:50:46 +01:00
|
|
|
i64 md5_read; // How far into the file the md5 has done so far
|
2011-08-11 09:06:32 +02:00
|
|
|
const char *util_infile;
|
|
|
|
|
char delete_infile;
|
|
|
|
|
const char *util_outfile;
|
2011-08-13 09:35:36 +02:00
|
|
|
#define STREAM_BUCKET_SIZE 20
|
|
|
|
|
size_t sinfo_buckets;
|
|
|
|
|
size_t sinfo_idx;
|
|
|
|
|
struct stream_info **sinfo_queue;
|
2011-08-11 09:06:32 +02:00
|
|
|
char delete_outfile;
|
|
|
|
|
FILE *outputfile;
|
2011-08-12 08:43:42 +02:00
|
|
|
char library_mode : 1;
|
2011-08-13 08:21:45 +02:00
|
|
|
int log_level;
|
|
|
|
|
void (*log_cb)(void *data, unsigned int level, unsigned int line, const char *file, const char *func, const char *format, va_list);
|
2011-08-12 08:43:42 +02:00
|
|
|
void *log_data;
|
2011-03-08 22:34:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct stream {
|
|
|
|
|
i64 last_head;
|
|
|
|
|
uchar *buf;
|
|
|
|
|
i64 buflen;
|
|
|
|
|
i64 bufp;
|
2011-03-22 15:51:40 +01:00
|
|
|
uchar eos;
|
2011-03-08 22:34:44 +01:00
|
|
|
long uthread_no;
|
|
|
|
|
long unext_thread;
|
|
|
|
|
long base_thread;
|
|
|
|
|
int total_threads;
|
2011-03-20 05:45:44 +01:00
|
|
|
i64 last_headofs;
|
2011-03-08 22:34:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct stream_info {
|
|
|
|
|
struct stream *s;
|
2011-03-22 15:51:40 +01:00
|
|
|
uchar num_streams;
|
2011-03-08 22:34:44 +01:00
|
|
|
int fd;
|
|
|
|
|
i64 bufsize;
|
|
|
|
|
i64 cur_pos;
|
|
|
|
|
i64 initial_pos;
|
|
|
|
|
i64 ram_alloced;
|
2011-03-12 01:17:11 +01:00
|
|
|
i64 size;
|
2011-03-08 22:34:44 +01:00
|
|
|
long thread_no;
|
|
|
|
|
long next_thread;
|
|
|
|
|
int chunks;
|
|
|
|
|
char chunk_bytes;
|
|
|
|
|
};
|
2011-08-13 08:21:45 +02:00
|
|
|
|
|
|
|
|
static inline void print_stuff(const rzip_control *control, int level, unsigned int line, const char *file, const char *func, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
if (control->library_mode && control->log_cb && (control->log_level >= level)) {
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
control->log_cb(control->log_data, level, line, file, func, format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
} else if (control->msgout) {
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vfprintf(control->msgout, format, ap);
|
|
|
|
|
fflush(control->msgout);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void print_err(const rzip_control *control, unsigned int line, const char *file, const char *func, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
if (control->library_mode && control->log_cb && (control->log_level >= 0)) {
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
control->log_cb(control->log_data, 0, line, file, func, format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
} else if (control->msgerr) {
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vfprintf(control->msgerr, format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define print_stuff(level, format, args...) do {\
|
|
|
|
|
print_stuff(control, level, __LINE__, __FILE__, __func__, format, ##args); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define print_output(format, args...) do {\
|
|
|
|
|
print_stuff(1, format, ##args); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define print_progress(format, args...) do {\
|
|
|
|
|
if (SHOW_PROGRESS) \
|
|
|
|
|
print_stuff(2, format, ##args); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define print_verbose(format, args...) do {\
|
|
|
|
|
if (VERBOSE) \
|
|
|
|
|
print_stuff(3, format, ##args); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define print_maxverbose(format, args...) do {\
|
|
|
|
|
if (MAX_VERBOSE) \
|
|
|
|
|
print_stuff(4, format, ##args); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define print_err(format, args...) do {\
|
|
|
|
|
print_err(control, __LINE__, __FILE__, __func__, format, ##args); \
|
|
|
|
|
} while (0)
|
2011-03-08 22:34:44 +01:00
|
|
|
#endif
|