Skip to content

Commit

Permalink
Merge pull request #23 from terrelln/master
Browse files Browse the repository at this point in the history
Add zstd compression support
  • Loading branch information
chipturner authored Sep 17, 2017
2 parents 1f98030 + 5986f1d commit e275db0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CONFIGURATION
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ These are the most useful options to ./configure:
--with-xz=PREFIX
--with-lzo=PREFIX
--with-lz4=PREFIX
--with-zstd=PREFIX

More options are available in `./configure --help'
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
COMPRESSION_LIBS = $(ZLIB_LIBS) $(XZ_LIBS) $(LZO_LIBS) $(LZ4_LIBS)
COMPRESSION_LIBS = $(ZLIB_LIBS) $(XZ_LIBS) $(LZO_LIBS) $(LZ4_LIBS) $(ZSTD_LIBS)

ACLOCAL_AMFLAGS = -I m4 --install

Expand All @@ -23,7 +23,7 @@ libsquashfuse_la_SOURCES = swap.c cache.c table.c dir.c file.c fs.c \
dir.h file.h decompress.h xattr.h squashfuse.h hash.h stack.h traverse.h \
util.h fs.h
libsquashfuse_la_CPPFLAGS = $(ZLIB_CPPFLAGS) $(XZ_CPPFLAGS) $(LZO_CPPFLAGS) \
$(LZ4_CPPFLAGS)
$(LZ4_CPPFLAGS) $(ZSTD_CPPFLAGS)
libsquashfuse_la_LIBADD =

# Helper for FUSE clients: libfuseprivate
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SQ_CHECK_DECOMPRESS([ZLIB],[z],[uncompress],[zlib.h])
SQ_CHECK_DECOMPRESS([XZ],[lzma],[lzma_stream_buffer_decode],[lzma.h],[liblzma])
SQ_CHECK_DECOMPRESS([LZO],[lzo2],[lzo1x_decompress_safe],[lzo/lzo1x.h])
SQ_CHECK_DECOMPRESS([LZ4],[lz4],[LZ4_decompress_safe],[lz4.h])
SQ_CHECK_DECOMPRESS([ZSTD],[zstd],[ZSTD_decompress],[zstd.h])
AS_IF([test "x$sq_decompressors" = x],
[AC_MSG_FAILURE([At least one decompression library must exist])])

Expand Down
21 changes: 20 additions & 1 deletion decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ static sqfs_err sqfs_decompressor_lz4(void *in, size_t insz,
#endif


#ifdef HAVE_ZSTD_H
#include <zstd.h>
static sqfs_err sqfs_decompressor_zstd(void *in, size_t insz,
void *out, size_t *outsz) {
const size_t zstdout = ZSTD_decompress(out, *outsz, in, insz);
if (ZSTD_isError(zstdout))
return SQFS_ERR;
*outsz = zstdout;
return SQFS_OK;
}
#define CAN_DECOMPRESS_ZSTD 1
#endif

sqfs_decompressor sqfs_decompressor_get(sqfs_compression_type type) {
switch (type) {
#ifdef CAN_DECOMPRESS_ZLIB
Expand All @@ -111,13 +124,16 @@ sqfs_decompressor sqfs_decompressor_get(sqfs_compression_type type) {
#endif
#ifdef CAN_DECOMPRESS_LZ4
case LZ4_COMPRESSION: return &sqfs_decompressor_lz4;
#endif
#ifdef CAN_DECOMPRESS_ZSTD
case ZSTD_COMPRESSION: return &sqfs_decompressor_zstd;
#endif
default: return NULL;
}
}

static char *const sqfs_compression_names[SQFS_COMP_MAX] = {
NULL, "zlib", "lzma", "lzo", "xz", "lz4",
NULL, "zlib", "lzma", "lzo", "xz", "lz4", "zstd",
};

char *sqfs_compression_name(sqfs_compression_type type) {
Expand All @@ -141,4 +157,7 @@ void sqfs_compression_supported(sqfs_compression_type *types) {
#ifdef CAN_DECOMPRESS_LZ4
types[i++] = LZ4_COMPRESSION;
#endif
#ifdef CAN_DECOMPRESS_ZSTD
types[i++] = ZSTD_COMPRESSION;
#endif
}
1 change: 1 addition & 0 deletions squashfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
#define LZO_COMPRESSION 3
#define XZ_COMPRESSION 4
#define LZ4_COMPRESSION 5
#define ZSTD_COMPRESSION 6

struct squashfs_super_block {
__le32 s_magic;
Expand Down

0 comments on commit e275db0

Please sign in to comment.