aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-24 00:45:03 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-24 01:03:10 +0100
commit0f89517d418ff907fd9cf51f5313974812ceb305 (patch)
treeb8083226dd401a64fd4369777c474af2a15848f8 /lib
parent5971411b6db1a1e0dab92df37f3974643a3d4399 (diff)
Fix: Move LZO compressor from libsquashfs to libcommon
The liblzo2 library is licensed under GPLv2, so it is not possible to distribute binaries of libsquashfs that link against liblzo2 under LGPL. This commit moves the LZO compressor implementation to libcommon, where this isn't a problem, since the tools themselves are licensed under GPLv3. It removes the ability of libsquashfs to read or generate LZO compressed SquashFS images, but the tools still can. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Makemodule.am5
-rw-r--r--lib/common/comp_lzo.c (renamed from lib/sqfs/comp/lzo.c)26
-rw-r--r--lib/common/compress.c10
-rw-r--r--lib/common/writer.c10
-rw-r--r--lib/sqfs/Makemodule.am9
-rw-r--r--lib/sqfs/comp/compressor.c3
-rw-r--r--lib/sqfs/comp/internal.h3
-rw-r--r--lib/sqfs/libsquashfs.pc.in2
8 files changed, 46 insertions, 22 deletions
diff --git a/lib/common/Makemodule.am b/lib/common/Makemodule.am
index 2e5a812..7e1ec63 100644
--- a/lib/common/Makemodule.am
+++ b/lib/common/Makemodule.am
@@ -6,5 +6,10 @@ libcommon_a_SOURCES += lib/common/data_writer.c include/common.h
libcommon_a_SOURCES += lib/common/get_path.c lib/common/io_stdin.c
libcommon_a_SOURCES += lib/common/writer.c lib/common/perror.c
libcommon_a_SOURCES += lib/common/mkdir_p.c lib/common/filename_sane.c
+libcommon_a_CFLAGS = $(AM_CFLAGS) $(LZO_CFLAGS)
+
+if WITH_LZO
+libcommon_a_SOURCES += lib/common/comp_lzo.c
+endif
noinst_LIBRARIES += libcommon.a
diff --git a/lib/sqfs/comp/lzo.c b/lib/common/comp_lzo.c
index 46f9301..473b76f 100644
--- a/lib/sqfs/comp/lzo.c
+++ b/lib/common/comp_lzo.c
@@ -1,11 +1,11 @@
-/* SPDX-License-Identifier: LGPL-3.0-or-later */
+/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
- * lzo.c
+ * comp_lzo.c
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#define SQFS_BUILDING_DLL
#include "config.h"
+#include "common.h"
#include <stdbool.h>
#include <stdlib.h>
@@ -13,8 +13,6 @@
#include <lzo/lzo1x.h>
-#include "internal.h"
-
#define LZO_NUM_ALGS (sizeof(lzo_algs) / sizeof(lzo_algs[0]))
typedef int (*lzo_cb_t)(const lzo_bytep src, lzo_uint src_len, lzo_bytep dst,
@@ -62,7 +60,9 @@ typedef struct {
static int lzo_write_options(sqfs_compressor_t *base, sqfs_file_t *file)
{
lzo_compressor_t *lzo = (lzo_compressor_t *)base;
+ sqfs_u8 buffer[sizeof(lzo_options_t) + 2];
lzo_options_t opt;
+ int ret;
if (lzo->algorithm == SQFS_LZO_DEFAULT_ALG &&
lzo->level == SQFS_LZO_DEFAULT_LEVEL) {
@@ -77,19 +77,31 @@ static int lzo_write_options(sqfs_compressor_t *base, sqfs_file_t *file)
opt.level = 0;
}
- return sqfs_generic_write_options(file, &opt, sizeof(opt));
+ *((sqfs_u16 *)buffer) = htole16(0x8000 | sizeof(opt));
+ memcpy(buffer + 2, &opt, sizeof(opt));
+
+ ret = file->write_at(file, sizeof(sqfs_super_t),
+ buffer, sizeof(buffer));
+
+ return ret ? ret : (int)sizeof(buffer);
}
static int lzo_read_options(sqfs_compressor_t *base, sqfs_file_t *file)
{
lzo_compressor_t *lzo = (lzo_compressor_t *)base;
+ sqfs_u8 buffer[sizeof(lzo_options_t) + 2];
lzo_options_t opt;
int ret;
- ret = sqfs_generic_read_options(file, &opt, sizeof(opt));
+ ret = file->read_at(file, sizeof(sqfs_super_t),
+ buffer, sizeof(buffer));
if (ret)
return ret;
+ if (le16toh(*((sqfs_u16 *)buffer)) != (0x8000 | sizeof(opt)))
+ return SQFS_ERROR_CORRUPTED;
+
+ memcpy(&opt, buffer + 2, sizeof(opt));
lzo->algorithm = le32toh(opt.algorithm);
lzo->level = le32toh(opt.level);
diff --git a/lib/common/compress.c b/lib/common/compress.c
index 04e1f40..a2f53c2 100644
--- a/lib/common/compress.c
+++ b/lib/common/compress.c
@@ -19,12 +19,20 @@ E_SQFS_COMPRESSOR compressor_get_default(void)
void compressor_print_available(void)
{
+ bool have_compressor;
int i;
fputs("Available compressors:\n", stdout);
for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) {
- if (sqfs_compressor_exists(i))
+ have_compressor = sqfs_compressor_exists(i);
+
+#ifdef WITH_LZO
+ if (i == SQFS_COMP_LZO)
+ have_compressor = true;
+#endif
+
+ if (have_compressor)
printf("\t%s\n", sqfs_compressor_name_from_id(i));
}
diff --git a/lib/common/writer.c b/lib/common/writer.c
index 1221358..d67f76b 100644
--- a/lib/common/writer.c
+++ b/lib/common/writer.c
@@ -86,6 +86,16 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg)
goto fail_file;
sqfs->cmp = sqfs_compressor_create(&cfg);
+
+#ifdef WITH_LZO
+ if (cfg.id == SQFS_COMP_LZO) {
+ if (sqfs->cmp != NULL)
+ sqfs->cmp->destroy(sqfs->cmp);
+
+ sqfs->cmp = lzo_compressor_create(&cfg);
+ }
+#endif
+
if (sqfs->cmp == NULL) {
fputs("Error creating compressor\n", stderr);
goto fail_fs;
diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am
index f81ced7..da2e3b2 100644
--- a/lib/sqfs/Makemodule.am
+++ b/lib/sqfs/Makemodule.am
@@ -26,9 +26,9 @@ libsquashfs_la_SOURCES += lib/sqfs/data_writer/fileapi.c
libsquashfs_la_CPPFLAGS = $(AM_CPPFLAGS)
libsquashfs_la_LDFLAGS = $(AM_LDFLAGS)
libsquashfs_la_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) $(ZLIB_CFLAGS)
-libsquashfs_la_CFLAGS += $(XZ_CFLAGS) $(LZO_CFLAGS) $(LZ4_CFLAGS)
+libsquashfs_la_CFLAGS += $(XZ_CFLAGS) $(LZ4_CFLAGS)
libsquashfs_la_CFLAGS += $(ZSTD_CFLAGS) $(PTHREAD_CFLAGS)
-libsquashfs_la_LIBADD = $(XZ_LIBS) $(ZLIB_LIBS) $(LZO_LIBS) $(LZ4_LIBS)
+libsquashfs_la_LIBADD = $(XZ_LIBS) $(ZLIB_LIBS) $(LZ4_LIBS)
libsquashfs_la_LIBADD += $(ZSTD_LIBS) $(PTHREAD_LIBS) libutil.la
if WINDOWS
@@ -57,11 +57,6 @@ libsquashfs_la_SOURCES += lib/sqfs/comp/lzma.c
libsquashfs_la_CPPFLAGS += -DWITH_XZ
endif
-if WITH_LZO
-libsquashfs_la_SOURCES += lib/sqfs/comp/lzo.c
-libsquashfs_la_CPPFLAGS += -DWITH_LZO
-endif
-
if WITH_LZ4
libsquashfs_la_SOURCES += lib/sqfs/comp/lz4.c
libsquashfs_la_CPPFLAGS += -DWITH_LZ4
diff --git a/lib/sqfs/comp/compressor.c b/lib/sqfs/comp/compressor.c
index 2e2e3a3..c835f3f 100644
--- a/lib/sqfs/comp/compressor.c
+++ b/lib/sqfs/comp/compressor.c
@@ -23,9 +23,6 @@ static compressor_fun_t compressors[SQFS_COMP_MAX + 1] = {
[SQFS_COMP_XZ] = xz_compressor_create,
[SQFS_COMP_LZMA] = lzma_compressor_create,
#endif
-#ifdef WITH_LZO
- [SQFS_COMP_LZO] = lzo_compressor_create,
-#endif
#ifdef WITH_LZ4
[SQFS_COMP_LZ4] = lz4_compressor_create,
#endif
diff --git a/lib/sqfs/comp/internal.h b/lib/sqfs/comp/internal.h
index 875a194..dabf1a6 100644
--- a/lib/sqfs/comp/internal.h
+++ b/lib/sqfs/comp/internal.h
@@ -30,9 +30,6 @@ SQFS_INTERNAL
sqfs_compressor_t *gzip_compressor_create(const sqfs_compressor_config_t *cfg);
SQFS_INTERNAL
-sqfs_compressor_t *lzo_compressor_create(const sqfs_compressor_config_t *cfg);
-
-SQFS_INTERNAL
sqfs_compressor_t *lz4_compressor_create(const sqfs_compressor_config_t *cfg);
SQFS_INTERNAL
diff --git a/lib/sqfs/libsquashfs.pc.in b/lib/sqfs/libsquashfs.pc.in
index 6105248..0244bad 100644
--- a/lib/sqfs/libsquashfs.pc.in
+++ b/lib/sqfs/libsquashfs.pc.in
@@ -11,4 +11,4 @@ Cflags: -I${includedir}
Libs: -L${libdir} -lsquashfs
Requires.private: @LIBSQFS_DEP_MOD@
-Libs.private: @LZO_LIBS@ @PTHREAD_LIBS@
+Libs.private: @PTHREAD_LIBS@