From caf350448c0020f95b9bfdd65770d86faf548549 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 15 Dec 2019 19:29:34 +0100 Subject: Remove fstree inode table Signed-off-by: David Oberhollenzer --- lib/common/writer.c | 5 ++- lib/fstree/Makemodule.am | 2 +- lib/fstree/fstree.c | 1 - lib/fstree/gen_inode_numbers.c | 49 ++++++++++++++++++++++++++++ lib/fstree/gen_inode_table.c | 74 ------------------------------------------ 5 files changed, 52 insertions(+), 79 deletions(-) create mode 100644 lib/fstree/gen_inode_numbers.c delete mode 100644 lib/fstree/gen_inode_table.c (limited to 'lib') 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_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 + */ +#include "config.h" + +#include "fstree.h" + +#include +#include + +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; +} 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 - */ -#include "config.h" - -#include "fstree.h" - -#include -#include - -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; -} -- cgit v1.2.3