diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-11-22 14:45:32 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-11-22 14:45:32 +0100 |
commit | 168ef9be32ad754d7bcb38ed70787237fc12630d (patch) | |
tree | 39d567fa667b2f170783329a07481769dd538d43 | |
parent | 61a0dd71c4b69c21ee4aacdc0459dba58504a24a (diff) |
Move gensquashfs specific code from libfstree to gensquashfs
The "from dir" and from "from file" code, as well as the "sort file"
code is specific to gensquashfs, so move them there and the test
cases as well.
The medium term idea is to reduce libfstree to a stub, merge it into
the generic writer and ultimately hoist that into libsquashfs.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | bin/gensquashfs/Makemodule.am | 3 | ||||
-rw-r--r-- | bin/gensquashfs/fstree_from_dir.c (renamed from lib/fstree/fstree_from_dir.c) | 2 | ||||
-rw-r--r-- | bin/gensquashfs/fstree_from_file.c (renamed from lib/fstree/fstree_from_file.c) | 2 | ||||
-rw-r--r-- | bin/gensquashfs/mkfs.h | 36 | ||||
-rw-r--r-- | bin/gensquashfs/sort_by_file.c (renamed from lib/fstree/sort_by_file.c) | 2 | ||||
-rw-r--r-- | include/fstree.h | 36 | ||||
-rw-r--r-- | lib/fstree/Makemodule.am | 6 | ||||
-rw-r--r-- | tests/gensquashfs/Makemodule.am | 48 | ||||
-rw-r--r-- | tests/gensquashfs/fstree1.txt (renamed from tests/libfstree/fstree1.txt) | 0 | ||||
-rw-r--r-- | tests/gensquashfs/fstree_from_dir.c (renamed from tests/libfstree/fstree_from_dir.c) | 2 | ||||
-rw-r--r-- | tests/gensquashfs/fstree_from_file.c (renamed from tests/libfstree/fstree_from_file.c) | 2 | ||||
-rw-r--r-- | tests/gensquashfs/fstree_fuzz.c (renamed from tests/libfstree/fstree_fuzz.c) | 2 | ||||
-rw-r--r-- | tests/gensquashfs/fstree_glob1.c (renamed from tests/libfstree/fstree_glob1.c) | 2 | ||||
-rw-r--r-- | tests/gensquashfs/fstree_glob1.txt (renamed from tests/libfstree/fstree_glob1.txt) | 0 | ||||
-rw-r--r-- | tests/gensquashfs/fstree_glob2.txt (renamed from tests/libfstree/fstree_glob2.txt) | 0 | ||||
-rw-r--r-- | tests/gensquashfs/fstree_glob3.txt (renamed from tests/libfstree/fstree_glob3.txt) | 0 | ||||
-rw-r--r-- | tests/gensquashfs/sort_file.c (renamed from tests/libfstree/sort_file.c) | 2 | ||||
-rw-r--r-- | tests/libfstree/Makemodule.am | 31 |
18 files changed, 96 insertions, 80 deletions
diff --git a/bin/gensquashfs/Makemodule.am b/bin/gensquashfs/Makemodule.am index e7fad8e..c6a98a2 100644 --- a/bin/gensquashfs/Makemodule.am +++ b/bin/gensquashfs/Makemodule.am @@ -2,6 +2,9 @@ gensquashfs_SOURCES = bin/gensquashfs/mkfs.c bin/gensquashfs/mkfs.h gensquashfs_SOURCES += bin/gensquashfs/options.c bin/gensquashfs/selinux.c gensquashfs_SOURCES += bin/gensquashfs/dirscan_xattr.c gensquashfs_SOURCES += bin/gensquashfs/filemap_xattr.c +gensquashfs_SOURCES += bin/gensquashfs/fstree_from_file.c +gensquashfs_SOURCES += bin/gensquashfs/fstree_from_dir.c +gensquashfs_SOURCES += bin/gensquashfs/sort_by_file.c gensquashfs_LDADD = libcommon.a libsquashfs.la libfstree.a libio.a gensquashfs_LDADD += libutil.a libcompat.a $(LZO_LIBS) $(PTHREAD_LIBS) gensquashfs_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/lib/fstree/fstree_from_dir.c b/bin/gensquashfs/fstree_from_dir.c index 01f331d..5b3f003 100644 --- a/lib/fstree/fstree_from_dir.c +++ b/bin/gensquashfs/fstree_from_dir.c @@ -5,7 +5,7 @@ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> */ #include "config.h" -#include "fstree.h" +#include "mkfs.h" #include <dirent.h> #include <stdlib.h> diff --git a/lib/fstree/fstree_from_file.c b/bin/gensquashfs/fstree_from_file.c index 411c64f..feacbbc 100644 --- a/lib/fstree/fstree_from_file.c +++ b/bin/gensquashfs/fstree_from_file.c @@ -8,8 +8,8 @@ #include "util/util.h" #include "io/file.h" -#include "fstree.h" #include "compat.h" +#include "mkfs.h" #include <stdlib.h> #include <string.h> diff --git a/bin/gensquashfs/mkfs.h b/bin/gensquashfs/mkfs.h index 33ba707..53fb018 100644 --- a/bin/gensquashfs/mkfs.h +++ b/bin/gensquashfs/mkfs.h @@ -98,4 +98,40 @@ int selinux_relable_node(void *sehnd, sqfs_xattr_writer_t *xwr, void selinux_close_context_file(void *sehnd); +/* + Parses the file format accepted by gensquashfs and produce a file system + tree from it. File input paths are interpreted as relative to the current + working directory. + + On failure, an error report with filename and line number is written + to stderr. + + Returns 0 on success. + */ +int fstree_from_file(fstree_t *fs, const char *filename, + const char *basepath); + +int fstree_from_file_stream(fstree_t *fs, istream_t *file, + const char *basepath); + +/* + Recursively scan a directory to build a file system tree. + + Returns 0 on success, prints to stderr on failure. + */ +int fstree_from_dir(fstree_t *fs, tree_node_t *root, + const char *path, scan_node_callback cb, void *user, + unsigned int flags); + +/* + Same as fstree_from_dir, but scans a sub-directory inside the specified path. + + Returns 0 on success, prints to stderr on failure. + */ +int fstree_from_subdir(fstree_t *fs, tree_node_t *root, + const char *path, const char *subdir, + scan_node_callback cb, void *user, unsigned int flags); + +int fstree_sort_files(fstree_t *fs, istream_t *sortfile); + #endif /* MKFS_H */ diff --git a/lib/fstree/sort_by_file.c b/bin/gensquashfs/sort_by_file.c index ed4a58c..a555718 100644 --- a/lib/fstree/sort_by_file.c +++ b/bin/gensquashfs/sort_by_file.c @@ -8,7 +8,7 @@ #include "util/util.h" #include "fstree.h" -#include "compat.h" +#include "mkfs.h" #include "sqfs/block.h" diff --git a/include/fstree.h b/include/fstree.h index 1c5e5ef..51e2fbc 100644 --- a/include/fstree.h +++ b/include/fstree.h @@ -183,22 +183,6 @@ tree_node_t *fstree_add_generic(fstree_t *fs, const char *path, const struct stat *sb, const char *extra); /* - Parses the file format accepted by gensquashfs and produce a file system - tree from it. File input paths are interpreted as relative to the current - working directory. - - On failure, an error report with filename and line number is written - to stderr. - - Returns 0 on success. - */ -int fstree_from_file(fstree_t *fs, const char *filename, - const char *basepath); - -int fstree_from_file_stream(fstree_t *fs, istream_t *file, - const char *basepath); - -/* This function performs all the necessary post processing steps on the file system tree, i.e. recursively sorting all directory entries by name, allocating inode numbers, resolving hard links and stringing all files nodes @@ -249,26 +233,6 @@ tree_node_t *fstree_add_hard_link(fstree_t *fs, const char *path, */ int fstree_resolve_hard_link(fstree_t *fs, tree_node_t *node); -/* - Recursively scan a directory to build a file system tree. - - Returns 0 on success, prints to stderr on failure. - */ -int fstree_from_dir(fstree_t *fs, tree_node_t *root, - const char *path, scan_node_callback cb, void *user, - unsigned int flags); - -/* - Same as fstree_from_dir, but scans a sub-directory inside the specified path. - - Returns 0 on success, prints to stderr on failure. - */ -int fstree_from_subdir(fstree_t *fs, tree_node_t *root, - const char *path, const char *subdir, - scan_node_callback cb, void *user, unsigned int flags); - -int fstree_sort_files(fstree_t *fs, istream_t *sortfile); - void fstree_insert_sorted(tree_node_t *root, tree_node_t *n); #endif /* FSTREE_H */ diff --git a/lib/fstree/Makemodule.am b/lib/fstree/Makemodule.am index 4388bde..09cd9ac 100644 --- a/lib/fstree/Makemodule.am +++ b/lib/fstree/Makemodule.am @@ -1,9 +1,7 @@ -libfstree_a_SOURCES = lib/fstree/fstree.c lib/fstree/fstree_from_file.c -libfstree_a_SOURCES += lib/fstree/hardlink.c +libfstree_a_SOURCES = include/fstree.h lib/fstree/fstree.c libfstree_a_SOURCES += lib/fstree/post_process.c lib/fstree/get_path.c -libfstree_a_SOURCES += lib/fstree/mknode.c lib/fstree/fstree_from_dir.c +libfstree_a_SOURCES += lib/fstree/mknode.c lib/fstree/hardlink.c libfstree_a_SOURCES += lib/fstree/add_by_path.c lib/fstree/get_by_path.c -libfstree_a_SOURCES += include/fstree.h lib/fstree/sort_by_file.c libfstree_a_CFLAGS = $(AM_CFLAGS) libfstree_a_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/tests/gensquashfs/Makemodule.am b/tests/gensquashfs/Makemodule.am index a20e6ef..c1ab164 100644 --- a/tests/gensquashfs/Makemodule.am +++ b/tests/gensquashfs/Makemodule.am @@ -8,13 +8,55 @@ test_filemap_xattr_CPPFLAGS += -DTESTPATH=$(GENDATADIR)/xattr1.txt test_filemap_xattr_LDADD = libsquashfs.la libfstree.a libutil.a test_filemap_xattr_LDADD += libio.a libcompat.a +test_fstree_from_file_SOURCES = tests/gensquashfs/fstree_from_file.c \ + bin/gensquashfs/fstree_from_file.c \ + bin/gensquashfs/fstree_from_dir.c \ + bin/gensquashfs/mkfs.h +test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs +test_fstree_from_file_CPPFLAGS += -DTESTPATH=$(GENDATADIR)/fstree1.txt +test_fstree_from_file_LDADD = libfstree.a libio.a libutil.a libcompat.a + +test_fstree_glob1_SOURCES = tests/gensquashfs/fstree_glob1.c \ + bin/gensquashfs/fstree_from_file.c \ + bin/gensquashfs/fstree_from_dir.c \ + bin/gensquashfs/mkfs.h +test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs +test_fstree_glob1_CPPFLAGS += -DTESTPATH=$(GENDATADIR) +test_fstree_glob1_LDADD = libfstree.a libio.a libutil.a libcompat.a + +test_fstree_from_dir_SOURCES = tests/gensquashfs/fstree_from_dir.c \ + bin/gensquashfs/fstree_from_dir.c \ + bin/gensquashfs/mkfs.h +test_fstree_from_dir_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs +test_fstree_from_dir_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/libtar/data +test_fstree_from_dir_LDADD = libfstree.a libutil.a libcompat.a + +test_sort_file_SOURCES = tests/gensquashfs/sort_file.c \ + bin/gensquashfs/fstree_from_file.c \ + bin/gensquashfs/fstree_from_dir.c \ + bin/gensquashfs/sort_by_file.c \ + bin/gensquashfs/mkfs.h +test_sort_file_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs +test_sort_file_LDADD = libfstree.a libio.a libutil.a libcompat.a + +fstree_fuzz_SOURCES = tests/gensquashfs/fstree_fuzz.c \ + bin/gensquashfs/fstree_from_file.c \ + bin/gensquashfs/fstree_from_dir.c \ + bin/gensquashfs/mkfs.h +fstree_fuzz_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs +fstree_fuzz_LDADD = libfstree.a libio.a libutil.a libcompat.a + GENSQUASHFS_TESTS = \ - test_filemap_xattr + test_filemap_xattr test_fstree_from_file test_fstree_from_dir \ + test_fstree_glob1 test_sort_file if BUILD_TOOLS +noinst_PROGRAMS += fstree_fuzz + check_PROGRAMS += $(GENSQUASHFS_TESTS) TESTS += $(GENSQUASHFS_TESTS) endif -EXTRA_DIST += $(GENDATADIR)/xattr1.txt - +EXTRA_DIST += $(GENDATADIR)/xattr1.txt $(GENDATADIR)/fstree1.txt +EXTRA_DIST += $(GENDATADIR)/fstree_glob1.txt $(GENDATADIR)/fstree_glob2.txt +EXTRA_DIST += $(GENDATADIR)/fstree_glob3.txt diff --git a/tests/libfstree/fstree1.txt b/tests/gensquashfs/fstree1.txt index 95ee469..95ee469 100644 --- a/tests/libfstree/fstree1.txt +++ b/tests/gensquashfs/fstree1.txt diff --git a/tests/libfstree/fstree_from_dir.c b/tests/gensquashfs/fstree_from_dir.c index 438e357..2799bf3 100644 --- a/tests/libfstree/fstree_from_dir.c +++ b/tests/gensquashfs/fstree_from_dir.c @@ -6,8 +6,8 @@ */ #include "config.h" -#include "fstree.h" #include "util/test.h" +#include "mkfs.h" static void check_hierarchy(tree_node_t *root, bool recursive) { diff --git a/tests/libfstree/fstree_from_file.c b/tests/gensquashfs/fstree_from_file.c index 184c011..2a9ba1e 100644 --- a/tests/libfstree/fstree_from_file.c +++ b/tests/gensquashfs/fstree_from_file.c @@ -6,8 +6,8 @@ */ #include "config.h" -#include "fstree.h" #include "util/test.h" +#include "mkfs.h" int main(int argc, char **argv) { diff --git a/tests/libfstree/fstree_fuzz.c b/tests/gensquashfs/fstree_fuzz.c index ebc8c45..4fbb72b 100644 --- a/tests/libfstree/fstree_fuzz.c +++ b/tests/gensquashfs/fstree_fuzz.c @@ -6,7 +6,7 @@ */ #include "config.h" -#include "fstree.h" +#include "mkfs.h" #include <stdlib.h> #include <stdio.h> diff --git a/tests/libfstree/fstree_glob1.c b/tests/gensquashfs/fstree_glob1.c index 3aff21a..fbcbf91 100644 --- a/tests/libfstree/fstree_glob1.c +++ b/tests/gensquashfs/fstree_glob1.c @@ -6,8 +6,8 @@ */ #include "config.h" -#include "fstree.h" #include "util/test.h" +#include "mkfs.h" static void check_hierarchy(tree_node_t *root, bool subdir, bool recursive) { diff --git a/tests/libfstree/fstree_glob1.txt b/tests/gensquashfs/fstree_glob1.txt index b1df979..b1df979 100644 --- a/tests/libfstree/fstree_glob1.txt +++ b/tests/gensquashfs/fstree_glob1.txt diff --git a/tests/libfstree/fstree_glob2.txt b/tests/gensquashfs/fstree_glob2.txt index 3c8019b..3c8019b 100644 --- a/tests/libfstree/fstree_glob2.txt +++ b/tests/gensquashfs/fstree_glob2.txt diff --git a/tests/libfstree/fstree_glob3.txt b/tests/gensquashfs/fstree_glob3.txt index 35090e4..35090e4 100644 --- a/tests/libfstree/fstree_glob3.txt +++ b/tests/gensquashfs/fstree_glob3.txt diff --git a/tests/libfstree/sort_file.c b/tests/gensquashfs/sort_file.c index 78d1606..951328e 100644 --- a/tests/libfstree/sort_file.c +++ b/tests/gensquashfs/sort_file.c @@ -7,9 +7,9 @@ #include "config.h" #include "sqfs/block.h" -#include "fstree.h" #include "util/test.h" #include "util/util.h" +#include "mkfs.h" static const char *listing = "dir /bin 0755 0 0\n" diff --git a/tests/libfstree/Makemodule.am b/tests/libfstree/Makemodule.am index 7826cf8..5ae44a6 100644 --- a/tests/libfstree/Makemodule.am +++ b/tests/libfstree/Makemodule.am @@ -25,43 +25,16 @@ test_fstree_sort_SOURCES = tests/libfstree/fstree_sort.c test_fstree_sort_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree test_fstree_sort_LDADD = libfstree.a libio.a libutil.a libcompat.a -test_fstree_from_file_SOURCES = tests/libfstree/fstree_from_file.c -test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) -test_fstree_from_file_CPPFLAGS += -DTESTPATH=$(FSTDATADIR)/fstree1.txt -test_fstree_from_file_LDADD = libfstree.a libio.a libutil.a libcompat.a - -test_fstree_glob1_SOURCES = tests/libfstree/fstree_glob1.c -test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(FSTDATADIR) -test_fstree_glob1_LDADD = libfstree.a libio.a libutil.a libcompat.a - -test_fstree_from_dir_SOURCES = tests/libfstree/fstree_from_dir.c -test_fstree_from_dir_CPPFLAGS = $(AM_CPPFLAGS) -test_fstree_from_dir_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/libtar/data -test_fstree_from_dir_LDADD = libfstree.a libutil.a libcompat.a - test_fstree_init_SOURCES = tests/libfstree/fstree_init.c test_fstree_init_LDADD = libfstree.a libio.a libutil.a libcompat.a -test_sort_file_SOURCES = tests/libfstree/sort_file.c -test_sort_file_LDADD = libfstree.a libio.a libutil.a libcompat.a - -fstree_fuzz_SOURCES = tests/libfstree/fstree_fuzz.c -fstree_fuzz_LDADD = libfstree.a libio.a libutil.a libcompat.a - FSTREE_TESTS = \ test_mknode_simple test_mknode_slink \ test_mknode_reg test_mknode_dir test_gen_inode_numbers \ - test_add_by_path test_get_path test_fstree_sort test_fstree_from_file \ - test_fstree_init test_fstree_from_dir test_fstree_glob1 \ - test_sort_file + test_add_by_path test_get_path test_fstree_sort \ + test_fstree_init if BUILD_TOOLS check_PROGRAMS += $(FSTREE_TESTS) -noinst_PROGRAMS += fstree_fuzz - TESTS += $(FSTREE_TESTS) endif - -EXTRA_DIST += $(FSTDATADIR)/fstree1.txt -EXTRA_DIST += $(FSTDATADIR)/fstree_glob1.txt $(FSTDATADIR)/fstree_glob2.txt -EXTRA_DIST += $(FSTDATADIR)/fstree_glob3.txt |