003 File Manager
Current Path:
/usr/src/sys/kern
usr
/
src
/
sys
/
kern
/
📁
..
📄
Make.tags.inc
(2.13 KB)
📄
Makefile
(302 B)
📄
bus_if.m
(26.31 KB)
📄
capabilities.conf
(13.67 KB)
📄
clock_if.m
(1.7 KB)
📄
cpufreq_if.m
(2.27 KB)
📄
device_if.m
(10.41 KB)
📄
firmw.S
(2.15 KB)
📄
genassym.sh
(1.11 KB)
📄
genoffset.c
(1.68 KB)
📄
genoffset.sh
(3.58 KB)
📄
imgact_aout.c
(9.45 KB)
📄
imgact_binmisc.c
(18.64 KB)
📄
imgact_elf.c
(76.32 KB)
📄
imgact_elf32.c
(1.47 KB)
📄
imgact_elf64.c
(1.47 KB)
📄
imgact_shell.c
(8.41 KB)
📄
init_main.c
(24.31 KB)
📄
init_sysent.c
(95.3 KB)
📄
kern_acct.c
(19.03 KB)
📄
kern_alq.c
(24.97 KB)
📄
kern_clock.c
(21.12 KB)
📄
kern_clocksource.c
(23.34 KB)
📄
kern_condvar.c
(11.28 KB)
📄
kern_conf.c
(36.14 KB)
📄
kern_cons.c
(15.75 KB)
📄
kern_context.c
(3.59 KB)
📄
kern_cpu.c
(30.77 KB)
📄
kern_cpuset.c
(59.78 KB)
📄
kern_ctf.c
(8.73 KB)
📄
kern_descrip.c
(112.87 KB)
📄
kern_dtrace.c
(2.94 KB)
📄
kern_dump.c
(8.51 KB)
📄
kern_environment.c
(22.75 KB)
📄
kern_et.c
(7.1 KB)
📄
kern_event.c
(62.49 KB)
📄
kern_exec.c
(46.67 KB)
📄
kern_exit.c
(34.61 KB)
📄
kern_fail.c
(29.32 KB)
📄
kern_ffclock.c
(12.66 KB)
📄
kern_fork.c
(28.29 KB)
📄
kern_hhook.c
(13.58 KB)
📄
kern_idle.c
(2.74 KB)
📄
kern_intr.c
(40.44 KB)
📄
kern_jail.c
(112.67 KB)
📄
kern_kcov.c
(15.32 KB)
📄
kern_khelp.c
(9.45 KB)
📄
kern_kthread.c
(11.8 KB)
📄
kern_ktr.c
(11.93 KB)
📄
kern_ktrace.c
(31.41 KB)
📄
kern_linker.c
(54.3 KB)
📄
kern_lock.c
(46.99 KB)
📄
kern_lockf.c
(64.46 KB)
📄
kern_lockstat.c
(3.8 KB)
📄
kern_loginclass.c
(6.69 KB)
📄
kern_malloc.c
(37.09 KB)
📄
kern_mbuf.c
(43.16 KB)
📄
kern_mib.c
(24.26 KB)
📄
kern_module.c
(11.05 KB)
📄
kern_mtxpool.c
(5.82 KB)
📄
kern_mutex.c
(33.62 KB)
📄
kern_ntptime.c
(32.49 KB)
📄
kern_osd.c
(12.37 KB)
📄
kern_physio.c
(5.74 KB)
📄
kern_pmc.c
(8.89 KB)
📄
kern_poll.c
(15.86 KB)
📄
kern_priv.c
(9.14 KB)
📄
kern_proc.c
(80.01 KB)
📄
kern_procctl.c
(19.48 KB)
📄
kern_prot.c
(57.94 KB)
📄
kern_racct.c
(34.01 KB)
📄
kern_rangelock.c
(8.67 KB)
📄
kern_rctl.c
(53.87 KB)
📄
kern_resource.c
(36.66 KB)
📄
kern_rmlock.c
(28.27 KB)
📄
kern_rwlock.c
(40.72 KB)
📄
kern_sdt.c
(2.05 KB)
📄
kern_sema.c
(4.85 KB)
📄
kern_sendfile.c
(33.97 KB)
📄
kern_sharedpage.c
(10.37 KB)
📄
kern_shutdown.c
(43.34 KB)
📄
kern_sig.c
(101.89 KB)
📄
kern_switch.c
(13.85 KB)
📄
kern_sx.c
(40.27 KB)
📄
kern_synch.c
(18.17 KB)
📄
kern_syscalls.c
(6.74 KB)
📄
kern_sysctl.c
(67.24 KB)
📄
kern_tc.c
(55.73 KB)
📄
kern_thr.c
(14.14 KB)
📄
kern_thread.c
(41.75 KB)
📄
kern_time.c
(40.89 KB)
📄
kern_timeout.c
(43.08 KB)
📄
kern_tslog.c
(3.44 KB)
📄
kern_ubsan.c
(50.74 KB)
📄
kern_umtx.c
(107.14 KB)
📄
kern_uuid.c
(11.68 KB)
📄
kern_xxx.c
(10.44 KB)
📄
ksched.c
(6.56 KB)
📄
link_elf.c
(47.99 KB)
📄
link_elf_obj.c
(44.41 KB)
📄
linker_if.m
(3.96 KB)
📄
makesyscalls.sh
(23.57 KB)
📄
md4c.c
(7.89 KB)
📄
md5c.c
(9.56 KB)
📄
msi_if.m
(2.48 KB)
📄
p1003_1b.c
(8.84 KB)
📄
pic_if.m
(3.9 KB)
📄
posix4_mib.c
(5.59 KB)
📄
sched_4bsd.c
(45.03 KB)
📄
sched_ule.c
(82.65 KB)
📄
serdev_if.m
(3.49 KB)
📄
stack_protector.c
(613 B)
📄
subr_acl_nfs4.c
(37.42 KB)
📄
subr_acl_posix1e.c
(17.71 KB)
📄
subr_atomic64.c
(3.97 KB)
📄
subr_autoconf.c
(7.7 KB)
📄
subr_blist.c
(31.88 KB)
📄
subr_boot.c
(5.8 KB)
📄
subr_bufring.c
(2.21 KB)
📄
subr_bus.c
(145.4 KB)
📄
subr_bus_dma.c
(19.67 KB)
📄
subr_busdma_bufalloc.c
(5.24 KB)
📄
subr_capability.c
(11.93 KB)
📄
subr_clock.c
(10.61 KB)
📄
subr_compressor.c
(13.11 KB)
📄
subr_counter.c
(4.44 KB)
📄
subr_coverage.c
(6.17 KB)
📄
subr_csan.c
(25.39 KB)
📄
subr_devmap.c
(9.8 KB)
📄
subr_devstat.c
(16.21 KB)
📄
subr_disk.c
(8.54 KB)
📄
subr_dummy_vdso_tc.c
(1.7 KB)
📄
subr_early.c
(2.26 KB)
📄
subr_epoch.c
(25.02 KB)
📄
subr_eventhandler.c
(9.17 KB)
📄
subr_fattime.c
(9.98 KB)
📄
subr_filter.c
(12.2 KB)
📄
subr_firmware.c
(13.88 KB)
📄
subr_gtaskqueue.c
(20.19 KB)
📄
subr_hash.c
(4.8 KB)
📄
subr_hints.c
(12.87 KB)
📄
subr_intr.c
(40.61 KB)
📄
subr_kdb.c
(16.13 KB)
📄
subr_kobj.c
(7.1 KB)
📄
subr_lock.c
(18.81 KB)
📄
subr_log.c
(7.64 KB)
📄
subr_mchain.c
(11.06 KB)
📄
subr_module.c
(12.98 KB)
📄
subr_msgbuf.c
(10.6 KB)
📄
subr_param.c
(10.93 KB)
📄
subr_pcpu.c
(10.18 KB)
📄
subr_pctrie.c
(20.99 KB)
📄
subr_physmem.c
(11.52 KB)
📄
subr_pidctrl.c
(5.43 KB)
📄
subr_power.c
(3.13 KB)
📄
subr_prf.c
(27.42 KB)
📄
subr_prng.c
(3.36 KB)
📄
subr_prof.c
(15.43 KB)
📄
subr_rangeset.c
(8.5 KB)
📄
subr_rman.c
(27.61 KB)
📄
subr_rtc.c
(11.42 KB)
📄
subr_sbuf.c
(20.53 KB)
📄
subr_scanf.c
(15.59 KB)
📄
subr_sfbuf.c
(6.17 KB)
📄
subr_sglist.c
(22.83 KB)
📄
subr_sleepqueue.c
(39.43 KB)
📄
subr_smp.c
(31.62 KB)
📄
subr_smr.c
(20.17 KB)
📄
subr_stack.c
(6.47 KB)
📄
subr_stats.c
(103.01 KB)
📄
subr_syscall.c
(7.98 KB)
📄
subr_taskqueue.c
(21.1 KB)
📄
subr_terminal.c
(15.52 KB)
📄
subr_trap.c
(10.87 KB)
📄
subr_turnstile.c
(35.58 KB)
📄
subr_uio.c
(11.38 KB)
📄
subr_unit.c
(22.97 KB)
📄
subr_vmem.c
(43.25 KB)
📄
subr_witness.c
(84.59 KB)
📄
sys_capability.c
(15.06 KB)
📄
sys_eventfd.c
(8.42 KB)
📄
sys_generic.c
(44.22 KB)
📄
sys_getrandom.c
(4.21 KB)
📄
sys_pipe.c
(45.14 KB)
📄
sys_procdesc.c
(14.57 KB)
📄
sys_process.c
(30.73 KB)
📄
sys_socket.c
(20.11 KB)
📄
syscalls.c
(22.73 KB)
📄
syscalls.master
(60.26 KB)
📄
systrace_args.c
(178.49 KB)
📄
sysv_ipc.c
(6.53 KB)
📄
sysv_msg.c
(48.65 KB)
📄
sysv_sem.c
(49.85 KB)
📄
sysv_shm.c
(43.93 KB)
📄
tty.c
(55.14 KB)
📄
tty_compat.c
(11.46 KB)
📄
tty_info.c
(9.93 KB)
📄
tty_inq.c
(12.22 KB)
📄
tty_outq.c
(8.74 KB)
📄
tty_pts.c
(19.74 KB)
📄
tty_tty.c
(2.83 KB)
📄
tty_ttydisc.c
(28.6 KB)
📄
uipc_accf.c
(8.07 KB)
📄
uipc_debug.c
(12.42 KB)
📄
uipc_domain.c
(13.13 KB)
📄
uipc_ktls.c
(55.7 KB)
📄
uipc_mbuf.c
(52.45 KB)
📄
uipc_mbuf2.c
(12.64 KB)
📄
uipc_mbufhash.c
(4.9 KB)
📄
uipc_mqueue.c
(64.64 KB)
📄
uipc_sem.c
(25.18 KB)
📄
uipc_shm.c
(50.47 KB)
📄
uipc_sockbuf.c
(42.9 KB)
📄
uipc_socket.c
(110.61 KB)
📄
uipc_syscalls.c
(35.94 KB)
📄
uipc_usrreq.c
(75.11 KB)
📄
vfs_acl.c
(14.5 KB)
📄
vfs_aio.c
(76.32 KB)
📄
vfs_bio.c
(145.39 KB)
📄
vfs_cache.c
(143.09 KB)
📄
vfs_cluster.c
(28.36 KB)
📄
vfs_default.c
(33.16 KB)
📄
vfs_export.c
(14.55 KB)
📄
vfs_extattr.c
(17.91 KB)
📄
vfs_hash.c
(6 KB)
📄
vfs_init.c
(15.86 KB)
📄
vfs_lookup.c
(45.48 KB)
📄
vfs_mount.c
(62.58 KB)
📄
vfs_mountroot.c
(26.23 KB)
📄
vfs_subr.c
(167.52 KB)
📄
vfs_syscalls.c
(106.86 KB)
📄
vfs_vnops.c
(86.28 KB)
📄
vnode_if.src
(13.66 KB)
Editing: subr_compressor.c
/*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2014, 2017 Mark Johnston <markj@FreeBSD.org> * Copyright (c) 2017 Conrad Meyer <cem@FreeBSD.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Subroutines used for writing compressed user process and kernel core dumps. */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); #include "opt_gzio.h" #include "opt_zstdio.h" #include <sys/param.h> #include <sys/systm.h> #include <sys/compressor.h> #include <sys/kernel.h> #include <sys/linker_set.h> #include <sys/malloc.h> MALLOC_DEFINE(M_COMPRESS, "compressor", "kernel compression subroutines"); struct compressor_methods { int format; void *(* const init)(size_t, int); void (* const reset)(void *); int (* const write)(void *, void *, size_t, compressor_cb_t, void *); void (* const fini)(void *); }; struct compressor { const struct compressor_methods *methods; compressor_cb_t cb; void *priv; void *arg; }; SET_DECLARE(compressors, struct compressor_methods); #ifdef GZIO #include <contrib/zlib/zutil.h> struct gz_stream { uint8_t *gz_buffer; /* output buffer */ size_t gz_bufsz; /* output buffer size */ off_t gz_off; /* offset into the output stream */ uint32_t gz_crc; /* stream CRC32 */ z_stream gz_stream; /* zlib state */ }; static void *gz_init(size_t maxiosize, int level); static void gz_reset(void *stream); static int gz_write(void *stream, void *data, size_t len, compressor_cb_t, void *); static void gz_fini(void *stream); static void * gz_alloc(void *arg __unused, u_int n, u_int sz) { /* * Memory for zlib state is allocated using M_NODUMP since it may be * used to compress a kernel dump, and we don't want zlib to attempt to * compress its own state. */ return (malloc(n * sz, M_COMPRESS, M_WAITOK | M_ZERO | M_NODUMP)); } static void gz_free(void *arg __unused, void *ptr) { free(ptr, M_COMPRESS); } static void * gz_init(size_t maxiosize, int level) { struct gz_stream *s; int error; s = gz_alloc(NULL, 1, roundup2(sizeof(*s), PAGE_SIZE)); s->gz_buffer = gz_alloc(NULL, 1, maxiosize); s->gz_bufsz = maxiosize; s->gz_stream.zalloc = gz_alloc; s->gz_stream.zfree = gz_free; s->gz_stream.opaque = NULL; s->gz_stream.next_in = Z_NULL; s->gz_stream.avail_in = 0; if (level != Z_DEFAULT_COMPRESSION) { if (level < Z_BEST_SPEED) level = Z_BEST_SPEED; else if (level > Z_BEST_COMPRESSION) level = Z_BEST_COMPRESSION; } error = deflateInit2(&s->gz_stream, level, Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); if (error != 0) goto fail; gz_reset(s); return (s); fail: gz_free(NULL, s); return (NULL); } static void gz_reset(void *stream) { struct gz_stream *s; uint8_t *hdr; const size_t hdrlen = 10; s = stream; s->gz_off = 0; s->gz_crc = crc32(0L, Z_NULL, 0); (void)deflateReset(&s->gz_stream); s->gz_stream.avail_out = s->gz_bufsz; s->gz_stream.next_out = s->gz_buffer; /* Write the gzip header to the output buffer. */ hdr = s->gz_buffer; memset(hdr, 0, hdrlen); hdr[0] = 0x1f; hdr[1] = 0x8b; hdr[2] = Z_DEFLATED; hdr[9] = OS_CODE; s->gz_stream.next_out += hdrlen; s->gz_stream.avail_out -= hdrlen; } static int gz_write(void *stream, void *data, size_t len, compressor_cb_t cb, void *arg) { struct gz_stream *s; uint8_t trailer[8]; size_t room; int error, zerror, zflag; s = stream; zflag = data == NULL ? Z_FINISH : Z_NO_FLUSH; if (len > 0) { s->gz_stream.avail_in = len; s->gz_stream.next_in = data; s->gz_crc = crc32(s->gz_crc, data, len); } error = 0; do { zerror = deflate(&s->gz_stream, zflag); if (zerror != Z_OK && zerror != Z_STREAM_END) { error = EIO; break; } if (s->gz_stream.avail_out == 0 || zerror == Z_STREAM_END) { /* * Our output buffer is full or there's nothing left * to produce, so we're flushing the buffer. */ len = s->gz_bufsz - s->gz_stream.avail_out; if (zerror == Z_STREAM_END) { /* * Try to pack as much of the trailer into the * output buffer as we can. */ ((uint32_t *)trailer)[0] = s->gz_crc; ((uint32_t *)trailer)[1] = s->gz_stream.total_in; room = MIN(sizeof(trailer), s->gz_bufsz - len); memcpy(s->gz_buffer + len, trailer, room); len += room; } error = cb(s->gz_buffer, len, s->gz_off, arg); if (error != 0) break; s->gz_off += len; s->gz_stream.next_out = s->gz_buffer; s->gz_stream.avail_out = s->gz_bufsz; /* * If we couldn't pack the trailer into the output * buffer, write it out now. */ if (zerror == Z_STREAM_END && room < sizeof(trailer)) error = cb(trailer + room, sizeof(trailer) - room, s->gz_off, arg); } } while (zerror != Z_STREAM_END && (zflag == Z_FINISH || s->gz_stream.avail_in > 0)); return (error); } static void gz_fini(void *stream) { struct gz_stream *s; s = stream; (void)deflateEnd(&s->gz_stream); gz_free(NULL, s->gz_buffer); gz_free(NULL, s); } struct compressor_methods gzip_methods = { .format = COMPRESS_GZIP, .init = gz_init, .reset = gz_reset, .write = gz_write, .fini = gz_fini, }; DATA_SET(compressors, gzip_methods); #endif /* GZIO */ #ifdef ZSTDIO #define ZSTD_STATIC_LINKING_ONLY #include <contrib/zstd/lib/zstd.h> struct zstdio_stream { ZSTD_CCtx *zst_stream; ZSTD_inBuffer zst_inbuffer; ZSTD_outBuffer zst_outbuffer; uint8_t * zst_buffer; /* output buffer */ size_t zst_maxiosz; /* Max output IO size */ off_t zst_off; /* offset into the output stream */ void * zst_static_wkspc; }; static void *zstdio_init(size_t maxiosize, int level); static void zstdio_reset(void *stream); static int zstdio_write(void *stream, void *data, size_t len, compressor_cb_t, void *); static void zstdio_fini(void *stream); static void * zstdio_init(size_t maxiosize, int level) { ZSTD_CCtx *dump_compressor; struct zstdio_stream *s; void *wkspc, *owkspc, *buffer; size_t wkspc_size, buf_size, rc; s = NULL; wkspc_size = ZSTD_estimateCStreamSize(level); owkspc = wkspc = malloc(wkspc_size + 8, M_COMPRESS, M_WAITOK | M_NODUMP); /* Zstd API requires 8-byte alignment. */ if ((uintptr_t)wkspc % 8 != 0) wkspc = (void *)roundup2((uintptr_t)wkspc, 8); dump_compressor = ZSTD_initStaticCCtx(wkspc, wkspc_size); if (dump_compressor == NULL) { printf("%s: workspace too small.\n", __func__); goto out; } rc = ZSTD_CCtx_setParameter(dump_compressor, ZSTD_c_checksumFlag, 1); if (ZSTD_isError(rc)) { printf("%s: error setting checksumFlag: %s\n", __func__, ZSTD_getErrorName(rc)); goto out; } rc = ZSTD_CCtx_setParameter(dump_compressor, ZSTD_c_compressionLevel, level); if (ZSTD_isError(rc)) { printf("%s: error setting compressLevel: %s\n", __func__, ZSTD_getErrorName(rc)); goto out; } buf_size = ZSTD_CStreamOutSize() * 2; buffer = malloc(buf_size, M_COMPRESS, M_WAITOK | M_NODUMP); s = malloc(sizeof(*s), M_COMPRESS, M_NODUMP | M_WAITOK); s->zst_buffer = buffer; s->zst_outbuffer.dst = buffer; s->zst_outbuffer.size = buf_size; s->zst_maxiosz = maxiosize; s->zst_stream = dump_compressor; s->zst_static_wkspc = owkspc; zstdio_reset(s); out: if (s == NULL) free(owkspc, M_COMPRESS); return (s); } static void zstdio_reset(void *stream) { struct zstdio_stream *s; size_t res; s = stream; res = ZSTD_resetCStream(s->zst_stream, 0); if (ZSTD_isError(res)) panic("%s: could not reset stream %p: %s\n", __func__, s, ZSTD_getErrorName(res)); s->zst_off = 0; s->zst_inbuffer.src = NULL; s->zst_inbuffer.size = 0; s->zst_inbuffer.pos = 0; s->zst_outbuffer.pos = 0; } static int zst_flush_intermediate(struct zstdio_stream *s, compressor_cb_t cb, void *arg) { size_t bytes_to_dump; int error; /* Flush as many full output blocks as possible. */ /* XXX: 4096 is arbitrary safe HDD block size for kernel dumps */ while (s->zst_outbuffer.pos >= 4096) { bytes_to_dump = rounddown(s->zst_outbuffer.pos, 4096); if (bytes_to_dump > s->zst_maxiosz) bytes_to_dump = s->zst_maxiosz; error = cb(s->zst_buffer, bytes_to_dump, s->zst_off, arg); if (error != 0) return (error); /* * Shift any non-full blocks up to the front of the output * buffer. */ s->zst_outbuffer.pos -= bytes_to_dump; memmove(s->zst_outbuffer.dst, (char *)s->zst_outbuffer.dst + bytes_to_dump, s->zst_outbuffer.pos); s->zst_off += bytes_to_dump; } return (0); } static int zstdio_flush(struct zstdio_stream *s, compressor_cb_t cb, void *arg) { size_t rc, lastpos; int error; /* * Positive return indicates unflushed data remaining; need to call * endStream again after clearing out room in output buffer. */ rc = 1; lastpos = s->zst_outbuffer.pos; while (rc > 0) { rc = ZSTD_endStream(s->zst_stream, &s->zst_outbuffer); if (ZSTD_isError(rc)) { printf("%s: ZSTD_endStream failed (%s)\n", __func__, ZSTD_getErrorName(rc)); return (EIO); } if (lastpos == s->zst_outbuffer.pos) { printf("%s: did not make forward progress endStream %zu\n", __func__, lastpos); return (EIO); } error = zst_flush_intermediate(s, cb, arg); if (error != 0) return (error); lastpos = s->zst_outbuffer.pos; } /* * We've already done an intermediate flush, so all full blocks have * been written. Only a partial block remains. Padding happens in a * higher layer. */ if (s->zst_outbuffer.pos != 0) { error = cb(s->zst_buffer, s->zst_outbuffer.pos, s->zst_off, arg); if (error != 0) return (error); } return (0); } static int zstdio_write(void *stream, void *data, size_t len, compressor_cb_t cb, void *arg) { struct zstdio_stream *s; size_t lastpos, rc; int error; s = stream; if (data == NULL) return (zstdio_flush(s, cb, arg)); s->zst_inbuffer.src = data; s->zst_inbuffer.size = len; s->zst_inbuffer.pos = 0; lastpos = 0; while (s->zst_inbuffer.pos < s->zst_inbuffer.size) { rc = ZSTD_compressStream(s->zst_stream, &s->zst_outbuffer, &s->zst_inbuffer); if (ZSTD_isError(rc)) { printf("%s: Compress failed on %p! (%s)\n", __func__, data, ZSTD_getErrorName(rc)); return (EIO); } if (lastpos == s->zst_inbuffer.pos) { /* * XXX: May need flushStream to make forward progress */ printf("ZSTD: did not make forward progress @pos %zu\n", lastpos); return (EIO); } lastpos = s->zst_inbuffer.pos; error = zst_flush_intermediate(s, cb, arg); if (error != 0) return (error); } return (0); } static void zstdio_fini(void *stream) { struct zstdio_stream *s; s = stream; if (s->zst_static_wkspc != NULL) free(s->zst_static_wkspc, M_COMPRESS); else ZSTD_freeCCtx(s->zst_stream); free(s->zst_buffer, M_COMPRESS); free(s, M_COMPRESS); } static struct compressor_methods zstd_methods = { .format = COMPRESS_ZSTD, .init = zstdio_init, .reset = zstdio_reset, .write = zstdio_write, .fini = zstdio_fini, }; DATA_SET(compressors, zstd_methods); #endif /* ZSTDIO */ bool compressor_avail(int format) { struct compressor_methods **iter; SET_FOREACH(iter, compressors) { if ((*iter)->format == format) return (true); } return (false); } struct compressor * compressor_init(compressor_cb_t cb, int format, size_t maxiosize, int level, void *arg) { struct compressor_methods **iter; struct compressor *s; void *priv; SET_FOREACH(iter, compressors) { if ((*iter)->format == format) break; } if (iter == SET_LIMIT(compressors)) return (NULL); priv = (*iter)->init(maxiosize, level); if (priv == NULL) return (NULL); s = malloc(sizeof(*s), M_COMPRESS, M_WAITOK | M_ZERO); s->methods = (*iter); s->priv = priv; s->cb = cb; s->arg = arg; return (s); } void compressor_reset(struct compressor *stream) { stream->methods->reset(stream->priv); } int compressor_write(struct compressor *stream, void *data, size_t len) { return (stream->methods->write(stream->priv, data, len, stream->cb, stream->arg)); } int compressor_flush(struct compressor *stream) { return (stream->methods->write(stream->priv, NULL, 0, stream->cb, stream->arg)); } void compressor_fini(struct compressor *stream) { stream->methods->fini(stream->priv); }
Upload File
Create Folder