summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-14 15:26:28 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-16 09:34:35 +0200
commit3e5ccf8568f6291b827bf6308103f324d1901197 (patch)
tree2bd839e0d960f04442d17653dfaa8775f17f08b3
parentc9f5cfd3df2706da940a39d6d816ad084ba80fbd (diff)
Implement input decompression support for tar2sqfs
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--bin/tar2sqfs/Makemodule.am6
-rw-r--r--bin/tar2sqfs/tar2sqfs.c45
2 files changed, 50 insertions, 1 deletions
diff --git a/bin/tar2sqfs/Makemodule.am b/bin/tar2sqfs/Makemodule.am
index 0a74419..58d1ef9 100644
--- a/bin/tar2sqfs/Makemodule.am
+++ b/bin/tar2sqfs/Makemodule.am
@@ -3,7 +3,11 @@ tar2sqfs_SOURCES += bin/tar2sqfs/options.c bin/tar2sqfs/process_tarball.c
tar2sqfs_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
tar2sqfs_LDADD = libcommon.a libsquashfs.la libtar.a libfstream.a
tar2sqfs_LDADD += libfstree.a libcompat.a libfstree.a $(LZO_LIBS)
-tar2sqfs_LDADD += $(PTHREAD_LIBS)
+tar2sqfs_LDADD += $(ZLIB_LIBS) $(XZ_LIBS) $(PTHREAD_LIBS)
+
+if WITH_OWN_ZLIB
+tar2sqfs_LDADD += libz.la
+endif
dist_man1_MANS += bin/tar2sqfs/tar2sqfs.1
bin_PROGRAMS += tar2sqfs
diff --git a/bin/tar2sqfs/tar2sqfs.c b/bin/tar2sqfs/tar2sqfs.c
index 6cab231..603ee25 100644
--- a/bin/tar2sqfs/tar2sqfs.c
+++ b/bin/tar2sqfs/tar2sqfs.c
@@ -6,11 +6,38 @@
*/
#include "tar2sqfs.h"
+static int tar_probe(const sqfs_u8 *data, size_t size)
+{
+ size_t i, offset;
+
+ if (size >= TAR_RECORD_SIZE) {
+ for (i = 0; i < TAR_RECORD_SIZE; ++i) {
+ if (data[i] != 0x00)
+ break;
+ }
+
+ if (i == TAR_RECORD_SIZE) {
+ data += TAR_RECORD_SIZE;
+ size -= TAR_RECORD_SIZE;
+ }
+ }
+
+ offset = offsetof(tar_header_t, magic);
+
+ if (offset + 5 <= size) {
+ if (memcmp(data + offset, "ustar", 5) == 0)
+ return 1;
+ }
+
+ return 0;
+}
+
int main(int argc, char **argv)
{
int status = EXIT_FAILURE;
istream_t *input_file = NULL;
sqfs_writer_t sqfs;
+ int ret;
process_args(argc, argv);
@@ -18,6 +45,24 @@ int main(int argc, char **argv)
if (input_file == NULL)
return EXIT_FAILURE;
+ ret = istream_detect_compressor(input_file, tar_probe);
+ if (ret < 0)
+ goto out_if;
+
+ if (ret > 0) {
+ if (!fstream_compressor_exists(ret)) {
+ fprintf(stderr,
+ "%s: %s compression is not supported.\n",
+ istream_get_filename(input_file),
+ fstream_compressor_name_from_id(ret));
+ goto out_if;
+ }
+
+ input_file = istream_compressor_create(input_file, ret);
+ if (input_file == NULL)
+ return EXIT_FAILURE;
+ }
+
memset(&sqfs, 0, sizeof(sqfs));
if (sqfs_writer_init(&sqfs, &cfg))
goto out_if;