diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-12-15 14:21:06 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-12-16 14:46:24 +0100 |
commit | 9e2f960007887ea47fe273736f006569fc24df6d (patch) | |
tree | d96f832035f592607fb256ef089ba28425794fac /lib/common/serialize_fstree.c | |
parent | cae8192e0e5e922615a813426fa0df3e177724cb (diff) |
Cleanup: split sqfs_serialize_fstree into smaller functions
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common/serialize_fstree.c')
-rw-r--r-- | lib/common/serialize_fstree.c | 109 |
1 files changed, 52 insertions, 57 deletions
diff --git a/lib/common/serialize_fstree.c b/lib/common/serialize_fstree.c index 42843e2..3cfcb50 100644 --- a/lib/common/serialize_fstree.c +++ b/lib/common/serialize_fstree.c @@ -97,18 +97,63 @@ fail: return NULL; } +static int serialize_tree_node(const char *filename, sqfs_dir_writer_t *dirwr, + sqfs_meta_writer_t *im, sqfs_id_table_t *idtbl, + tree_node_t *n) +{ + sqfs_inode_generic_t *inode; + sqfs_u32 offset; + sqfs_u64 block; + int ret; + + if (S_ISDIR(n->mode)) { + inode = write_dir_entries(filename, dirwr, n); + ret = SQFS_ERROR_INTERNAL; + } else if (S_ISREG(n->mode)) { + inode = n->data.file.user_ptr; + n->data.file.user_ptr = NULL; + ret = SQFS_ERROR_INTERNAL; + } else { + inode = tree_node_to_inode(n); + ret = SQFS_ERROR_ALLOC; + } + + if (inode == NULL) + return ret; + + inode->base.mode = n->mode; + inode->base.mod_time = n->mod_time; + inode->base.inode_number = n->inode_num; + + sqfs_inode_set_xattr_index(inode, n->xattr_idx); + + ret = sqfs_id_table_id_to_index(idtbl, n->uid, + &inode->base.uid_idx); + if (ret) + goto out; + + ret = sqfs_id_table_id_to_index(idtbl, n->gid, + &inode->base.gid_idx); + if (ret) + goto out; + + sqfs_meta_writer_get_position(im, &block, &offset); + n->inode_ref = (block << 16) | offset; + + ret = sqfs_meta_writer_write_inode(im, inode); +out: + free(inode); + return ret; +} + int sqfs_serialize_fstree(const char *filename, sqfs_file_t *file, sqfs_super_t *super, fstree_t *fs, sqfs_compressor_t *cmp, sqfs_id_table_t *idtbl) { - sqfs_inode_generic_t *inode; sqfs_meta_writer_t *im, *dm; sqfs_dir_writer_t *dirwr; - sqfs_u32 offset; - sqfs_u64 block; - tree_node_t *n; - int ret = -1; size_t i; + int ret; im = sqfs_meta_writer_create(file, cmp, 0); if (im == NULL) { @@ -132,58 +177,8 @@ int sqfs_serialize_fstree(const char *filename, sqfs_file_t *file, super->inode_table_start = file->get_size(file); for (i = 0; i < fs->inode_tbl_size; ++i) { - n = fs->inode_table[i]; - - if (S_ISDIR(n->mode)) { - inode = write_dir_entries(filename, dirwr, n); - - if (inode == NULL) { - ret = 1; - goto out; - } - } else if (S_ISREG(n->mode)) { - inode = n->data.file.user_ptr; - n->data.file.user_ptr = NULL; - - if (inode == NULL) { - ret = SQFS_ERROR_INTERNAL; - goto out; - } - } else { - inode = tree_node_to_inode(n); - - if (inode == NULL) { - ret = SQFS_ERROR_ALLOC; - goto out; - } - } - - inode->base.mode = n->mode; - inode->base.mod_time = n->mod_time; - inode->base.inode_number = n->inode_num; - - sqfs_inode_set_xattr_index(inode, n->xattr_idx); - - ret = sqfs_id_table_id_to_index(idtbl, n->uid, - &inode->base.uid_idx); - if (ret) { - free(inode); - goto out; - } - - ret = sqfs_id_table_id_to_index(idtbl, n->gid, - &inode->base.gid_idx); - if (ret) { - free(inode); - goto out; - } - - sqfs_meta_writer_get_position(im, &block, &offset); - fs->inode_table[i]->inode_ref = (block << 16) | offset; - - ret = sqfs_meta_writer_write_inode(im, inode); - free(inode); - + ret = serialize_tree_node(filename, dirwr, im, idtbl, + fs->inode_table[i]); if (ret) goto out; } |