aboutsummaryrefslogtreecommitdiff
path: root/lib/fstree/gen_inode_table.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_table.c
parent5aa1bab7fabc55a6f2a2ff2f7d8e2c49421cb215 (diff)
Remove fstree inode table
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/gen_inode_table.c')
-rw-r--r--lib/fstree/gen_inode_table.c74
1 files changed, 0 insertions, 74 deletions
diff --git a/lib/fstree/gen_inode_table.c b/lib/fstree/gen_inode_table.c
deleted file mode 100644
index 006029f..0000000
--- a/lib/fstree/gen_inode_table.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * gen_inode_table.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include "fstree.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-
-static size_t count_nodes(tree_node_t *root)
-{
- tree_node_t *n = root->data.dir.children;
- size_t count = 1;
-
- while (n != NULL) {
- if (S_ISDIR(n->mode)) {
- count += count_nodes(n);
- } else {
- ++count;
- }
- n = n->next;
- }
-
- return count;
-}
-
-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) {
- it->inode_num = *counter;
- *counter += 1;
-
- fs->inode_table[it->inode_num - 1] = it;
- }
-}
-
-int fstree_gen_inode_table(fstree_t *fs)
-{
- size_t inum = 1;
-
- fs->inode_tbl_size = count_nodes(fs->root);
- fs->inode_table = calloc(1, sizeof(tree_node_t*) * fs->inode_tbl_size);
-
- if (fs->inode_table == NULL) {
- perror("allocating inode table");
- return -1;
- }
-
- map_child_nodes(fs, fs->root, &inum);
- fs->root->inode_num = inum;
- fs->inode_table[inum - 1] = fs->root;
- return 0;
-}