From 5aa1bab7fabc55a6f2a2ff2f7d8e2c49421cb215 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 15 Dec 2019 19:22:06 +0100 Subject: Do the fstree serialization in a recursive tree walk Remove usage of the "inode table". Signed-off-by: David Oberhollenzer --- lib/common/serialize_fstree.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'lib/common') diff --git a/lib/common/serialize_fstree.c b/lib/common/serialize_fstree.c index 939b1c1..0f34d7d 100644 --- a/lib/common/serialize_fstree.c +++ b/lib/common/serialize_fstree.c @@ -145,19 +145,55 @@ out: return ret; } +static int serialize_recursive(const char *filename, sqfs_writer_t *wr, + tree_node_t *root) +{ + bool has_subdirs = false; + tree_node_t *it; + int ret; + + for (it = root->data.dir.children; it != NULL; it = it->next) { + if (S_ISDIR(it->mode)) { + has_subdirs = true; + break; + } + } + + if (has_subdirs) { + for (it = root->data.dir.children; it != NULL; it = it->next) { + if (S_ISDIR(it->mode)) { + ret = serialize_recursive(filename, wr, it); + if (ret) + return ret; + } + } + } + + for (it = root->data.dir.children; it != NULL; it = it->next) { + ret = serialize_tree_node(filename, wr, it); + if (ret) + return ret; + } + + return 0; +} + int sqfs_serialize_fstree(const char *filename, sqfs_writer_t *wr) { - size_t i; int ret; wr->super.inode_table_start = wr->outfile->get_size(wr->outfile); - for (i = 0; i < wr->fs.inode_tbl_size; ++i) { - ret = serialize_tree_node(filename, wr, wr->fs.inode_table[i]); + if (S_ISDIR(wr->fs.root->mode)) { + ret = serialize_recursive(filename, wr, wr->fs.root); if (ret) goto out; } + ret = serialize_tree_node(filename, wr, wr->fs.root); + if (ret) + goto out; + ret = sqfs_meta_writer_flush(wr->im); if (ret) goto out; -- cgit v1.2.3