From 88f75857702bcc6a2a423570912140c125ec518a Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 5 Aug 2019 17:38:08 +0200 Subject: cleanup: unify all the code that reads squashfs images This commit creates a new data structure called 'sqfs_reader_t' that takes care of all the repetetive tasks like opening the file, reading the super block, creating the compressor, deserializing an fstree and creating a data reader. This in turn makes it possible to remove all the duplicate code from rdsquashfs and sqfs2tar. Signed-off-by: David Oberhollenzer --- include/highlevel.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/highlevel.h') diff --git a/include/highlevel.h b/include/highlevel.h index e3afbd7..f8c5bfb 100644 --- a/include/highlevel.h +++ b/include/highlevel.h @@ -9,6 +9,7 @@ #include "config.h" +#include "data_reader.h" #include "squashfs.h" #include "compress.h" #include "id_table.h" @@ -17,6 +18,14 @@ #include #include +typedef struct { + compressor_t *cmp; + data_reader_t *data; + sqfs_super_t super; + fstree_t fs; + int sqfsfd; +} sqfs_reader_t; + enum RDTREE_FLAGS { RDTREE_NO_DEVICES = 0x01, RDTREE_NO_SOCKETS = 0x02, @@ -96,4 +105,14 @@ int write_export_table(int outfd, fstree_t *fs, sqfs_super_t *super, /* Print out fancy statistics for squashfs packing tools */ void sqfs_print_statistics(fstree_t *fs, sqfs_super_t *super); +/* Open a squashfs file, extract all the information we may need and + construct datastructures we need to access its contents. + Returns 0 on success. Prints error messages to stderr on failure. +*/ +int sqfs_reader_open(sqfs_reader_t *rd, const char *filename, + int rdtree_flags); + +/* Cleanup after a successfull sqfs_reader_open */ +void sqfs_reader_close(sqfs_reader_t *rd); + #endif /* HIGHLEVEL_H */ -- cgit v1.2.3