summaryrefslogtreecommitdiff
path: root/lib/fstree
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-23 16:12:40 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-25 22:10:24 +0200
commit22fba34bcd0f2944def234fa684d1c9cc4d65310 (patch)
treebb7d122e7d2bd06583b358f0530dc7ee189ef279 /lib/fstree
parent8cc66cf51bdbf50e3476b58106627afc7adc1300 (diff)
Generate linear file list in fstree
Instead of doing DFS on the fly in gensquashfs, churn out a linked list of all files in an archive. Future improvements in packing strategies can go into this file. This can also be usefull for other purposes in the future, such as file deduplication or as a work queue for the unpacker. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree')
-rw-r--r--lib/fstree/gen_file_list.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/fstree/gen_file_list.c b/lib/fstree/gen_file_list.c
new file mode 100644
index 0000000..30cd2f6
--- /dev/null
+++ b/lib/fstree/gen_file_list.c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include "config.h"
+#include "fstree.h"
+
+static file_info_t *file_list_dfs(tree_node_t *n)
+{
+ if (S_ISREG(n->mode))
+ return n->data.file;
+
+ if (S_ISDIR(n->mode)) {
+ file_info_t *list = NULL, *last = NULL;
+
+ for (n = n->data.dir->children; n != NULL; n = n->next) {
+ if (list == NULL) {
+ list = file_list_dfs(n);
+ if (list == NULL)
+ continue;
+ last = list;
+ } else {
+ last->next = file_list_dfs(n);
+ }
+
+ while (last->next != NULL)
+ last = last->next;
+ }
+
+ return list;
+ }
+
+ return NULL;
+}
+
+void fstree_gen_file_list(fstree_t *fs)
+{
+ fs->files = file_list_dfs(fs->root);
+}