summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common/writer.c3
-rw-r--r--lib/fstree/Makemodule.am3
-rw-r--r--lib/fstree/fstree_sort.c10
-rw-r--r--lib/fstree/gen_file_list.c43
-rw-r--r--lib/fstree/post_process.c (renamed from lib/fstree/gen_inode_numbers.c)48
5 files changed, 47 insertions, 60 deletions
diff --git a/lib/common/writer.c b/lib/common/writer.c
index 087ee3c..1bbf6bd 100644
--- a/lib/common/writer.c
+++ b/lib/common/writer.c
@@ -213,9 +213,6 @@ int sqfs_writer_finish(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *cfg)
if (!cfg->quiet)
fputs("Writing inodes and directories...\n", stdout);
- tree_node_sort_recursive(sqfs->fs.root);
- fstree_gen_inode_numbers(&sqfs->fs);
-
sqfs->super.inode_count = sqfs->fs.unique_inode_count;
if (sqfs_serialize_fstree(cfg->filename, sqfs))
diff --git a/lib/fstree/Makemodule.am b/lib/fstree/Makemodule.am
index bb17d24..64c2650 100644
--- a/lib/fstree/Makemodule.am
+++ b/lib/fstree/Makemodule.am
@@ -1,10 +1,9 @@
libfstree_a_SOURCES = lib/fstree/fstree.c lib/fstree/fstree_from_file.c
libfstree_a_SOURCES += lib/fstree/fstree_sort.c
-libfstree_a_SOURCES += lib/fstree/gen_inode_numbers.c lib/fstree/get_path.c
+libfstree_a_SOURCES += lib/fstree/post_process.c lib/fstree/get_path.c
libfstree_a_SOURCES += lib/fstree/mknode.c
libfstree_a_SOURCES += lib/fstree/add_by_path.c
libfstree_a_SOURCES += include/fstree.h
-libfstree_a_SOURCES += lib/fstree/gen_file_list.c
libfstree_a_SOURCES += lib/fstree/source_date_epoch.c
libfstree_a_SOURCES += lib/fstree/canonicalize_name.c
libfstree_a_CFLAGS = $(AM_CFLAGS)
diff --git a/lib/fstree/fstree_sort.c b/lib/fstree/fstree_sort.c
index 9cb177b..124106e 100644
--- a/lib/fstree/fstree_sort.c
+++ b/lib/fstree/fstree_sort.c
@@ -60,13 +60,3 @@ tree_node_t *tree_node_list_sort(tree_node_t *head)
return merge(tree_node_list_sort(head), tree_node_list_sort(half));
}
-
-void tree_node_sort_recursive(tree_node_t *n)
-{
- n->data.dir.children = tree_node_list_sort(n->data.dir.children);
-
- for (n = n->data.dir.children; n != NULL; n = n->next) {
- if (S_ISDIR(n->mode))
- tree_node_sort_recursive(n);
- }
-}
diff --git a/lib/fstree/gen_file_list.c b/lib/fstree/gen_file_list.c
deleted file mode 100644
index f20c131..0000000
--- a/lib/fstree/gen_file_list.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * gen_file_list.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-#include "fstree.h"
-
-static file_info_t *file_list_dfs(tree_node_t *n)
-{
- if (S_ISREG(n->mode)) {
- n->data.file.next = NULL;
- 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);
-}
diff --git a/lib/fstree/gen_inode_numbers.c b/lib/fstree/post_process.c
index 35dbc7a..5e7f152 100644
--- a/lib/fstree/gen_inode_numbers.c
+++ b/lib/fstree/post_process.c
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
- * gen_inode_numbers.c
+ * post_process.c
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
@@ -38,12 +38,56 @@ static void map_child_nodes(fstree_t *fs, tree_node_t *root, size_t *counter)
}
}
-void fstree_gen_inode_numbers(fstree_t *fs)
+static void sort_recursive(tree_node_t *n)
+{
+ n->data.dir.children = tree_node_list_sort(n->data.dir.children);
+
+ for (n = n->data.dir.children; n != NULL; n = n->next) {
+ if (S_ISDIR(n->mode))
+ sort_recursive(n);
+ }
+}
+
+static file_info_t *file_list_dfs(tree_node_t *n)
+{
+ if (S_ISREG(n->mode)) {
+ n->data.file.next = NULL;
+ 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_post_process(fstree_t *fs)
{
size_t inum = 1;
+ sort_recursive(fs->root);
+
fs->unique_inode_count = 0;
map_child_nodes(fs, fs->root, &inum);
fs->root->inode_num = inum;
fs->unique_inode_count += 1;
+
+ fs->files = file_list_dfs(fs->root);
}