summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/highlevel.h3
-rw-r--r--lib/sqfshelper/Makemodule.am1
-rw-r--r--lib/sqfshelper/inode_stat.c78
3 files changed, 82 insertions, 0 deletions
diff --git a/include/highlevel.h b/include/highlevel.h
index 8173d6f..1c1ea11 100644
--- a/include/highlevel.h
+++ b/include/highlevel.h
@@ -22,6 +22,7 @@
#include "data_writer.h"
#include "fstree.h"
+#include <sys/stat.h>
#include <stdint.h>
#include <stddef.h>
@@ -120,4 +121,6 @@ int xattr_reader_restore_node(sqfs_xattr_reader_t *xr, fstree_t *fs,
sqfs_inode_generic_t *tree_node_to_inode(fstree_t *fs, sqfs_id_table_t *idtbl,
tree_node_t *node);
+int inode_stat(const sqfs_tree_node_t *node, struct stat *sb);
+
#endif /* HIGHLEVEL_H */
diff --git a/lib/sqfshelper/Makemodule.am b/lib/sqfshelper/Makemodule.am
index 623b2b0..32d9852 100644
--- a/lib/sqfshelper/Makemodule.am
+++ b/lib/sqfshelper/Makemodule.am
@@ -7,6 +7,7 @@ libsqfshelper_a_SOURCES += lib/sqfshelper/tree_node_to_inode.c
libsqfshelper_a_SOURCES += lib/sqfshelper/write_export_table.c
libsqfshelper_a_SOURCES += lib/sqfshelper/print_version.c
libsqfshelper_a_SOURCES += lib/sqfshelper/xattr_reader.c
+libsqfshelper_a_SOURCES += lib/sqfshelper/inode_stat.c
libsqfshelper_a_SOURCES += lib/sqfshelper/compress.c lib/sqfshelper/comp_opt.c
libsqfshelper_a_SOURCES += include/data_reader.h lib/sqfshelper/data_reader.c
libsqfshelper_a_SOURCES += include/data_writer.h lib/sqfshelper/data_writer.c
diff --git a/lib/sqfshelper/inode_stat.c b/lib/sqfshelper/inode_stat.c
new file mode 100644
index 0000000..67ff764
--- /dev/null
+++ b/lib/sqfshelper/inode_stat.c
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * inode_stat.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "highlevel.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;
+ }
+
+ sb->st_blocks = sb->st_size / sb->st_blksize;
+ if (sb->st_size % sb->st_blksize)
+ sb->st_blocks += 1;
+
+ return 0;
+}