diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-20 14:08:34 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-20 14:08:34 +0200 |
commit | c5f0334e87deea2b54f33f62ee879455a814633c (patch) | |
tree | 8d384482c8cd29d3ebe5b280b7d853968aff816c /lib/fstree/src | |
parent | d7be81367997536dceb08a7be0014136a1f89df2 (diff) |
libfstree: Remove special modes for hard links
Instead of adding special sentinel modes, simply treat hard links as
special case of symlinks, setting a flag to indicate that it is a
hard link and another flag to indicate that it has been resolved.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/src')
-rw-r--r-- | lib/fstree/src/hardlink.c | 13 | ||||
-rw-r--r-- | lib/fstree/src/post_process.c | 25 |
2 files changed, 21 insertions, 17 deletions
diff --git a/lib/fstree/src/hardlink.c b/lib/fstree/src/hardlink.c index 81636c7..b6467e2 100644 --- a/lib/fstree/src/hardlink.c +++ b/lib/fstree/src/hardlink.c @@ -18,16 +18,17 @@ static int resolve_link(fstree_t *fs, tree_node_t *node) tree_node_t *start = node; for (;;) { - if (node->mode == FSTREE_MODE_HARD_LINK_RESOLVED) { + if (!S_ISLNK(node->mode) || !(node->flags & FLAG_LINK_IS_HARD)) + break; + + if (node->flags & FLAG_LINK_RESOVED) { node = node->data.target_node; - } else if (node->mode == FSTREE_MODE_HARD_LINK) { + } else { node = fstree_get_node_by_path(fs, fs->root, node->data.target, false, false); if (node == NULL) return -1; - } else { - break; } if (node == start) { @@ -46,7 +47,7 @@ static int resolve_link(fstree_t *fs, tree_node_t *node) return -1; } - start->mode = FSTREE_MODE_HARD_LINK_RESOLVED; + start->flags |= FLAG_LINK_RESOVED; start->data.target_node = node; node->link_count++; @@ -70,7 +71,7 @@ tree_node_t *fstree_add_hard_link(fstree_t *fs, const char *path, return NULL; } - n->mode = FSTREE_MODE_HARD_LINK; + n->flags |= FLAG_LINK_IS_HARD; } n->next_by_type = fs->links_unresolved; diff --git a/lib/fstree/src/post_process.c b/lib/fstree/src/post_process.c index f8bc0f7..c5a15a3 100644 --- a/lib/fstree/src/post_process.c +++ b/lib/fstree/src/post_process.c @@ -35,18 +35,19 @@ static int alloc_inode_num_dfs(fstree_t *fs, tree_node_t *root) } 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; + if (S_ISLNK(it->mode) && (it->flags & FLAG_LINK_IS_HARD)) + continue; - if ((sizeof(size_t) > sizeof(sqfs_u32)) && - inum > 0x0FFFFFFFFUL) { - goto fail_ov; - } + if (SZ_ADD_OV(fs->unique_inode_count, 1, &inum)) + goto fail_ov; - it->inode_num = (sqfs_u32)inum; - fs->unique_inode_count = inum; + if ((sizeof(size_t) > sizeof(sqfs_u32)) && + inum > 0x0FFFFFFFFUL) { + goto fail_ov; } + + it->inode_num = (sqfs_u32)inum; + fs->unique_inode_count = inum; } return 0; @@ -87,7 +88,7 @@ static tree_node_t *file_list_dfs(tree_node_t *n) static void map_inodes_dfs(fstree_t *fs, tree_node_t *n) { - if (n->mode == FSTREE_MODE_HARD_LINK_RESOLVED) + if (S_ISLNK(n->mode) && (n->flags & FLAG_LINK_IS_HARD)) return; fs->inodes[n->inode_num - 1] = n; @@ -110,7 +111,9 @@ static void reorder_hard_links(fstree_t *fs) it = fs->inodes[i]->data.children; for (; it != NULL; it = it->next) { - if (it->mode != FSTREE_MODE_HARD_LINK_RESOLVED) + if (!S_ISLNK(it->mode)) + continue; + if (!(it->flags & FLAG_LINK_IS_HARD)) continue; tgt = it->data.target_node; |