aboutsummaryrefslogtreecommitdiff
path: root/lib/fstree
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-23 00:42:53 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-23 00:50:00 +0100
commit9db873364de85e6b5f972dbd2bada80591ef8af4 (patch)
tree32be9fbb328e6f5f3c1ef4111fe1dec7a19827df /lib/fstree
parentb16616ef092e8cd97674aac3380c5d7c600d7c61 (diff)
Bring back the flat list of inodes in libfstree
It makes further processing simpler and doesn't leak the abstraction into upper layers. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree')
-rw-r--r--lib/fstree/fstree.c1
-rw-r--r--lib/fstree/post_process.c27
2 files changed, 25 insertions, 3 deletions
diff --git a/lib/fstree/fstree.c b/lib/fstree/fstree.c
index ce35b84..b2e199d 100644
--- a/lib/fstree/fstree.c
+++ b/lib/fstree/fstree.c
@@ -126,5 +126,6 @@ int fstree_init(fstree_t *fs, char *defaults)
void fstree_cleanup(fstree_t *fs)
{
free_recursive(fs->root);
+ free(fs->inodes);
memset(fs, 0, sizeof(*fs));
}
diff --git a/lib/fstree/post_process.c b/lib/fstree/post_process.c
index e6bcb3f..c2b462b 100644
--- a/lib/fstree/post_process.c
+++ b/lib/fstree/post_process.c
@@ -47,7 +47,7 @@ static void hard_link_snap(tree_node_t *n)
n->data.target_node = n->data.target_node->data.target_node;
}
-static int map_child_nodes(fstree_t *fs, tree_node_t *root, size_t *counter)
+static int alloc_inode_num_dfs(fstree_t *fs, tree_node_t *root, size_t *counter)
{
bool has_subdirs = false;
tree_node_t *it, *tgt;
@@ -68,7 +68,7 @@ static int map_child_nodes(fstree_t *fs, tree_node_t *root, size_t *counter)
if (has_subdirs) {
for (it = root->data.dir.children; it != NULL; it = it->next) {
if (S_ISDIR(it->mode)) {
- if (map_child_nodes(fs, it, counter))
+ if (alloc_inode_num_dfs(fs, it, counter))
return -1;
}
}
@@ -172,6 +172,19 @@ static file_info_t *file_list_dfs(tree_node_t *n)
return NULL;
}
+static void map_inodes_dfs(fstree_t *fs, tree_node_t *n)
+{
+ if (n->mode == FSTREE_MODE_HARD_LINK_RESOLVED)
+ return;
+
+ fs->inodes[n->inode_num - 1] = n;
+
+ if (S_ISDIR(n->mode)) {
+ for (n = n->data.dir.children; n != NULL; n = n->next)
+ map_inodes_dfs(fs, n);
+ }
+}
+
int fstree_post_process(fstree_t *fs)
{
size_t inum = 1;
@@ -182,11 +195,19 @@ int fstree_post_process(fstree_t *fs)
return -1;
fs->unique_inode_count = 0;
- if (map_child_nodes(fs, fs->root, &inum))
+ if (alloc_inode_num_dfs(fs, fs->root, &inum))
return -1;
fs->root->inode_num = inum;
fs->unique_inode_count += 1;
+ fs->inodes = calloc(sizeof(fs->inodes[0]), fs->unique_inode_count);
+ if (fs->inodes == NULL) {
+ perror("Allocating inode list");
+ return -1;
+ }
+
+ map_inodes_dfs(fs, fs->root);
+
fs->files = file_list_dfs(fs->root);
return 0;
}