aboutsummaryrefslogtreecommitdiff
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
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>
-rw-r--r--Makefile.am4
-rw-r--r--difftool/Makemodule.am2
-rw-r--r--difftool/sqfsdiff.c15
-rw-r--r--include/common.h7
-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
-rw-r--r--mkfs/Makemodule.am2
-rw-r--r--mkfs/options.c5
-rw-r--r--tar/Makemodule.am3
-rw-r--r--tar/sqfs2tar.c15
-rw-r--r--tar/tar2sqfs.c5
-rw-r--r--unpack/Makemodule.am1
-rw-r--r--unpack/rdsquashfs.c15
19 files changed, 114 insertions, 28 deletions
diff --git a/Makefile.am b/Makefile.am
index 6502a26..379a949 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,6 +3,10 @@ ACLOCAL_AMFLAGS = -I m4
AM_CPPFLAGS = -I$(top_srcdir)/include -D_GNU_SOURCE
AM_CFLAGS = $(WARN_CFLAGS)
+if WITH_LZO
+AM_CPPFLAGS += -DWITH_LZO
+endif
+
noinst_LTLIBRARIES =
noinst_LIBRARIES =
noinst_PROGRAMS =
diff --git a/difftool/Makemodule.am b/difftool/Makemodule.am
index e43f35d..e827a8b 100644
--- a/difftool/Makemodule.am
+++ b/difftool/Makemodule.am
@@ -2,6 +2,6 @@ sqfsdiff_SOURCES = difftool/sqfsdiff.c difftool/sqfsdiff.h difftool/util.c
sqfsdiff_SOURCES += difftool/compare_dir.c difftool/node_compare.c
sqfsdiff_SOURCES += difftool/compare_files.c difftool/super.c
sqfsdiff_SOURCES += difftool/extract.c difftool/options.c
-sqfsdiff_LDADD = libcommon.a libsquashfs.la libutil.la
+sqfsdiff_LDADD = libcommon.a libsquashfs.la libutil.la $(LZO_LIBS)
bin_PROGRAMS += sqfsdiff
diff --git a/difftool/sqfsdiff.c b/difftool/sqfsdiff.c
index 7479938..1c80812 100644
--- a/difftool/sqfsdiff.c
+++ b/difftool/sqfsdiff.c
@@ -22,7 +22,14 @@ static int open_sfqs(sqfs_state_t *state, const char *path)
goto fail_file;
}
- if (!sqfs_compressor_exists(state->super.compression_id)) {
+ ret = sqfs_compressor_exists(state->super.compression_id);
+
+#ifdef WITH_LZO
+ if (state->super.compression_id == SQFS_COMP_LZO)
+ ret = true;
+#endif
+
+ if (!ret) {
fprintf(stderr, "%s: unknown compressor used.\n",
path);
goto fail_file;
@@ -33,6 +40,12 @@ static int open_sfqs(sqfs_state_t *state, const char *path)
SQFS_COMP_FLAG_UNCOMPRESS);
state->cmp = sqfs_compressor_create(&state->cfg);
+
+#ifdef WITH_LZO
+ if (state->super.compression_id == SQFS_COMP_LZO && state->cmp == NULL)
+ state->cmp = lzo_compressor_create(&state->cfg);
+#endif
+
if (state->cmp == NULL) {
fprintf(stderr, "%s: error creating compressor.\n", path);
goto fail_file;
diff --git a/include/common.h b/include/common.h
index f7e139f..66f6f76 100644
--- a/include/common.h
+++ b/include/common.h
@@ -151,4 +151,11 @@ int mkdir_p(const char *path);
/* A common implementation of the '--version' command line flag. */
void print_version(const char *progname);
+/*
+ Create an liblzo2 based LZO compressor.
+
+ XXX: This must be in libcommon instead of libsquashfs for legal reasons.
+ */
+sqfs_compressor_t *lzo_compressor_create(const sqfs_compressor_config_t *cfg);
+
#endif /* COMMON_H */
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@
diff --git a/mkfs/Makemodule.am b/mkfs/Makemodule.am
index f4dffa7..0a2b7da 100644
--- a/mkfs/Makemodule.am
+++ b/mkfs/Makemodule.am
@@ -1,7 +1,7 @@
gensquashfs_SOURCES = mkfs/mkfs.c mkfs/mkfs.h mkfs/options.c
gensquashfs_SOURCES += mkfs/dirscan.c mkfs/selinux.c
gensquashfs_LDADD = libcommon.a libsquashfs.la libfstree.a
-gensquashfs_LDADD += libcompat.a libutil.la $(LIBSELINUX_LIBS)
+gensquashfs_LDADD += libcompat.a libutil.la $(LIBSELINUX_LIBS) $(LZO_LIBS)
gensquashfs_CPPFLAGS = $(AM_CPPFLAGS)
gensquashfs_CFLAGS = $(AM_CFLAGS) $(LIBSELINUX_CFLAGS)
diff --git a/mkfs/options.c b/mkfs/options.c
index 83f1bae..31b7731 100644
--- a/mkfs/options.c
+++ b/mkfs/options.c
@@ -168,6 +168,11 @@ void process_command_line(options_t *opt, int argc, char **argv)
if (!sqfs_compressor_exists(opt->cfg.comp_id))
have_compressor = false;
+#ifdef WITH_LZO
+ if (opt->cfg.comp_id == SQFS_COMP_LZO)
+ have_compressor = true;
+#endif
+
if (!have_compressor) {
fprintf(stderr, "Unsupported compressor '%s'\n",
optarg);
diff --git a/tar/Makemodule.am b/tar/Makemodule.am
index ec65d3a..4d28bb7 100644
--- a/tar/Makemodule.am
+++ b/tar/Makemodule.am
@@ -1,8 +1,9 @@
sqfs2tar_SOURCES = tar/sqfs2tar.c
sqfs2tar_LDADD = libcommon.a libsquashfs.la libtar.a libcompat.a libutil.la
+sqfs2tar_LDADD += $(LZO_LIBS)
tar2sqfs_SOURCES = tar/tar2sqfs.c
tar2sqfs_LDADD = libcommon.a libsquashfs.la libtar.a
-tar2sqfs_LDADD += libfstree.a libcompat.a libutil.la
+tar2sqfs_LDADD += libfstree.a libcompat.a libutil.la $(LZO_LIBS)
bin_PROGRAMS += sqfs2tar tar2sqfs
diff --git a/tar/sqfs2tar.c b/tar/sqfs2tar.c
index 77f4843..9a12a96 100644
--- a/tar/sqfs2tar.c
+++ b/tar/sqfs2tar.c
@@ -420,7 +420,14 @@ int main(int argc, char **argv)
goto out_fd;
}
- if (!sqfs_compressor_exists(super.compression_id)) {
+ ret = sqfs_compressor_exists(super.compression_id);
+
+#ifdef WITH_LZO
+ if (super.compression_id == SQFS_COMP_LZO)
+ ret = true;
+#endif
+
+ if (!ret) {
fprintf(stderr, "%s: unknown compressor used.\n", filename);
goto out_fd;
}
@@ -430,6 +437,12 @@ int main(int argc, char **argv)
SQFS_COMP_FLAG_UNCOMPRESS);
cmp = sqfs_compressor_create(&cfg);
+
+#ifdef WITH_LZO
+ if (super.compression_id == SQFS_COMP_LZO && cmp == NULL)
+ cmp = lzo_compressor_create(&cfg);
+#endif
+
if (cmp == NULL) {
fputs("Error creating compressor.\n", stderr);
goto out_fd;
diff --git a/tar/tar2sqfs.c b/tar/tar2sqfs.c
index 10bb091..08bb8b5 100644
--- a/tar/tar2sqfs.c
+++ b/tar/tar2sqfs.c
@@ -126,6 +126,11 @@ static void process_args(int argc, char **argv)
if (!sqfs_compressor_exists(cfg.comp_id))
have_compressor = false;
+#ifdef WITH_LZO
+ if (cfg.comp_id == SQFS_COMP_LZO)
+ have_compressor = true;
+#endif
+
if (!have_compressor) {
fprintf(stderr, "Unsupported compressor '%s'\n",
optarg);
diff --git a/unpack/Makemodule.am b/unpack/Makemodule.am
index b137787..16d7ce1 100644
--- a/unpack/Makemodule.am
+++ b/unpack/Makemodule.am
@@ -3,5 +3,6 @@ rdsquashfs_SOURCES += unpack/list_files.c unpack/options.c
rdsquashfs_SOURCES += unpack/restore_fstree.c unpack/describe.c
rdsquashfs_SOURCES += unpack/fill_files.c unpack/dump_xattrs.c
rdsquashfs_LDADD = libcommon.a libcompat.a libsquashfs.la libutil.la
+rdsquashfs_LDADD += $(LZO_LIBS)
bin_PROGRAMS += rdsquashfs
diff --git a/unpack/rdsquashfs.c b/unpack/rdsquashfs.c
index 4acc71e..3cce318 100644
--- a/unpack/rdsquashfs.c
+++ b/unpack/rdsquashfs.c
@@ -35,7 +35,14 @@ int main(int argc, char **argv)
goto out_file;
}
- if (!sqfs_compressor_exists(super.compression_id)) {
+ ret = sqfs_compressor_exists(super.compression_id);
+
+#ifdef WITH_LZO
+ if (super.compression_id == SQFS_COMP_LZO)
+ ret = true;
+#endif
+
+ if (!ret) {
fprintf(stderr, "%s: unknown compressor used.\n",
opt.image_name);
goto out_file;
@@ -46,6 +53,12 @@ int main(int argc, char **argv)
SQFS_COMP_FLAG_UNCOMPRESS);
cmp = sqfs_compressor_create(&cfg);
+
+#ifdef WITH_LZO
+ if (super.compression_id == SQFS_COMP_LZO && cmp == NULL)
+ cmp = lzo_compressor_create(&cfg);
+#endif
+
if (cmp == NULL) {
fputs("Error creating compressor.\n", stderr);
goto out_file;