diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-12-18 17:40:49 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-12-18 17:40:49 +0100 |
commit | 19b98cf450220b742987e7f0599ae284e93f8e54 (patch) | |
tree | 8845d9bae7f99920dd01ba7e7c52ee4baecf02d9 /lib | |
parent | 5dc3ab23d0552dc9460152f8a9089f25c8572d90 (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')
-rw-r--r-- | lib/common/serialize_fstree.c | 16 | ||||
-rw-r--r-- | lib/fstree/mknode.c | 7 |
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; } |