aboutsummaryrefslogtreecommitdiff
path: root/lib
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
parent5aa1bab7fabc55a6f2a2ff2f7d8e2c49421cb215 (diff)
Remove fstree inode table
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/common/writer.c5
-rw-r--r--lib/fstree/Makemodule.am2
-rw-r--r--lib/fstree/fstree.c1
-rw-r--r--lib/fstree/gen_inode_numbers.c (renamed from lib/fstree/gen_inode_table.c)37
4 files changed, 9 insertions, 36 deletions
diff --git a/lib/common/writer.c b/lib/common/writer.c
index 0b7f378..087ee3c 100644
--- a/lib/common/writer.c
+++ b/lib/common/writer.c
@@ -214,10 +214,9 @@ int sqfs_writer_finish(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *cfg)
fputs("Writing inodes and directories...\n", stdout);
tree_node_sort_recursive(sqfs->fs.root);
- if (fstree_gen_inode_table(&sqfs->fs))
- return -1;
+ fstree_gen_inode_numbers(&sqfs->fs);
- sqfs->super.inode_count = sqfs->fs.inode_tbl_size;
+ sqfs->super.inode_count = sqfs->fs.unique_inode_count;
if (sqfs_serialize_fstree(cfg->filename, sqfs))
return -1;
diff --git a/lib/fstree/Makemodule.am b/lib/fstree/Makemodule.am
index 6638480..bb17d24 100644
--- a/lib/fstree/Makemodule.am
+++ b/lib/fstree/Makemodule.am
@@ -1,6 +1,6 @@
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_table.c lib/fstree/get_path.c
+libfstree_a_SOURCES += lib/fstree/gen_inode_numbers.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
diff --git a/lib/fstree/fstree.c b/lib/fstree/fstree.c
index ad48508..90e14ce 100644
--- a/lib/fstree/fstree.c
+++ b/lib/fstree/fstree.c
@@ -128,6 +128,5 @@ int fstree_init(fstree_t *fs, char *defaults)
void fstree_cleanup(fstree_t *fs)
{
free_recursive(fs->root);
- free(fs->inode_table);
memset(fs, 0, sizeof(*fs));
}
diff --git a/lib/fstree/gen_inode_table.c b/lib/fstree/gen_inode_numbers.c
index 006029f..35dbc7a 100644
--- a/lib/fstree/gen_inode_table.c
+++ b/lib/fstree/gen_inode_numbers.c
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
- * gen_inode_table.c
+ * gen_inode_numbers.c
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
@@ -11,23 +11,6 @@
#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;
@@ -48,27 +31,19 @@ static void map_child_nodes(fstree_t *fs, tree_node_t *root, size_t *counter)
}
for (it = root->data.dir.children; it != NULL; it = it->next) {
+ fs->unique_inode_count += 1;
+
it->inode_num = *counter;
*counter += 1;
-
- fs->inode_table[it->inode_num - 1] = it;
}
}
-int fstree_gen_inode_table(fstree_t *fs)
+void fstree_gen_inode_numbers(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;
- }
-
+ fs->unique_inode_count = 0;
map_child_nodes(fs, fs->root, &inum);
fs->root->inode_num = inum;
- fs->inode_table[inum - 1] = fs->root;
- return 0;
+ fs->unique_inode_count += 1;
}