summaryrefslogtreecommitdiff
path: root/lib/fstree/mknode.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-18 17:40:49 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-18 17:40:49 +0100
commit19b98cf450220b742987e7f0599ae284e93f8e54 (patch)
tree8845d9bae7f99920dd01ba7e7c52ee4baecf02d9 /lib/fstree/mknode.c
parent5dc3ab23d0552dc9460152f8a9089f25c8572d90 (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/mknode.c')
-rw-r--r--lib/fstree/mknode.c7
1 files changed, 7 insertions, 0 deletions
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;
}