summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-07-02 21:14:45 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-07-08 19:17:35 +0200
commit8c0aa2504199036eaaa09673ea93dcdcd79606ef (patch)
treea27807d97cb7c390cbba15c063b07650803de620
parent10ab81a0de97513d82d05945c12bff87b02ede27 (diff)
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 <david.oberhollenzer@sigma-star.at>
-rw-r--r--bin/sqfs2tar/write_tree.c41
-rw-r--r--include/common.h2
-rw-r--r--lib/common/Makemodule.am2
-rw-r--r--lib/common/inode_stat.c78
4 files changed, 42 insertions, 81 deletions
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;
diff --git a/include/common.h b/include/common.h
index cbd73b2..5ef4e05 100644
--- a/include/common.h
+++ b/include/common.h
@@ -34,8 +34,6 @@ typedef struct sqfs_hard_link_t {
char *target;
} sqfs_hard_link_t;
-int inode_stat(const sqfs_tree_node_t *node, struct stat *sb);
-
char *sqfs_tree_node_get_path(const sqfs_tree_node_t *node);
int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data,
diff --git a/lib/common/Makemodule.am b/lib/common/Makemodule.am
index 326f831..f0616fc 100644
--- a/lib/common/Makemodule.am
+++ b/lib/common/Makemodule.am
@@ -1,4 +1,4 @@
-libcommon_a_SOURCES = lib/common/inode_stat.c lib/common/hardlink.c
+libcommon_a_SOURCES = lib/common/hardlink.c
libcommon_a_SOURCES += lib/common/print_version.c lib/common/data_reader_dump.c
libcommon_a_SOURCES += lib/common/compress.c lib/common/comp_opt.c
libcommon_a_SOURCES += lib/common/data_writer.c include/common.h
diff --git a/lib/common/inode_stat.c b/lib/common/inode_stat.c
deleted file mode 100644
index fd0668a..0000000
--- a/lib/common/inode_stat.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * inode_stat.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "common.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-int 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_atime = node->inode->base.mod_time;
- sb->st_mtime = node->inode->base.mod_time;
- sb->st_ctime = node->inode->base.mod_time;
- sb->st_ino = node->inode->base.inode_number;
- sb->st_nlink = 1;
- sb->st_blksize = 512;
-
- switch (node->inode->base.type) {
- case SQFS_INODE_BDEV:
- case SQFS_INODE_CDEV:
- sb->st_rdev = node->inode->data.dev.devno;
- sb->st_nlink = node->inode->data.dev.nlink;
- break;
- case SQFS_INODE_EXT_BDEV:
- case SQFS_INODE_EXT_CDEV:
- sb->st_rdev = node->inode->data.dev_ext.devno;
- sb->st_nlink = node->inode->data.dev_ext.nlink;
- break;
- case SQFS_INODE_FIFO:
- case SQFS_INODE_SOCKET:
- sb->st_nlink = node->inode->data.ipc.nlink;
- break;
- case SQFS_INODE_EXT_FIFO:
- case SQFS_INODE_EXT_SOCKET:
- sb->st_nlink = node->inode->data.ipc_ext.nlink;
- break;
- case SQFS_INODE_SLINK:
- sb->st_size = node->inode->data.slink.target_size;
- sb->st_nlink = node->inode->data.slink.nlink;
- break;
- case SQFS_INODE_EXT_SLINK:
- sb->st_size = node->inode->data.slink_ext.target_size;
- sb->st_nlink = node->inode->data.slink_ext.nlink;
- 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;
- sb->st_nlink = node->inode->data.file_ext.nlink;
- break;
- case SQFS_INODE_DIR:
- sb->st_size = node->inode->data.dir.size;
- sb->st_nlink = node->inode->data.dir.nlink;
- break;
- case SQFS_INODE_EXT_DIR:
- sb->st_size = node->inode->data.dir_ext.size;
- sb->st_nlink = node->inode->data.dir_ext.nlink;
- break;
- default:
- break;
- }
-
- sb->st_blocks = sb->st_size / sb->st_blksize;
- if (sb->st_size % sb->st_blksize)
- sb->st_blocks += 1;
-
- return 0;
-}