summaryrefslogtreecommitdiff
path: root/lib/sqfshelper/tree_node_to_inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfshelper/tree_node_to_inode.c')
-rw-r--r--lib/sqfshelper/tree_node_to_inode.c97
1 files changed, 23 insertions, 74 deletions
diff --git a/lib/sqfshelper/tree_node_to_inode.c b/lib/sqfshelper/tree_node_to_inode.c
index fa8c538..5cb04a4 100644
--- a/lib/sqfshelper/tree_node_to_inode.c
+++ b/lib/sqfshelper/tree_node_to_inode.c
@@ -39,69 +39,38 @@ static int get_type(tree_node_t *node)
if (node->xattr != NULL)
return SQFS_INODE_EXT_CDEV;
return SQFS_INODE_CDEV;
- case S_IFREG: {
- file_info_t *fi = node->data.file;
-
- if (node->xattr != NULL || fi->sparse > 0)
- return SQFS_INODE_EXT_FILE;
-
- if (fi->startblock > 0xFFFFFFFFUL || fi->size > 0xFFFFFFFFUL)
- return SQFS_INODE_EXT_FILE;
-
- return SQFS_INODE_FILE;
- }
}
assert(0);
}
-static bool has_fragment(const fstree_t *fs, const file_info_t *file)
-{
- if (file->size % fs->block_size == 0)
- return false;
-
- return file->fragment_offset < fs->block_size &&
- (file->fragment != 0xFFFFFFFF);
-}
-
-sqfs_inode_generic_t *tree_node_to_inode(fstree_t *fs, sqfs_id_table_t *idtbl,
+sqfs_inode_generic_t *tree_node_to_inode(sqfs_id_table_t *idtbl,
tree_node_t *node)
{
- size_t i, extra = 0, block_count = 0;
sqfs_inode_generic_t *inode;
uint16_t uid_idx, gid_idx;
uint32_t xattr = 0xFFFFFFFF;
- file_info_t *fi = NULL;
-
- if (S_ISLNK(node->mode)) {
- extra = strlen(node->data.slink_target);
- } else if (S_ISREG(node->mode)) {
- fi = node->data.file;
-
- block_count = fi->size / fs->block_size;
-
- if ((fi->size % fs->block_size) != 0 && !has_fragment(fs, fi))
- ++block_count;
-
- extra = block_count * sizeof(uint32_t);
- }
-
- 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;
+ 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;
+ }
- memcpy(inode->extra, node->data.slink_target, extra);
- } else if (S_ISREG(node->mode)) {
- inode->block_sizes = (uint32_t *)inode->extra;
+ if (S_ISLNK(node->mode)) {
+ inode->slink_target = (char *)inode->extra;
- for (i = 0; i < block_count; ++i) {
- inode->block_sizes[i] =
- node->data.file->block_size[i];
+ 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))
@@ -113,7 +82,6 @@ sqfs_inode_generic_t *tree_node_to_inode(fstree_t *fs, sqfs_id_table_t *idtbl,
if (node->xattr != NULL)
xattr = node->xattr->index;
- inode->base.type = get_type(node);
inode->base.mode = node->mode;
inode->base.uid_idx = uid_idx;
inode->base.gid_idx = gid_idx;
@@ -151,36 +119,17 @@ sqfs_inode_generic_t *tree_node_to_inode(fstree_t *fs, sqfs_id_table_t *idtbl,
inode->data.dev_ext.xattr_idx = xattr;
break;
case SQFS_INODE_FILE:
- inode->data.file.blocks_start = fi->startblock;
- inode->data.file.fragment_index = 0xFFFFFFFF;
- inode->data.file.fragment_offset = 0xFFFFFFFF;
- inode->data.file.file_size = fi->size;
-
- if (has_fragment(fs, fi)) {
- inode->data.file.fragment_index = fi->fragment;
- inode->data.file.fragment_offset = fi->fragment_offset;
+ if (xattr != 0xFFFFFFFF) {
+ sqfs_inode_make_extended(inode);
+ inode->data.file_ext.xattr_idx = xattr;
}
break;
case SQFS_INODE_EXT_FILE:
- inode->data.file_ext.blocks_start = fi->startblock;
- inode->data.file_ext.file_size = fi->size;
- inode->data.file_ext.sparse = fi->sparse;
- inode->data.file_ext.nlink = 1;
- inode->data.file_ext.fragment_idx = 0xFFFFFFFF;
- inode->data.file_ext.fragment_offset = 0xFFFFFFFF;
- inode->data.file_ext.xattr_idx = xattr;
-
- if (has_fragment(fs, fi)) {
- inode->data.file_ext.fragment_idx = fi->fragment;
- inode->data.file_ext.fragment_offset =
- fi->fragment_offset;
- }
break;
default:
goto fail;
}
- inode->num_file_blocks = block_count;
return inode;
fail:
free(inode);