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/common/serialize_fstree.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'lib/common') diff --git a/lib/common/serialize_fstree.c b/lib/common/serialize_fstree.c index a64d90f..39f8f94 100644 --- a/lib/common/serialize_fstree.c +++ b/lib/common/serialize_fstree.c @@ -28,27 +28,27 @@ static sqfs_inode_generic_t *tree_node_to_inode(tree_node_t *node) switch (node->mode & S_IFMT) { case S_IFSOCK: inode->base.type = SQFS_INODE_SOCKET; - inode->data.ipc.nlink = 1; + inode->data.ipc.nlink = node->link_count; break; case S_IFIFO: inode->base.type = SQFS_INODE_FIFO; - inode->data.ipc.nlink = 1; + inode->data.ipc.nlink = node->link_count; break; case S_IFLNK: inode->base.type = SQFS_INODE_SLINK; - inode->data.slink.nlink = 1; + inode->data.slink.nlink = node->link_count; inode->data.slink.target_size = extra; inode->slink_target = (char *)inode->extra; memcpy(inode->extra, node->data.target, extra); break; case S_IFBLK: inode->base.type = SQFS_INODE_BDEV; - inode->data.dev.nlink = 1; + inode->data.dev.nlink = node->link_count; inode->data.dev.devno = node->data.devno; break; case S_IFCHR: inode->base.type = SQFS_INODE_CDEV; - inode->data.dev.nlink = 1; + inode->data.dev.nlink = node->link_count; inode->data.dev.devno = node->data.devno; break; default: @@ -91,6 +91,12 @@ static sqfs_inode_generic_t *write_dir_entries(const char *filename, goto fail; } + if (inode->base.type == SQFS_INODE_DIR) { + inode->data.dir.nlink = node->link_count; + } else { + inode->data.dir_ext.nlink = node->link_count; + } + return inode; fail: sqfs_perror(filename, "recoding directory entries", ret); -- cgit v1.2.3