From 19b98cf450220b742987e7f0599ae284e93f8e54 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 18 Dec 2019 17:40:49 +0100 Subject: Add an explicit link count to the fstree nodes Gets initialized to 2 for directories, 1 for all other types. The count of the parent node is automatically incremented. Signed-off-by: David Oberhollenzer --- lib/fstree/mknode.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/fstree') diff --git a/lib/fstree/mknode.c b/lib/fstree/mknode.c index 16cfa9c..4353b74 100644 --- a/lib/fstree/mknode.c +++ b/lib/fstree/mknode.c @@ -44,6 +44,7 @@ tree_node_t *fstree_mknode(tree_node_t *parent, const char *name, n->gid = sb->st_gid; n->mode = sb->st_mode; n->mod_time = sb->st_mtime; + n->link_count = 1; n->name = (char *)n->payload; memcpy(n->name, name, name_len); @@ -66,7 +67,13 @@ tree_node_t *fstree_mknode(tree_node_t *parent, const char *name, case S_IFCHR: n->data.devno = sb->st_rdev; break; + case S_IFDIR: + n->link_count = 2; + break; } + if (parent != NULL) + parent->link_count += 1; + return n; } -- cgit v1.2.3