diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-12-13 09:15:19 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-01-19 16:24:56 +0100 |
commit | 551dd3879c288a2b6b6fbaca5c09c04fbe994ff4 (patch) | |
tree | f3437139699edffd034168999854258f30c4023b /bin | |
parent | 722ecf27eaf83685dfc6e92adc9d66f0107da5ea (diff) |
Split stream compression out of libio
Move it to a separate libxfrm library, where it can be independently
tested as well. The bulk of the new code is also mainly test cases
for the compressors.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sqfs2tar/Makemodule.am | 2 | ||||
-rw-r--r-- | bin/sqfs2tar/options.c | 17 | ||||
-rw-r--r-- | bin/sqfs2tar/sqfs2tar.c | 10 | ||||
-rw-r--r-- | bin/sqfs2tar/sqfs2tar.h | 1 | ||||
-rw-r--r-- | bin/tar2sqfs/Makemodule.am | 2 | ||||
-rw-r--r-- | bin/tar2sqfs/options.c | 8 | ||||
-rw-r--r-- | bin/tar2sqfs/tar2sqfs.c | 60 | ||||
-rw-r--r-- | bin/tar2sqfs/tar2sqfs.h | 1 |
8 files changed, 58 insertions, 43 deletions
diff --git a/bin/sqfs2tar/Makemodule.am b/bin/sqfs2tar/Makemodule.am index 22d523e..05cee5b 100644 --- a/bin/sqfs2tar/Makemodule.am +++ b/bin/sqfs2tar/Makemodule.am @@ -3,7 +3,7 @@ sqfs2tar_SOURCES += bin/sqfs2tar/options.c bin/sqfs2tar/write_tree.c sqfs2tar_SOURCES += bin/sqfs2tar/xattr.c sqfs2tar_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) sqfs2tar_LDADD = libcommon.a libutil.a libsquashfs.la libtar.a -sqfs2tar_LDADD += libio.a libcompat.a libfstree.a +sqfs2tar_LDADD += libio.a libxfrm.a libcompat.a libfstree.a sqfs2tar_LDADD += $(ZLIB_LIBS) $(XZ_LIBS) $(LZO_LIBS) $(ZSTD_LIBS) $(BZIP2_LIBS) sqfs2tar_LDADD += $(PTHREAD_LIBS) diff --git a/bin/sqfs2tar/options.c b/bin/sqfs2tar/options.c index 4f783e0..ba1588d 100644 --- a/bin/sqfs2tar/options.c +++ b/bin/sqfs2tar/options.c @@ -91,19 +91,12 @@ void process_args(int argc, char **argv) switch (i) { case 'c': - compressor = io_compressor_id_from_name(optarg); + compressor = xfrm_compressor_id_from_name(optarg); if (compressor <= 0) { fprintf(stderr, "unknown compressor '%s'.\n", optarg); goto fail; } - - if (!io_compressor_exists(compressor)) { - fprintf(stderr, - "%s compressor is not supported.\n", - optarg); - goto fail; - } break; case 'd': if (num_subdirs == max_subdirs) { @@ -163,11 +156,11 @@ void process_args(int argc, char **argv) case 'h': fputs(usagestr, stdout); - i = IO_COMPRESSOR_MIN; + i = XFRM_COMPRESSOR_MIN; - while (i <= IO_COMPRESSOR_MAX) { - name = io_compressor_name_from_id(i); - if (io_compressor_exists(i)) + while (i <= XFRM_COMPRESSOR_MAX) { + name = xfrm_compressor_name_from_id(i); + if (name != NULL) printf("\t%s\n", name); ++i; } diff --git a/bin/sqfs2tar/sqfs2tar.c b/bin/sqfs2tar/sqfs2tar.c index f8d3173..43f9e78 100644 --- a/bin/sqfs2tar/sqfs2tar.c +++ b/bin/sqfs2tar/sqfs2tar.c @@ -124,9 +124,15 @@ int main(int argc, char **argv) } if (compressor > 0) { - ostream_t *strm = ostream_compressor_create(out_file, - compressor); + xfrm_stream_t *xfrm = compressor_stream_create(compressor,NULL); + ostream_t *strm; + + if (xfrm == NULL) + goto out; + + strm = ostream_xfrm_create(out_file, xfrm); sqfs_drop(out_file); + sqfs_drop(xfrm); out_file = strm; if (out_file == NULL) diff --git a/bin/sqfs2tar/sqfs2tar.h b/bin/sqfs2tar/sqfs2tar.h index 71b491d..4bf5428 100644 --- a/bin/sqfs2tar/sqfs2tar.h +++ b/bin/sqfs2tar/sqfs2tar.h @@ -12,6 +12,7 @@ #include "util/util.h" #include "tar/tar.h" +#include "xfrm/compress.h" #include "io/xfrm.h" #include <getopt.h> diff --git a/bin/tar2sqfs/Makemodule.am b/bin/tar2sqfs/Makemodule.am index a9c503f..faa2948 100644 --- a/bin/tar2sqfs/Makemodule.am +++ b/bin/tar2sqfs/Makemodule.am @@ -1,7 +1,7 @@ tar2sqfs_SOURCES = bin/tar2sqfs/tar2sqfs.c bin/tar2sqfs/tar2sqfs.h 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 libio.a +tar2sqfs_LDADD = libcommon.a libsquashfs.la libtar.a libio.a libxfrm.a tar2sqfs_LDADD += libfstree.a libcompat.a libfstree.a libutil.a $(LZO_LIBS) tar2sqfs_LDADD += $(ZLIB_LIBS) $(XZ_LIBS) $(ZSTD_LIBS) $(BZIP2_LIBS) tar2sqfs_LDADD += $(PTHREAD_LIBS) diff --git a/bin/tar2sqfs/options.c b/bin/tar2sqfs/options.c index 94e7036..f2185a6 100644 --- a/bin/tar2sqfs/options.c +++ b/bin/tar2sqfs/options.c @@ -94,15 +94,15 @@ char *root_becomes = NULL; static void input_compressor_print_available(void) { - int i = IO_COMPRESSOR_MIN; + int i = XFRM_COMPRESSOR_MIN; const char *name; fputs("\nSupported tar compression formats:\n", stdout); - while (i <= IO_COMPRESSOR_MAX) { - name = io_compressor_name_from_id(i); + while (i <= XFRM_COMPRESSOR_MAX) { + name = xfrm_compressor_name_from_id(i); - if (io_compressor_exists(i)) + if (name != NULL) printf("\t%s\n", name); ++i; diff --git a/bin/tar2sqfs/tar2sqfs.c b/bin/tar2sqfs/tar2sqfs.c index 572eb10..9257fed 100644 --- a/bin/tar2sqfs/tar2sqfs.c +++ b/bin/tar2sqfs/tar2sqfs.c @@ -32,12 +32,45 @@ static int tar_probe(const sqfs_u8 *data, size_t size) return 0; } +static istream_t *magic_autowrap(istream_t *strm) +{ + xfrm_stream_t *xfrm = NULL; + istream_t *wrapper = NULL; + const sqfs_u8 *data; + size_t avail; + int ret; + + ret = istream_precache(strm); + if (ret != 0) + goto out; + + data = strm->buffer + strm->buffer_offset; + avail = strm->buffer_used - strm->buffer_offset; + + ret = tar_probe(data, avail); + if (ret > 0) + return strm; + + ret = xfrm_compressor_id_from_magic(data, avail); + if (ret <= 0) + return strm; + + xfrm = decompressor_stream_create(ret); + if (xfrm == NULL) + goto out; + + wrapper = istream_xfrm_create(strm, xfrm); +out: + sqfs_drop(strm); + sqfs_drop(xfrm); + return wrapper; +} + 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); @@ -45,28 +78,9 @@ 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) { - istream_t *strm; - - if (!io_compressor_exists(ret)) { - fprintf(stderr, - "%s: %s compression is not supported.\n", - istream_get_filename(input_file), - io_compressor_name_from_id(ret)); - goto out_if; - } - - strm = istream_compressor_create(input_file, ret); - sqfs_drop(input_file); - input_file = strm; - - if (input_file == NULL) - return EXIT_FAILURE; - } + input_file = magic_autowrap(input_file); + if (input_file == NULL) + return EXIT_FAILURE; memset(&sqfs, 0, sizeof(sqfs)); if (sqfs_writer_init(&sqfs, &cfg)) diff --git a/bin/tar2sqfs/tar2sqfs.h b/bin/tar2sqfs/tar2sqfs.h index 6e4d123..a21774b 100644 --- a/bin/tar2sqfs/tar2sqfs.h +++ b/bin/tar2sqfs/tar2sqfs.h @@ -14,6 +14,7 @@ #include "util/util.h" #include "tar/tar.h" #include "tar/format.h" +#include "xfrm/compress.h" #include "io/xfrm.h" #include <stdlib.h> |