lrzip  0.641
About: lrzip (Long Range ZIP or Lzma RZIP) is a compression program optimised for large files. It combines the best parts of various algorithms for large files and scales with increasing RAM size.
  Fossies Dox: lrzip-0.641.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

stream.c File Reference
#include <sys/statvfs.h>
#include <pthread.h>
#include <bzlib.h>
#include <zlib.h>
#include <lzo/lzoconf.h>
#include <lzo/lzo1x.h>
#include <lz4.h>
#include "lzma/C/LzmaLib.h"
#include "util.h"
#include "lrzip_core.h"
Include dependency graph for stream.c:

Go to the source code of this file.

Data Structures

struct  compress_thread
 
struct  stream_thread_struct
 

Macros

#define STREAM_BUFSIZE   (1024 * 1024 * 10)
 
#define MIN_SIZE   (ENCRYPT ? CBC_LEN : 0)
 

Typedefs

typedef struct stream_thread_struct stream_thread_struct
 

Functions

bool init_mutex (rzip_control *control, pthread_mutex_t *mutex)
 
bool unlock_mutex (rzip_control *control, pthread_mutex_t *mutex)
 
bool lock_mutex (rzip_control *control, pthread_mutex_t *mutex)
 
static bool cond_wait (rzip_control *control, pthread_cond_t *cond, pthread_mutex_t *mutex)
 
static bool cond_broadcast (rzip_control *control, pthread_cond_t *cond)
 
bool create_pthread (rzip_control *control, pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
 
bool detach_pthread (rzip_control *control, pthread_t *thread)
 
bool join_pthread (rzip_control *control, pthread_t th, void **thread_return)
 
static int lz4_compresses (rzip_control *control, unsigned char *s_buf, i64 s_len)
 
static int zpaq_compress_buf (rzip_control *control, struct compress_thread *cthread, long thread)
 
static int bzip2_compress_buf (rzip_control *control, struct compress_thread *cthread)
 
static int gzip_compress_buf (rzip_control *control, struct compress_thread *cthread)
 
static int lzma_compress_buf (rzip_control *control, struct compress_thread *cthread)
 
static int lzo_compress_buf (rzip_control *control, struct compress_thread *cthread)
 
static int zpaq_decompress_buf (rzip_control *control __UNUSED__, struct uncomp_thread *ucthread, long thread)
 
static int bzip2_decompress_buf (rzip_control *control __UNUSED__, struct uncomp_thread *ucthread)
 
static int gzip_decompress_buf (rzip_control *control __UNUSED__, struct uncomp_thread *ucthread)
 
static int lzma_decompress_buf (rzip_control *control, struct uncomp_thread *ucthread)
 
static int lzo_decompress_buf (rzip_control *control __UNUSED__, struct uncomp_thread *ucthread)
 
ssize_t put_fdout (rzip_control *control, void *offset_buf, ssize_t ret)
 
ssize_t write_1g (rzip_control *control, void *buf, i64 len)
 
static bool read_fdin (struct rzip_control *control, i64 len)
 
static int dump_stdin (rzip_control *control)
 
ssize_t read_1g (rzip_control *control, int fd, void *buf, i64 len)
 
static int write_buf (rzip_control *control, unsigned char *p, i64 len)
 
static int write_u8 (rzip_control *control, unsigned char v)
 
static int write_val (rzip_control *control, i64 v, int len)
 
static int read_buf (rzip_control *control, int f, unsigned char *p, i64 len)
 
static int read_u8 (rzip_control *control, int f, unsigned char *v)
 
static int read_u32 (rzip_control *control, int f, u32 *v)
 
static int read_val (rzip_control *control, int f, i64 *v, int len)
 
static int fd_seekto (rzip_control *control, struct stream_info *sinfo, i64 spos, i64 pos)
 
static int seekto (rzip_control *control, struct stream_info *sinfo, i64 pos)
 
static int read_seekto (rzip_control *control, struct stream_info *sinfo, i64 pos)
 
static i64 get_seek (rzip_control *control, int fd)
 
i64 get_readseek (rzip_control *control, int fd)
 
bool prepare_streamout_threads (rzip_control *control)
 
bool close_streamout_threads (rzip_control *control)
 
void * open_stream_out (rzip_control *control, int f, unsigned int n, i64 chunk_limit, char cbytes)
 
static bool decrypt_header (rzip_control *control, unsigned char *head, unsigned char *c_type, i64 *c_len, i64 *u_len, i64 *last_head)
 
void * open_stream_in (rzip_control *control, int f, int n, char chunk_bytes)
 
static bool rewrite_encrypted (rzip_control *control, struct stream_info *sinfo, i64 ofs)
 
static void * compthread (void *data)
 
static void clear_buffer (rzip_control *control, struct stream_info *sinfo, int streamno, int newbuf)
 
void flush_buffer (rzip_control *control, struct stream_info *sinfo, int streamno)
 
static void * ucompthread (void *data)
 
static int fill_buffer (rzip_control *control, struct stream_info *sinfo, struct stream *s, int streamno)
 
void write_stream (rzip_control *control, void *ss, int streamno, unsigned char *p, i64 len)
 
i64 read_stream (rzip_control *control, void *ss, int streamno, unsigned char *p, i64 len)
 
int close_stream_out (rzip_control *control, void *ss)
 
static void add_to_rulist (rzip_control *control, struct stream_info *sinfo)
 
int close_stream_in (rzip_control *control, void *ss)
 

Variables

static struct compress_threadcthreads
 
static long output_thread
 
static pthread_mutex_t output_lock = PTHREAD_MUTEX_INITIALIZER
 
static pthread_cond_t output_cond = PTHREAD_COND_INITIALIZER
 

Macro Definition Documentation

◆ MIN_SIZE

#define MIN_SIZE   (ENCRYPT ? CBC_LEN : 0)

Definition at line 1225 of file stream.c.

◆ STREAM_BUFSIZE

#define STREAM_BUFSIZE   (1024 * 1024 * 10)

Definition at line 64 of file stream.c.

Typedef Documentation

◆ stream_thread_struct

Function Documentation

◆ add_to_rulist()

static void add_to_rulist ( rzip_control control,
struct stream_info sinfo 
)
static

◆ bzip2_compress_buf()

◆ bzip2_decompress_buf()

static int bzip2_decompress_buf ( rzip_control *control  __UNUSED__,
struct uncomp_thread ucthread 
)
static

◆ clear_buffer()

◆ close_stream_in()

◆ close_stream_out()

int close_stream_out ( rzip_control control,
void *  ss 
)

◆ close_streamout_threads()

bool close_streamout_threads ( rzip_control control)

Definition at line 909 of file stream.c.

References cksem_wait(), control, cthreads, dealloc, output_thread, rzip_control::pthreads, and rzip_control::threads.

Referenced by rzip_fd().

◆ compthread()

◆ cond_broadcast()

static bool cond_broadcast ( rzip_control control,
pthread_cond_t *  cond 
)
static

Definition at line 115 of file stream.c.

References fatal_return, and unlikely.

Referenced by compthread(), and fill_buffer().

◆ cond_wait()

static bool cond_wait ( rzip_control control,
pthread_cond_t *  cond,
pthread_mutex_t *  mutex 
)
static

Definition at line 108 of file stream.c.

References fatal_return, and unlikely.

Referenced by compthread(), and ucompthread().

◆ create_pthread()

bool create_pthread ( rzip_control control,
pthread_t *  thread,
pthread_attr_t *  attr,
void *(*)(void *)  start_routine,
void *  arg 
)

Definition at line 122 of file stream.c.

References fatal_return, and unlikely.

Referenced by cksum_update(), clear_buffer(), and fill_buffer().

◆ decrypt_header()

static bool decrypt_header ( rzip_control control,
unsigned char *  head,
unsigned char *  c_type,
i64 c_len,
i64 u_len,
i64 last_head 
)
static

Definition at line 1040 of file stream.c.

References control, lrz_decrypt(), SALT_LEN, uchar, and unlikely.

Referenced by fill_buffer(), and open_stream_in().

◆ detach_pthread()

bool detach_pthread ( rzip_control control,
pthread_t *  thread 
)

Definition at line 130 of file stream.c.

References fatal_return, and unlikely.

Referenced by clear_buffer().

◆ dump_stdin()

static int dump_stdin ( rzip_control control)
static

Definition at line 675 of file stream.c.

References close_tmpinbuf(), control, rzip_control::fd_in, read_tmpinfile(), unlikely, and write_fdin().

Referenced by read_1g(), and read_seekto().

◆ fd_seekto()

static int fd_seekto ( rzip_control control,
struct stream_info sinfo,
i64  spos,
i64  pos 
)
static

Definition at line 799 of file stream.c.

References stream_info::fd, print_err, and unlikely.

Referenced by read_seekto(), and seekto().

◆ fill_buffer()

◆ flush_buffer()

void flush_buffer ( rzip_control control,
struct stream_info sinfo,
int  streamno 
)

Definition at line 1518 of file stream.c.

References clear_buffer(), and control.

Referenced by write_sbstream(), and write_stream().

◆ get_readseek()

i64 get_readseek ( rzip_control control,
int  fd 
)

◆ get_seek()

static i64 get_seek ( rzip_control control,
int  fd 
)
static

◆ gzip_compress_buf()

◆ gzip_decompress_buf()

static int gzip_decompress_buf ( rzip_control *control  __UNUSED__,
struct uncomp_thread ucthread 
)
static

◆ init_mutex()

bool init_mutex ( rzip_control control,
pthread_mutex_t *  mutex 
)

Definition at line 87 of file stream.c.

References fatal_return, and unlikely.

Referenced by rzip_fd().

◆ join_pthread()

bool join_pthread ( rzip_control control,
pthread_t  th,
void **  thread_return 
)

Definition at line 137 of file stream.c.

References fatal_return.

Referenced by fill_buffer().

◆ lock_mutex()

bool lock_mutex ( rzip_control control,
pthread_mutex_t *  mutex 
)

Definition at line 101 of file stream.c.

References fatal_return, and unlikely.

Referenced by compthread(), fill_buffer(), lzma_compress_buf(), and ucompthread().

◆ lz4_compresses()

static int lz4_compresses ( rzip_control control,
unsigned char *  s_buf,
i64  s_len 
)
static

◆ lzma_compress_buf()

◆ lzma_decompress_buf()

static int lzma_decompress_buf ( rzip_control control,
struct uncomp_thread ucthread 
)
static

◆ lzo_compress_buf()

static int lzo_compress_buf ( rzip_control control,
struct compress_thread cthread 
)
static

◆ lzo_decompress_buf()

static int lzo_decompress_buf ( rzip_control *control  __UNUSED__,
struct uncomp_thread ucthread 
)
static

◆ open_stream_in()

◆ open_stream_out()

◆ prepare_streamout_threads()

bool prepare_streamout_threads ( rzip_control control)

◆ put_fdout()

ssize_t put_fdout ( rzip_control control,
void *  offset_buf,
ssize_t  ret 
)

◆ read_1g()

◆ read_buf()

static int read_buf ( rzip_control control,
int  f,
unsigned char *  p,
i64  len 
)
static

◆ read_fdin()

static bool read_fdin ( struct rzip_control control,
i64  len 
)
static

◆ read_seekto()

static int read_seekto ( rzip_control control,
struct stream_info sinfo,
i64  pos 
)
static

◆ read_stream()

i64 read_stream ( rzip_control control,
void *  ss,
int  streamno,
unsigned char *  p,
i64  len 
)

◆ read_u32()

static int read_u32 ( rzip_control control,
int  f,
u32 v 
)
inlinestatic

Definition at line 781 of file stream.c.

References control, le32toh, read_buf(), and uchar.

Referenced by fill_buffer(), and open_stream_in().

◆ read_u8()

static int read_u8 ( rzip_control control,
int  f,
unsigned char *  v 
)
inlinestatic

Definition at line 776 of file stream.c.

References control, and read_buf().

Referenced by fill_buffer(), and open_stream_in().

◆ read_val()

static int read_val ( rzip_control control,
int  f,
i64 v,
int  len 
)
inlinestatic

Definition at line 789 of file stream.c.

References control, read_buf(), and uchar.

Referenced by fill_buffer(), and open_stream_in().

◆ rewrite_encrypted()

static bool rewrite_encrypted ( rzip_control control,
struct stream_info sinfo,
i64  ofs 
)
static

◆ seekto()

static int seekto ( rzip_control control,
struct stream_info sinfo,
i64  pos 
)
static

◆ ucompthread()

◆ unlock_mutex()

bool unlock_mutex ( rzip_control control,
pthread_mutex_t *  mutex 
)

Definition at line 94 of file stream.c.

References fatal_return, and unlikely.

Referenced by compthread(), fill_buffer(), lzma_compress_buf(), and ucompthread().

◆ write_1g()

ssize_t write_1g ( rzip_control control,
void *  buf,
i64  len 
)

Definition at line 637 of file stream.c.

References control, MIN, one_g, put_fdout(), uchar, and unlikely.

Referenced by rzip_fd(), unzip_literal(), unzip_match(), and write_buf().

◆ write_buf()

static int write_buf ( rzip_control control,
unsigned char *  p,
i64  len 
)
static

Definition at line 732 of file stream.c.

References control, errno, print_err, strerror, unlikely, and write_1g().

Referenced by compthread(), rewrite_encrypted(), write_u8(), and write_val().

◆ write_stream()

void write_stream ( rzip_control control,
void *  ss,
int  streamno,
unsigned char *  p,
i64  len 
)

Definition at line 1755 of file stream.c.

References stream::buf, stream::buflen, stream_info::bufsize, control, flush_buffer(), MIN, and stream_info::s.

Referenced by put_u32(), put_u8(), and put_vchars().

◆ write_u8()

static int write_u8 ( rzip_control control,
unsigned char  v 
)
inlinestatic

Definition at line 749 of file stream.c.

References control, and write_buf().

Referenced by compthread().

◆ write_val()

static int write_val ( rzip_control control,
i64  v,
int  len 
)
inlinestatic

Definition at line 754 of file stream.c.

References control, htole64, uchar, and write_buf().

Referenced by compthread().

◆ zpaq_compress_buf()

◆ zpaq_decompress_buf()

static int zpaq_decompress_buf ( rzip_control *control  __UNUSED__,
struct uncomp_thread ucthread,
long  thread 
)
static

Variable Documentation

◆ cthreads

◆ output_cond

pthread_cond_t output_cond = PTHREAD_COND_INITIALIZER
static

Definition at line 85 of file stream.c.

Referenced by compthread(), fill_buffer(), and ucompthread().

◆ output_lock

pthread_mutex_t output_lock = PTHREAD_MUTEX_INITIALIZER
static

Definition at line 84 of file stream.c.

Referenced by compthread(), fill_buffer(), and ucompthread().

◆ output_thread

long output_thread
static