aboutsummaryrefslogtreecommitdiff
path: root/unpack
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-01 13:35:33 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-02 12:40:06 +0200
commit4da96898487f0f4aca1dfc7afc355aa90065308a (patch)
treeb4d08939634970e63eab4c7f8588dbdfe7a10409 /unpack
parentff0737a13f4ea5c97ff8f4973383080163a9a67f (diff)
Add unsquashfs stub
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack')
-rw-r--r--unpack/Makemodule.am12
-rw-r--r--unpack/unsquashfs.c65
2 files changed, 77 insertions, 0 deletions
diff --git a/unpack/Makemodule.am b/unpack/Makemodule.am
new file mode 100644
index 0000000..190803e
--- /dev/null
+++ b/unpack/Makemodule.am
@@ -0,0 +1,12 @@
+unsquashfs_SOURCES = unpack/unsquashfs.c
+unsquashfs_LDADD = libsquashfs.a libfstree.a libcompress.a libutil.a
+
+if WITH_LZMA
+unsquashfs_LDADD += $(XZ_LIBS)
+endif
+
+if WITH_ZLIB
+unsquashfs_LDADD += $(ZLIB_LIBS)
+endif
+
+bin_PROGRAMS += unsquashfs
diff --git a/unpack/unsquashfs.c b/unpack/unsquashfs.c
new file mode 100644
index 0000000..4606366
--- /dev/null
+++ b/unpack/unsquashfs.c
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include "squashfs.h"
+#include "compress.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+extern const char *__progname;
+
+int main(int argc, char **argv)
+{
+ int fd, status = EXIT_FAILURE;
+ sqfs_super_t super;
+ compressor_t *cmp;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <filename>\n", __progname);
+ return EXIT_FAILURE;
+ }
+
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
+ perror(argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ if (sqfs_super_read(&super, fd))
+ goto out;
+
+ if ((super.version_major != SQFS_VERSION_MAJOR) ||
+ (super.version_minor != SQFS_VERSION_MINOR)) {
+ fprintf(stderr,
+ "The image uses squashfs version %d.%d\n"
+ "We currently only supports version %d.%d (sorry).\n",
+ super.version_major, super.version_minor,
+ SQFS_VERSION_MAJOR, SQFS_VERSION_MINOR);
+ goto out;
+ }
+
+ if (super.flags & SQFS_FLAG_COMPRESSOR_OPTIONS) {
+ fputs("Image has been built with compressor options.\n"
+ "This is not yet supported.\n",
+ stderr);
+ goto out;
+ }
+
+ if (!compressor_exists(super.compression_id)) {
+ fputs("Image uses a compressor that has not been built in\n",
+ stderr);
+ goto out;
+ }
+
+ cmp = compressor_create(super.compression_id, false, super.block_size);
+ if (cmp == NULL)
+ goto out;
+
+ status = EXIT_SUCCESS;
+
+ cmp->destroy(cmp);
+out:
+ close(fd);
+ return status;
+}