aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common/serialize_fstree.c16
-rw-r--r--lib/fstree/mknode.c7
2 files changed, 18 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);
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;
}