summaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-15 19:22:06 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-16 14:46:24 +0100
commit5aa1bab7fabc55a6f2a2ff2f7d8e2c49421cb215 (patch)
tree2502932c4510a3d0030b4bef7dccd1a6b628640a /lib/common
parent7f567bb6ee1954e2d8a886b1d3dcb8cb4a1ed486 (diff)
Do the fstree serialization in a recursive tree walk
Remove usage of the "inode table". Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/serialize_fstree.c42
1 files changed, 39 insertions, 3 deletions
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;