aboutsummaryrefslogtreecommitdiff
path: root/lib/fstree/src
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-19 08:51:26 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-19 11:17:51 +0200
commit75fb524b5702bca4f8467309f7d95f9937ec6683 (patch)
treeb47a037c0f24873a9fc5b3f5b08583c9ad90de08 /lib/fstree/src
parenta13df03fddd9499960d4653aaee0970983b65f73 (diff)
libfstree: get rid of dir_info_t
The single boolean created_implicitly can be replaced with a general purpose flag field. The "children" pointer can then be hoisted directly into the data union of tree_node_t. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/src')
-rw-r--r--lib/fstree/src/add_by_path.c6
-rw-r--r--lib/fstree/src/fstree.c8
-rw-r--r--lib/fstree/src/get_by_path.c4
-rw-r--r--lib/fstree/src/hardlink.c2
-rw-r--r--lib/fstree/src/mknode.c4
-rw-r--r--lib/fstree/src/post_process.c12
6 files changed, 18 insertions, 18 deletions
diff --git a/lib/fstree/src/add_by_path.c b/lib/fstree/src/add_by_path.c
index 0afd898..344b586 100644
--- a/lib/fstree/src/add_by_path.c
+++ b/lib/fstree/src/add_by_path.c
@@ -31,13 +31,13 @@ tree_node_t *fstree_add_generic(fstree_t *fs, const char *path,
name = strrchr(path, '/');
name = (name == NULL ? path : (name + 1));
- child = parent->data.dir.children;
+ child = parent->data.children;
while (child != NULL && strcmp(child->name, name) != 0)
child = child->next;
out:
if (child != NULL) {
if (!S_ISDIR(child->mode) || !S_ISDIR(sb->st_mode) ||
- !child->data.dir.created_implicitly) {
+ !(child->flags & FLAG_DIR_CREATED_IMPLICITLY)) {
errno = EEXIST;
return NULL;
}
@@ -46,7 +46,7 @@ out:
child->gid = sb->st_gid;
child->mode = sb->st_mode;
child->mod_time = sb->st_mtime;
- child->data.dir.created_implicitly = false;
+ child->flags &= ~FLAG_DIR_CREATED_IMPLICITLY;
return child;
}
diff --git a/lib/fstree/src/fstree.c b/lib/fstree/src/fstree.c
index 19bd997..bf84c17 100644
--- a/lib/fstree/src/fstree.c
+++ b/lib/fstree/src/fstree.c
@@ -16,9 +16,9 @@ static void free_recursive(tree_node_t *n)
tree_node_t *it;
if (S_ISDIR(n->mode)) {
- while (n->data.dir.children != NULL) {
- it = n->data.dir.children;
- n->data.dir.children = it->next;
+ while (n->data.children != NULL) {
+ it = n->data.children;
+ n->data.children = it->next;
free_recursive(it);
}
@@ -47,7 +47,7 @@ int fstree_init(fstree_t *fs, const fstree_defaults_t *defaults)
return -1;
}
- fs->root->data.dir.created_implicitly = true;
+ fs->root->flags |= FLAG_DIR_CREATED_IMPLICITLY;
return 0;
}
diff --git a/lib/fstree/src/get_by_path.c b/lib/fstree/src/get_by_path.c
index f5e7374..133f412 100644
--- a/lib/fstree/src/get_by_path.c
+++ b/lib/fstree/src/get_by_path.c
@@ -14,7 +14,7 @@
static tree_node_t *child_by_name(tree_node_t *root, const char *name,
size_t len)
{
- tree_node_t *n = root->data.dir.children;
+ tree_node_t *n = root->data.children;
while (n != NULL) {
if (strncmp(n->name, name, len) == 0 && n->name[len] == '\0')
@@ -73,7 +73,7 @@ tree_node_t *fstree_get_node_by_path(fstree_t *fs, tree_node_t *root,
if (n == NULL)
return NULL;
- n->data.dir.created_implicitly = true;
+ n->flags |= FLAG_DIR_CREATED_IMPLICITLY;
}
root = n;
diff --git a/lib/fstree/src/hardlink.c b/lib/fstree/src/hardlink.c
index fc3c4d0..6973b4c 100644
--- a/lib/fstree/src/hardlink.c
+++ b/lib/fstree/src/hardlink.c
@@ -61,7 +61,7 @@ static int resolve_hard_links_dfs(fstree_t *fs, tree_node_t *n)
if (resolve_link(fs, n))
goto fail_link;
} else if (S_ISDIR(n->mode)) {
- for (it = n->data.dir.children; it != NULL; it = it->next) {
+ for (it = n->data.children; it != NULL; it = it->next) {
if (resolve_hard_links_dfs(fs, it))
return -1;
}
diff --git a/lib/fstree/src/mknode.c b/lib/fstree/src/mknode.c
index 8f1d212..a48cf06 100644
--- a/lib/fstree/src/mknode.c
+++ b/lib/fstree/src/mknode.c
@@ -13,7 +13,7 @@
static void insert_sorted(tree_node_t *root, tree_node_t *n)
{
- tree_node_t *it = root->data.dir.children, *prev = NULL;
+ tree_node_t *it = root->data.children, *prev = NULL;
while (it != NULL && strcmp(it->name, n->name) < 0) {
prev = it;
@@ -24,7 +24,7 @@ static void insert_sorted(tree_node_t *root, tree_node_t *n)
n->next = it;
if (prev == NULL) {
- root->data.dir.children = n;
+ root->data.children = n;
} else {
prev->next = n;
}
diff --git a/lib/fstree/src/post_process.c b/lib/fstree/src/post_process.c
index f614906..5bf7e7d 100644
--- a/lib/fstree/src/post_process.c
+++ b/lib/fstree/src/post_process.c
@@ -18,7 +18,7 @@ static int alloc_inode_num_dfs(fstree_t *fs, tree_node_t *root)
tree_node_t *it;
size_t inum;
- for (it = root->data.dir.children; it != NULL; it = it->next) {
+ for (it = root->data.children; it != NULL; it = it->next) {
if (S_ISDIR(it->mode)) {
has_subdirs = true;
break;
@@ -26,7 +26,7 @@ static int alloc_inode_num_dfs(fstree_t *fs, tree_node_t *root)
}
if (has_subdirs) {
- for (it = root->data.dir.children; it != NULL; it = it->next) {
+ for (it = root->data.children; it != NULL; it = it->next) {
if (S_ISDIR(it->mode)) {
if (alloc_inode_num_dfs(fs, it))
return -1;
@@ -34,7 +34,7 @@ static int alloc_inode_num_dfs(fstree_t *fs, tree_node_t *root)
}
}
- for (it = root->data.dir.children; it != NULL; it = it->next) {
+ for (it = root->data.children; it != NULL; it = it->next) {
if (it->mode != FSTREE_MODE_HARD_LINK_RESOLVED) {
if (SZ_ADD_OV(fs->unique_inode_count, 1, &inum))
goto fail_ov;
@@ -65,7 +65,7 @@ static file_info_t *file_list_dfs(tree_node_t *n)
if (S_ISDIR(n->mode)) {
file_info_t *list = NULL, *last = NULL;
- for (n = n->data.dir.children; n != NULL; n = n->next) {
+ for (n = n->data.children; n != NULL; n = n->next) {
if (list == NULL) {
list = file_list_dfs(n);
if (list == NULL)
@@ -93,7 +93,7 @@ static void map_inodes_dfs(fstree_t *fs, tree_node_t *n)
fs->inodes[n->inode_num - 1] = n;
if (S_ISDIR(n->mode)) {
- for (n = n->data.dir.children; n != NULL; n = n->next)
+ for (n = n->data.children; n != NULL; n = n->next)
map_inodes_dfs(fs, n);
}
}
@@ -107,7 +107,7 @@ static void reorder_hard_links(fstree_t *fs)
if (!S_ISDIR(fs->inodes[i]->mode))
continue;
- it = fs->inodes[i]->data.dir.children;
+ it = fs->inodes[i]->data.children;
for (; it != NULL; it = it->next) {
if (it->mode != FSTREE_MODE_HARD_LINK_RESOLVED)