aboutsummaryrefslogtreecommitdiff
path: root/lib/common
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/common
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/common')
-rw-r--r--lib/common/serialize_fstree.c16
1 files changed, 11 insertions, 5 deletions
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);