Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/subr_compressor.c
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | struct compressor { | ||||
void *priv; | void *priv; | ||||
void *arg; | void *arg; | ||||
}; | }; | ||||
SET_DECLARE(compressors, struct compressor_methods); | SET_DECLARE(compressors, struct compressor_methods); | ||||
#ifdef GZIO | #ifdef GZIO | ||||
#include <sys/gsb_crc32.h> | #include <contrib/zlib/zutil.h> | ||||
#include <sys/zutil.h> | |||||
struct gz_stream { | struct gz_stream { | ||||
uint8_t *gz_buffer; /* output buffer */ | uint8_t *gz_buffer; /* output buffer */ | ||||
size_t gz_bufsz; /* output buffer size */ | size_t gz_bufsz; /* output buffer size */ | ||||
off_t gz_off; /* offset into the output stream */ | off_t gz_off; /* offset into the output stream */ | ||||
uint32_t gz_crc; /* stream CRC32 */ | uint32_t gz_crc; /* stream CRC32 */ | ||||
z_stream gz_stream; /* zlib state */ | z_stream gz_stream; /* zlib state */ | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
gz_reset(void *stream) | gz_reset(void *stream) | ||||
{ | { | ||||
struct gz_stream *s; | struct gz_stream *s; | ||||
uint8_t *hdr; | uint8_t *hdr; | ||||
const size_t hdrlen = 10; | const size_t hdrlen = 10; | ||||
s = stream; | s = stream; | ||||
s->gz_off = 0; | s->gz_off = 0; | ||||
s->gz_crc = ~0U; | s->gz_crc = crc32(0L, Z_NULL, 0); | ||||
(void)deflateReset(&s->gz_stream); | (void)deflateReset(&s->gz_stream); | ||||
s->gz_stream.avail_out = s->gz_bufsz; | s->gz_stream.avail_out = s->gz_bufsz; | ||||
s->gz_stream.next_out = s->gz_buffer; | s->gz_stream.next_out = s->gz_buffer; | ||||
/* Write the gzip header to the output buffer. */ | /* Write the gzip header to the output buffer. */ | ||||
hdr = s->gz_buffer; | hdr = s->gz_buffer; | ||||
memset(hdr, 0, hdrlen); | memset(hdr, 0, hdrlen); | ||||
Show All 15 Lines | gz_write(void *stream, void *data, size_t len, compressor_cb_t cb, | ||||
int error, zerror, zflag; | int error, zerror, zflag; | ||||
s = stream; | s = stream; | ||||
zflag = data == NULL ? Z_FINISH : Z_NO_FLUSH; | zflag = data == NULL ? Z_FINISH : Z_NO_FLUSH; | ||||
if (len > 0) { | if (len > 0) { | ||||
s->gz_stream.avail_in = len; | s->gz_stream.avail_in = len; | ||||
s->gz_stream.next_in = data; | s->gz_stream.next_in = data; | ||||
s->gz_crc = crc32_raw(data, len, s->gz_crc); | s->gz_crc = crc32(s->gz_crc, data, len); | ||||
} else | } | ||||
s->gz_crc ^= ~0U; | |||||
error = 0; | error = 0; | ||||
do { | do { | ||||
zerror = deflate(&s->gz_stream, zflag); | zerror = deflate(&s->gz_stream, zflag); | ||||
if (zerror != Z_OK && zerror != Z_STREAM_END) { | if (zerror != Z_OK && zerror != Z_STREAM_END) { | ||||
error = EIO; | error = EIO; | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 374 Lines • Show Last 20 Lines |