aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac38
-rw-r--r--lib/Makemodule.am12
-rw-r--r--lib/comp/compressor.c8
-rw-r--r--lib/comp/gzip.c107
-rw-r--r--lib/comp/internal.h4
-rw-r--r--lib/comp/xz.c (renamed from lib/comp/lzma.c)36
-rw-r--r--lib/comp/zlib.c107
-rw-r--r--mkfs/Makemodule.am4
-rw-r--r--unpack/Makemodule.am4
9 files changed, 160 insertions, 160 deletions
diff --git a/configure.ac b/configure.ac
index 51c61a4..4cb29bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,41 +41,41 @@ AC_SUBST([WARN_CFLAGS])
##### config options #####
-AC_ARG_WITH([zlib],
- [AS_HELP_STRING([--without-zlib],
- [Build without zlib compression support])],
+AC_ARG_WITH([gzip],
+ [AS_HELP_STRING([--without-gzip],
+ [Build without gzip compression support])],
[case "${withval}" in
- yes) AM_CONDITIONAL([WITH_ZLIB], [true]) ;;
- no) AM_CONDITIONAL([WITH_ZLIB], [false]) ;;
- *) AC_MSG_ERROR([bad value ${withval} for --without-zlib]) ;;
+ yes) AM_CONDITIONAL([WITH_GZIP], [true]) ;;
+ no) AM_CONDITIONAL([WITH_GZIP], [false]) ;;
+ *) AC_MSG_ERROR([bad value ${withval} for --without-gzip]) ;;
esac],
- [AM_CONDITIONAL([WITH_ZLIB], [true])])
+ [AM_CONDITIONAL([WITH_GZIP], [true])])
-AC_ARG_WITH([lzma],
- [AS_HELP_STRING([--without-lzma],
- [Build without lzma compression support])],
+AC_ARG_WITH([xz],
+ [AS_HELP_STRING([--without-xz],
+ [Build without xz compression support])],
[case "${withval}" in
- yes) AM_CONDITIONAL([WITH_LZMA], [true]) ;;
- no) AM_CONDITIONAL([WITH_LZMA], [false]) ;;
- *) AC_MSG_ERROR([bad value ${withval} for --without-lzma]) ;;
+ yes) AM_CONDITIONAL([WITH_XZ], [true]) ;;
+ no) AM_CONDITIONAL([WITH_XZ], [false]) ;;
+ *) AC_MSG_ERROR([bad value ${withval} for --without-xz]) ;;
esac],
- [AM_CONDITIONAL([WITH_LZMA], [true])])
+ [AM_CONDITIONAL([WITH_XZ], [true])])
##### search for dependencies #####
need_zlib="no"
-need_lzma="no"
+need_xz="no"
-AM_COND_IF([WITH_ZLIB], [need_zlib="yes"])
-AM_COND_IF([WITH_LZMA], [need_lzma="yes"])
+AM_COND_IF([WITH_GZIP], [need_zlib="yes"])
+AM_COND_IF([WITH_XZ], [need_xz="yes"])
if test "x$need_zlib" = "xyes"; then
PKG_CHECK_MODULES(ZLIB, [zlib], [], [AC_MSG_ERROR([cannot find zlib])])
fi
-if test "x$need_lzma" = "xyes"; then
+if test "x$need_xz" = "xyes"; then
PKG_CHECK_MODULES(XZ, [liblzma >= 5.0.0], [],
- [AC_MSG_ERROR([cannot find lzma])])
+ [AC_MSG_ERROR([cannot find xz sdk])])
fi
##### generate output #####
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index 691d6df..d174c99 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -21,18 +21,18 @@ libutil_a_SOURCES = lib/util/canonicalize_name.c lib/util/write_retry.c
libutil_a_SOURCES += lib/util/read_retry.c include/util.h
libutil_a_SOURCES += lib/util/print_version.c lib/util/mkdir_p.c
-if WITH_ZLIB
-libcompress_a_SOURCES += lib/comp/zlib.c
+if WITH_GZIP
+libcompress_a_SOURCES += lib/comp/gzip.c
libcompress_a_CFLAGS += $(ZLIB_CFLAGS)
-libcompress_a_CPPFLAGS += -DWITH_ZLIB
+libcompress_a_CPPFLAGS += -DWITH_GZIP
endif
-if WITH_LZMA
-libcompress_a_SOURCES += lib/comp/lzma.c
+if WITH_XZ
+libcompress_a_SOURCES += lib/comp/xz.c
libcompress_a_CFLAGS += $(XZ_CFLAGS)
-libcompress_a_CPPFLAGS += -DWITH_LZMA
+libcompress_a_CPPFLAGS += -DWITH_XZ
endif
noinst_LIBRARIES += libfstree.a libcompress.a libutil.a libsquashfs.a
diff --git a/lib/comp/compressor.c b/lib/comp/compressor.c
index 3bc2b4d..1ede111 100644
--- a/lib/comp/compressor.c
+++ b/lib/comp/compressor.c
@@ -6,11 +6,11 @@
typedef compressor_t *(*compressor_fun_t)(bool compress, size_t block_size);
static compressor_fun_t compressors[SQFS_COMP_MAX + 1] = {
-#ifdef WITH_ZLIB
- [SQFS_COMP_GZIP] = create_zlib_compressor,
+#ifdef WITH_GZIP
+ [SQFS_COMP_GZIP] = create_gzip_compressor,
#endif
-#ifdef WITH_LZMA
- [SQFS_COMP_XZ] = create_lzma_compressor,
+#ifdef WITH_XZ
+ [SQFS_COMP_XZ] = create_xz_compressor,
#endif
};
diff --git a/lib/comp/gzip.c b/lib/comp/gzip.c
new file mode 100644
index 0000000..ea634b8
--- /dev/null
+++ b/lib/comp/gzip.c
@@ -0,0 +1,107 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <zlib.h>
+
+#include "internal.h"
+
+typedef struct {
+ compressor_t base;
+
+ z_stream strm;
+ bool compress;
+
+ size_t block_size;
+} gzip_compressor_t;
+
+static void gzip_destroy(compressor_t *base)
+{
+ gzip_compressor_t *gzip = (gzip_compressor_t *)base;
+
+ if (gzip->compress) {
+ deflateEnd(&gzip->strm);
+ } else {
+ inflateEnd(&gzip->strm);
+ }
+
+ free(gzip);
+}
+
+static ssize_t gzip_do_block(compressor_t *base, const uint8_t *in,
+ size_t size, uint8_t *out, size_t outsize)
+{
+ gzip_compressor_t *gzip = (gzip_compressor_t *)base;
+ size_t written;
+ int ret;
+
+ if (gzip->compress) {
+ ret = deflateReset(&gzip->strm);
+ } else {
+ ret = inflateReset(&gzip->strm);
+ }
+
+ if (ret != Z_OK) {
+ fputs("resetting zlib stream failed\n", stderr);
+ return -1;
+ }
+
+ gzip->strm.next_in = (void *)in;
+ gzip->strm.avail_in = size;
+ gzip->strm.next_out = out;
+ gzip->strm.avail_out = outsize;
+
+ if (gzip->compress) {
+ ret = deflate(&gzip->strm, Z_FINISH);
+ } else {
+ ret = inflate(&gzip->strm, Z_FINISH);
+ }
+
+ if (ret == Z_STREAM_END) {
+ written = gzip->strm.total_out;
+
+ if (gzip->compress && written >= size)
+ return 0;
+
+ return (ssize_t)written;
+ }
+
+ if (ret != Z_OK) {
+ fputs("gzip block processing failed\n", stderr);
+ return -1;
+ }
+
+ return 0;
+}
+
+compressor_t *create_gzip_compressor(bool compress, size_t block_size)
+{
+ gzip_compressor_t *gzip = calloc(1, sizeof(*gzip));
+ compressor_t *base = (compressor_t *)gzip;
+ int ret;
+
+ if (gzip == NULL) {
+ perror("creating gzip compressor");
+ return NULL;
+ }
+
+ gzip->compress = compress;
+ gzip->block_size = block_size;
+ base->do_block = gzip_do_block;
+ base->destroy = gzip_destroy;
+
+ if (compress) {
+ ret = deflateInit(&gzip->strm, Z_BEST_COMPRESSION);
+ } else {
+ ret = inflateInit(&gzip->strm);
+ }
+
+ if (ret != Z_OK) {
+ fputs("internal error creating zlib stream\n", stderr);
+ free(gzip);
+ return NULL;
+ }
+
+ return base;
+}
diff --git a/lib/comp/internal.h b/lib/comp/internal.h
index 17fffe1..d1cf1f2 100644
--- a/lib/comp/internal.h
+++ b/lib/comp/internal.h
@@ -4,8 +4,8 @@
#include "compress.h"
-compressor_t *create_lzma_compressor(bool compress, size_t block_size);
+compressor_t *create_xz_compressor(bool compress, size_t block_size);
-compressor_t *create_zlib_compressor(bool compress, size_t block_size);
+compressor_t *create_gzip_compressor(bool compress, size_t block_size);
#endif /* INTERNAL_H */
diff --git a/lib/comp/lzma.c b/lib/comp/xz.c
index 3169c33..98d740c 100644
--- a/lib/comp/lzma.c
+++ b/lib/comp/xz.c
@@ -10,23 +10,23 @@
typedef struct {
compressor_t base;
size_t block_size;
-} lzma_compressor_t;
+} xz_compressor_t;
-static ssize_t lzma_comp_block(compressor_t *base, const uint8_t *in,
+static ssize_t xz_comp_block(compressor_t *base, const uint8_t *in,
size_t size, uint8_t *out, size_t outsize)
{
- lzma_compressor_t *lzma = (lzma_compressor_t *)base;
+ xz_compressor_t *xz = (xz_compressor_t *)base;
lzma_filter filters[5];
lzma_options_lzma opt;
size_t written = 0;
lzma_ret ret;
if (lzma_lzma_preset(&opt, LZMA_PRESET_DEFAULT)) {
- fputs("error initializing LZMA options\n", stderr);
+ fputs("error initializing xz options\n", stderr);
return -1;
}
- opt.dict_size = lzma->block_size;
+ opt.dict_size = xz->block_size;
filters[0].id = LZMA_FILTER_LZMA2;
filters[0].options = &opt;
@@ -41,15 +41,15 @@ static ssize_t lzma_comp_block(compressor_t *base, const uint8_t *in,
return (written >= size) ? 0 : written;
if (ret != LZMA_BUF_ERROR) {
- fputs("lzma block compress failed\n", stderr);
+ fputs("xz block compress failed\n", stderr);
return -1;
}
return 0;
}
-static ssize_t lzma_uncomp_block(compressor_t *base, const uint8_t *in,
- size_t size, uint8_t *out, size_t outsize)
+static ssize_t xz_uncomp_block(compressor_t *base, const uint8_t *in,
+ size_t size, uint8_t *out, size_t outsize)
{
uint64_t memlimit = 32 * 1024 * 1024;
size_t dest_pos = 0;
@@ -64,27 +64,27 @@ static ssize_t lzma_uncomp_block(compressor_t *base, const uint8_t *in,
if (ret == LZMA_OK && size == src_pos)
return (ssize_t)dest_pos;
- fputs("lzma block extract failed\n", stderr);
+ fputs("xz block extract failed\n", stderr);
return -1;
}
-static void lzma_destroy(compressor_t *base)
+static void xz_destroy(compressor_t *base)
{
free(base);
}
-compressor_t *create_lzma_compressor(bool compress, size_t block_size)
+compressor_t *create_xz_compressor(bool compress, size_t block_size)
{
- lzma_compressor_t *lzma = calloc(1, sizeof(*lzma));
- compressor_t *base = (compressor_t *)lzma;
+ xz_compressor_t *xz = calloc(1, sizeof(*xz));
+ compressor_t *base = (compressor_t *)xz;
- if (lzma == NULL) {
- perror("creating lzma stream");
+ if (xz == NULL) {
+ perror("creating xz compressor");
return NULL;
}
- lzma->block_size = block_size;
- base->destroy = lzma_destroy;
- base->do_block = compress ? lzma_comp_block : lzma_uncomp_block;
+ xz->block_size = block_size;
+ base->destroy = xz_destroy;
+ base->do_block = compress ? xz_comp_block : xz_uncomp_block;
return base;
}
diff --git a/lib/comp/zlib.c b/lib/comp/zlib.c
deleted file mode 100644
index f151132..0000000
--- a/lib/comp/zlib.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <zlib.h>
-
-#include "internal.h"
-
-typedef struct {
- compressor_t base;
-
- z_stream strm;
- bool compress;
-
- size_t block_size;
-} zlib_compressor_t;
-
-static void zlib_destroy(compressor_t *base)
-{
- zlib_compressor_t *zlib = (zlib_compressor_t *)base;
-
- if (zlib->compress) {
- deflateEnd(&zlib->strm);
- } else {
- inflateEnd(&zlib->strm);
- }
-
- free(zlib);
-}
-
-static ssize_t zlib_do_block(compressor_t *base, const uint8_t *in,
- size_t size, uint8_t *out, size_t outsize)
-{
- zlib_compressor_t *zlib = (zlib_compressor_t *)base;
- size_t written;
- int ret;
-
- if (zlib->compress) {
- ret = deflateReset(&zlib->strm);
- } else {
- ret = inflateReset(&zlib->strm);
- }
-
- if (ret != Z_OK) {
- fputs("resetting zlib stream failed\n", stderr);
- return -1;
- }
-
- zlib->strm.next_in = (void *)in;
- zlib->strm.avail_in = size;
- zlib->strm.next_out = out;
- zlib->strm.avail_out = outsize;
-
- if (zlib->compress) {
- ret = deflate(&zlib->strm, Z_FINISH);
- } else {
- ret = inflate(&zlib->strm, Z_FINISH);
- }
-
- if (ret == Z_STREAM_END) {
- written = zlib->strm.total_out;
-
- if (zlib->compress && written >= size)
- return 0;
-
- return (ssize_t)written;
- }
-
- if (ret != Z_OK) {
- fputs("zlib block processing failed\n", stderr);
- return -1;
- }
-
- return 0;
-}
-
-compressor_t *create_zlib_compressor(bool compress, size_t block_size)
-{
- zlib_compressor_t *zlib = calloc(1, sizeof(*zlib));
- compressor_t *base = (compressor_t *)zlib;
- int ret;
-
- if (zlib == NULL) {
- perror("creating zlib stream");
- return NULL;
- }
-
- zlib->compress = compress;
- zlib->block_size = block_size;
- base->do_block = zlib_do_block;
- base->destroy = zlib_destroy;
-
- if (compress) {
- ret = deflateInit(&zlib->strm, Z_BEST_COMPRESSION);
- } else {
- ret = inflateInit(&zlib->strm);
- }
-
- if (ret != Z_OK) {
- fputs("internal error creating zlib stream\n", stderr);
- free(zlib);
- return NULL;
- }
-
- return base;
-}
diff --git a/mkfs/Makemodule.am b/mkfs/Makemodule.am
index fb56fcf..3914e71 100644
--- a/mkfs/Makemodule.am
+++ b/mkfs/Makemodule.am
@@ -2,11 +2,11 @@ mksquashfs_SOURCES = mkfs/mksquashfs.c mkfs/mksquashfs.h mkfs/block.c
mksquashfs_SOURCES += mkfs/options.c mkfs/meta.c
mksquashfs_LDADD = libsquashfs.a libfstree.a libcompress.a libutil.a
-if WITH_LZMA
+if WITH_XZ
mksquashfs_LDADD += $(XZ_LIBS)
endif
-if WITH_ZLIB
+if WITH_GZIP
mksquashfs_LDADD += $(ZLIB_LIBS)
endif
diff --git a/unpack/Makemodule.am b/unpack/Makemodule.am
index 7d71bf5..ccb5707 100644
--- a/unpack/Makemodule.am
+++ b/unpack/Makemodule.am
@@ -4,11 +4,11 @@ unsquashfs_SOURCES += unpack/list_files.c unpack/extract_file.c
unsquashfs_SOURCES += unpack/restore_fstree.c
unsquashfs_LDADD = libsquashfs.a libfstree.a libcompress.a libutil.a
-if WITH_LZMA
+if WITH_XZ
unsquashfs_LDADD += $(XZ_LIBS)
endif
-if WITH_ZLIB
+if WITH_GZIP
unsquashfs_LDADD += $(ZLIB_LIBS)
endif