From 8c0aa2504199036eaaa09673ea93dcdcd79606ef Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 2 Jul 2022 21:14:45 +0200 Subject: Cleanup: move inode_stat to sqfs2tar After trying removing many instances of `struct stat`, there is only one user of inode_stat left, so move the function there. Signed-off-by: David Oberhollenzer --- bin/sqfs2tar/write_tree.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'bin') diff --git a/bin/sqfs2tar/write_tree.c b/bin/sqfs2tar/write_tree.c index e460481..5fa08e8 100644 --- a/bin/sqfs2tar/write_tree.c +++ b/bin/sqfs2tar/write_tree.c @@ -24,6 +24,47 @@ static sqfs_hard_link_t *find_hard_link(const char *name, sqfs_u32 inum) return lnk; } +static void inode_stat(const sqfs_tree_node_t *node, struct stat *sb) +{ + memset(sb, 0, sizeof(*sb)); + + sb->st_mode = node->inode->base.mode; + sb->st_uid = node->uid; + sb->st_gid = node->gid; + sb->st_mtime = node->inode->base.mod_time; + + switch (node->inode->base.type) { + case SQFS_INODE_BDEV: + case SQFS_INODE_CDEV: + sb->st_rdev = node->inode->data.dev.devno; + break; + case SQFS_INODE_EXT_BDEV: + case SQFS_INODE_EXT_CDEV: + sb->st_rdev = node->inode->data.dev_ext.devno; + break; + case SQFS_INODE_SLINK: + sb->st_size = node->inode->data.slink.target_size; + break; + case SQFS_INODE_EXT_SLINK: + sb->st_size = node->inode->data.slink_ext.target_size; + break; + case SQFS_INODE_FILE: + sb->st_size = node->inode->data.file.file_size; + break; + case SQFS_INODE_EXT_FILE: + sb->st_size = node->inode->data.file_ext.file_size; + break; + case SQFS_INODE_DIR: + sb->st_size = node->inode->data.dir.size; + break; + case SQFS_INODE_EXT_DIR: + sb->st_size = node->inode->data.dir_ext.size; + break; + default: + break; + } +} + static int write_tree_dfs(const sqfs_tree_node_t *n) { sqfs_hard_link_t *lnk = NULL; -- cgit v1.2.3