summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-03 15:06:17 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-03 15:24:08 +0200
commitac7484feb984d44fee880bc301122422ed536b25 (patch)
tree674ee311fac488b9e05a886bca4662b5461bc62a /lib
parent6a218f0927c0cced058e14ee5156f10860a149d3 (diff)
Move tree_node_to_inode function to fstree serialization code
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/sqfshelper/Makemodule.am1
-rw-r--r--lib/sqfshelper/serialize_fstree.c106
-rw-r--r--lib/sqfshelper/tree_node_to_inode.c117
3 files changed, 106 insertions, 118 deletions
diff --git a/lib/sqfshelper/Makemodule.am b/lib/sqfshelper/Makemodule.am
index 2ae1ac2..62990fa 100644
--- a/lib/sqfshelper/Makemodule.am
+++ b/lib/sqfshelper/Makemodule.am
@@ -1,6 +1,5 @@
libsqfshelper_a_SOURCES = lib/sqfshelper/serialize_fstree.c
libsqfshelper_a_SOURCES += lib/sqfshelper/statistics.c
-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/inode_stat.c
diff --git a/lib/sqfshelper/serialize_fstree.c b/lib/sqfshelper/serialize_fstree.c
index 854231c..2786789 100644
--- a/lib/sqfshelper/serialize_fstree.c
+++ b/lib/sqfshelper/serialize_fstree.c
@@ -7,13 +7,119 @@
#include "config.h"
#include "sqfs/meta_writer.h"
+#include "sqfs/inode.h"
+#include "sqfs/dir.h"
+
#include "highlevel.h"
#include "util.h"
+#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
+static int get_type(tree_node_t *node)
+{
+ switch (node->mode & S_IFMT) {
+ case S_IFSOCK: return SQFS_INODE_SOCKET;
+ case S_IFIFO: return SQFS_INODE_FIFO;
+ case S_IFLNK: return SQFS_INODE_SLINK;
+ case S_IFBLK: return SQFS_INODE_BDEV;
+ case S_IFCHR: return SQFS_INODE_CDEV;
+ }
+ assert(0);
+}
+
+static sqfs_inode_generic_t *tree_node_to_inode(sqfs_id_table_t *idtbl,
+ tree_node_t *node)
+{
+ sqfs_inode_generic_t *inode;
+ sqfs_u16 uid_idx, gid_idx;
+ size_t extra = 0;
+
+ if (S_ISREG(node->mode)) {
+ inode = node->data.file.user_ptr;
+ node->data.file.user_ptr = NULL;
+ } else {
+ if (S_ISLNK(node->mode))
+ extra = strlen(node->data.slink_target);
+
+ inode = alloc_flex(sizeof(*inode), 1, extra);
+ if (inode == NULL) {
+ perror("creating inode from file system tree node");
+ return NULL;
+ }
+
+ if (S_ISLNK(node->mode)) {
+ inode->slink_target = (char *)inode->extra;
+
+ memcpy(inode->extra, node->data.slink_target, extra);
+ }
+
+ inode->base.type = get_type(node);
+ }
+
+ if (sqfs_id_table_id_to_index(idtbl, node->uid, &uid_idx))
+ goto fail;
+
+ if (sqfs_id_table_id_to_index(idtbl, node->gid, &gid_idx))
+ goto fail;
+
+ if (node->xattr_idx != 0xFFFFFFFF)
+ sqfs_inode_make_extended(inode);
+
+ inode->base.mode = node->mode;
+ inode->base.uid_idx = uid_idx;
+ inode->base.gid_idx = gid_idx;
+ inode->base.mod_time = node->mod_time;
+ inode->base.inode_number = node->inode_num;
+
+ switch (inode->base.type) {
+ case SQFS_INODE_FIFO:
+ case SQFS_INODE_SOCKET:
+ inode->data.ipc.nlink = 1;
+ break;
+ case SQFS_INODE_EXT_FIFO:
+ case SQFS_INODE_EXT_SOCKET:
+ inode->data.ipc_ext.nlink = 1;
+ inode->data.ipc_ext.xattr_idx = node->xattr_idx;
+ break;
+ case SQFS_INODE_SLINK:
+ inode->data.slink.nlink = 1;
+ inode->data.slink.target_size = extra;
+ break;
+ case SQFS_INODE_EXT_SLINK:
+ inode->data.slink_ext.nlink = 1;
+ inode->data.slink_ext.target_size = extra;
+ inode->data.slink_ext.xattr_idx = node->xattr_idx;
+ break;
+ case SQFS_INODE_BDEV:
+ case SQFS_INODE_CDEV:
+ inode->data.dev.nlink = 1;
+ inode->data.dev.devno = node->data.devno;
+ break;
+ case SQFS_INODE_EXT_BDEV:
+ case SQFS_INODE_EXT_CDEV:
+ inode->data.dev_ext.nlink = 1;
+ inode->data.dev_ext.devno = node->data.devno;
+ inode->data.dev_ext.xattr_idx = node->xattr_idx;
+ break;
+ case SQFS_INODE_FILE:
+ break;
+ case SQFS_INODE_EXT_FILE:
+ inode->data.file_ext.xattr_idx = node->xattr_idx;
+ break;
+ default:
+ goto fail;
+ }
+
+ return inode;
+fail:
+ free(inode);
+ return NULL;
+}
+
static sqfs_inode_generic_t *write_dir_entries(sqfs_dir_writer_t *dirw,
tree_node_t *node,
sqfs_id_table_t *idtbl)
diff --git a/lib/sqfshelper/tree_node_to_inode.c b/lib/sqfshelper/tree_node_to_inode.c
deleted file mode 100644
index bafaaf7..0000000
--- a/lib/sqfshelper/tree_node_to_inode.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * write_inode.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include "highlevel.h"
-#include "sqfs/inode.h"
-#include "sqfs/dir.h"
-#include "util.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-
-static int get_type(tree_node_t *node)
-{
- switch (node->mode & S_IFMT) {
- case S_IFSOCK: return SQFS_INODE_SOCKET;
- case S_IFIFO: return SQFS_INODE_FIFO;
- case S_IFLNK: return SQFS_INODE_SLINK;
- case S_IFBLK: return SQFS_INODE_BDEV;
- case S_IFCHR: return SQFS_INODE_CDEV;
- }
- assert(0);
-}
-
-sqfs_inode_generic_t *tree_node_to_inode(sqfs_id_table_t *idtbl,
- tree_node_t *node)
-{
- sqfs_inode_generic_t *inode;
- sqfs_u16 uid_idx, gid_idx;
- size_t extra = 0;
-
- if (S_ISREG(node->mode)) {
- inode = node->data.file.user_ptr;
- node->data.file.user_ptr = NULL;
- } else {
- if (S_ISLNK(node->mode))
- extra = strlen(node->data.slink_target);
-
- inode = alloc_flex(sizeof(*inode), 1, extra);
- if (inode == NULL) {
- perror("creating inode from file system tree node");
- return NULL;
- }
-
- if (S_ISLNK(node->mode)) {
- inode->slink_target = (char *)inode->extra;
-
- memcpy(inode->extra, node->data.slink_target, extra);
- }
-
- inode->base.type = get_type(node);
- }
-
- if (sqfs_id_table_id_to_index(idtbl, node->uid, &uid_idx))
- goto fail;
-
- if (sqfs_id_table_id_to_index(idtbl, node->gid, &gid_idx))
- goto fail;
-
- if (node->xattr_idx != 0xFFFFFFFF)
- sqfs_inode_make_extended(inode);
-
- inode->base.mode = node->mode;
- inode->base.uid_idx = uid_idx;
- inode->base.gid_idx = gid_idx;
- inode->base.mod_time = node->mod_time;
- inode->base.inode_number = node->inode_num;
-
- switch (inode->base.type) {
- case SQFS_INODE_FIFO:
- case SQFS_INODE_SOCKET:
- inode->data.ipc.nlink = 1;
- break;
- case SQFS_INODE_EXT_FIFO:
- case SQFS_INODE_EXT_SOCKET:
- inode->data.ipc_ext.nlink = 1;
- inode->data.ipc_ext.xattr_idx = node->xattr_idx;
- break;
- case SQFS_INODE_SLINK:
- inode->data.slink.nlink = 1;
- inode->data.slink.target_size = extra;
- break;
- case SQFS_INODE_EXT_SLINK:
- inode->data.slink_ext.nlink = 1;
- inode->data.slink_ext.target_size = extra;
- inode->data.slink_ext.xattr_idx = node->xattr_idx;
- break;
- case SQFS_INODE_BDEV:
- case SQFS_INODE_CDEV:
- inode->data.dev.nlink = 1;
- inode->data.dev.devno = node->data.devno;
- break;
- case SQFS_INODE_EXT_BDEV:
- case SQFS_INODE_EXT_CDEV:
- inode->data.dev_ext.nlink = 1;
- inode->data.dev_ext.devno = node->data.devno;
- inode->data.dev_ext.xattr_idx = node->xattr_idx;
- break;
- case SQFS_INODE_FILE:
- break;
- case SQFS_INODE_EXT_FILE:
- inode->data.file_ext.xattr_idx = node->xattr_idx;
- break;
- default:
- goto fail;
- }
-
- return inode;
-fail:
- free(inode);
- return NULL;
-}