summaryrefslogtreecommitdiff
path: root/lib/fstree/gen_inode_numbers.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-15 19:29:34 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-16 14:46:24 +0100
commitcaf350448c0020f95b9bfdd65770d86faf548549 (patch)
treeba71630dbf0c7b2c2395c23f494d6d1b3c3002f3 /lib/fstree/gen_inode_numbers.c
parent5aa1bab7fabc55a6f2a2ff2f7d8e2c49421cb215 (diff)
Remove fstree inode table
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/gen_inode_numbers.c')
-rw-r--r--lib/fstree/gen_inode_numbers.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/fstree/gen_inode_numbers.c b/lib/fstree/gen_inode_numbers.c
new file mode 100644
index 0000000..35dbc7a
--- /dev/null
+++ b/lib/fstree/gen_inode_numbers.c
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * gen_inode_numbers.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+static void map_child_nodes(fstree_t *fs, tree_node_t *root, size_t *counter)
+{
+ bool has_subdirs = false;
+ tree_node_t *it;
+
+ 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))
+ map_child_nodes(fs, it, counter);
+ }
+ }
+
+ for (it = root->data.dir.children; it != NULL; it = it->next) {
+ fs->unique_inode_count += 1;
+
+ it->inode_num = *counter;
+ *counter += 1;
+ }
+}
+
+void fstree_gen_inode_numbers(fstree_t *fs)
+{
+ size_t inum = 1;
+
+ fs->unique_inode_count = 0;
+ map_child_nodes(fs, fs->root, &inum);
+ fs->root->inode_num = inum;
+ fs->unique_inode_count += 1;
+}