diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-15 15:59:01 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-15 15:59:01 +0200 |
commit | 36205a44d68576a158c9f233a17abe5f8a3c63a0 (patch) | |
tree | 11ae83cb10b33726cb8e4c48abe4a5b69c9b9a8d /lib/sqfshelper | |
parent | e165fb864fe86eda398a14713cf38924cc537adc (diff) |
Add helper function to directory writer to create a basic inode
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfshelper')
-rw-r--r-- | lib/sqfshelper/serialize_fstree.c | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/lib/sqfshelper/serialize_fstree.c b/lib/sqfshelper/serialize_fstree.c index 78f7d13..61f9ae2 100644 --- a/lib/sqfshelper/serialize_fstree.c +++ b/lib/sqfshelper/serialize_fstree.c @@ -14,31 +14,51 @@ #include <stdlib.h> #include <stdio.h> -static int write_dir_entries(sqfs_dir_writer_t *dirw, tree_node_t *node) +static sqfs_inode_generic_t *write_dir_entries(sqfs_dir_writer_t *dirw, + tree_node_t *node, + sqfs_id_table_t *idtbl) { + uint32_t xattr, parent_inode; + sqfs_inode_generic_t *inode; tree_node_t *it; - uint64_t ref; int ret; if (sqfs_dir_writer_begin(dirw)) - return -1; + return NULL; for (it = node->data.dir->children; it != NULL; it = it->next) { ret = sqfs_dir_writer_add_entry(dirw, it->name, it->inode_num, it->inode_ref, it->mode); if (ret) - return -1; + return NULL; } if (sqfs_dir_writer_end(dirw)) - return -1; + return NULL; + + xattr = (node->xattr == NULL) ? 0xFFFFFFFF : node->xattr->index; + parent_inode = (node->parent == NULL) ? 1 : node->parent->inode_num; + + inode = sqfs_dir_writer_create_inode(dirw, 0, xattr, parent_inode); + if (inode == NULL) { + perror("creating inode"); + return NULL; + } - ref = sqfs_dir_writer_get_dir_reference(dirw); + if (sqfs_id_table_id_to_index(idtbl, node->uid, &inode->base.uid_idx)) + goto fail_id; - node->data.dir->size = sqfs_dir_writer_get_size(dirw); - node->data.dir->start_block = ref >> 16; - node->data.dir->block_offset = ref & 0xFFFF; - return 0; + if (sqfs_id_table_id_to_index(idtbl, node->gid, &inode->base.gid_idx)) + goto fail_id; + + inode->base.mode = node->mode; + inode->base.mod_time = node->mod_time; + inode->base.inode_number = node->inode_num; + return inode; +fail_id: + fputs("failed to allocate IDs\n", stderr); + free(inode); + return NULL; } int sqfs_serialize_fstree(sqfs_file_t *file, sqfs_super_t *super, fstree_t *fs, @@ -69,19 +89,16 @@ int sqfs_serialize_fstree(sqfs_file_t *file, sqfs_super_t *super, fstree_t *fs, for (i = 2; i < fs->inode_tbl_size; ++i) { if (S_ISDIR(fs->inode_table[i]->mode)) { - if (write_dir_entries(dirwr, fs->inode_table[i])) - goto out; + inode = write_dir_entries(dirwr, fs->inode_table[i], + idtbl); + } else { + inode = tree_node_to_inode(fs, idtbl, + fs->inode_table[i]); } - inode = tree_node_to_inode(fs, idtbl, fs->inode_table[i]); if (inode == NULL) goto out; - if (inode->base.type == SQFS_INODE_EXT_DIR) { - inode->data.dir_ext.inodex_count = - sqfs_dir_writer_get_index_size(dirwr); - } - sqfs_meta_writer_get_position(im, &block, &offset); fs->inode_table[i]->inode_ref = (block << 16) | offset; |