aboutsummaryrefslogtreecommitdiff
path: root/unpack
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-22 01:48:50 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-22 02:13:06 +0200
commit57b6a4c855120bc721cd4e76cca32c7b1a382407 (patch)
tree0ee339243e0062cd5543324383e921cfa5273be2 /unpack
parent1bf363ba52025a0cf504b313878ea99c174a1683 (diff)
Add helper functions for working with inodes
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack')
-rw-r--r--unpack/dump_xattrs.c22
-rw-r--r--unpack/fill_files.c73
-rw-r--r--unpack/list_files.c11
-rw-r--r--unpack/restore_fstree.c22
4 files changed, 29 insertions, 99 deletions
diff --git a/unpack/dump_xattrs.c b/unpack/dump_xattrs.c
index c619767..13bddfe 100644
--- a/unpack/dump_xattrs.c
+++ b/unpack/dump_xattrs.c
@@ -17,27 +17,7 @@ int dump_xattrs(sqfs_xattr_reader_t *xattr, const sqfs_inode_generic_t *inode)
if (xattr == NULL)
return 0;
- switch (inode->base.type) {
- case SQFS_INODE_EXT_DIR:
- index = inode->data.dir_ext.xattr_idx;
- break;
- case SQFS_INODE_EXT_FILE:
- index = inode->data.file_ext.xattr_idx;
- break;
- case SQFS_INODE_EXT_SLINK:
- index = inode->data.slink_ext.xattr_idx;
- break;
- case SQFS_INODE_EXT_BDEV:
- case SQFS_INODE_EXT_CDEV:
- index = inode->data.dev_ext.xattr_idx;
- break;
- case SQFS_INODE_EXT_FIFO:
- case SQFS_INODE_EXT_SOCKET:
- index = inode->data.ipc_ext.xattr_idx;
- break;
- default:
- return 0;
- }
+ sqfs_inode_get_xattr_index(inode, &index);
if (index == 0xFFFFFFFF)
return 0;
diff --git a/unpack/fill_files.c b/unpack/fill_files.c
index 2c20ab0..3d1e7b2 100644
--- a/unpack/fill_files.c
+++ b/unpack/fill_files.c
@@ -15,80 +15,51 @@ static struct file_ent {
static size_t num_files = 0, max_files = 0;
static size_t block_size = 0;
-static uint32_t get_frag_idx(const sqfs_inode_generic_t *inode)
-{
- if (inode->base.type == SQFS_INODE_EXT_FILE)
- return inode->data.file_ext.fragment_idx;
-
- return inode->data.file.fragment_index;
-}
-
-static uint32_t get_frag_off(const sqfs_inode_generic_t *inode)
-{
- if (inode->base.type == SQFS_INODE_EXT_FILE)
- return inode->data.file_ext.fragment_offset;
-
- return inode->data.file.fragment_offset;
-}
-
-static uint64_t get_size(const sqfs_inode_generic_t *inode)
-{
- if (inode->base.type == SQFS_INODE_EXT_FILE)
- return inode->data.file_ext.file_size;
-
- return inode->data.file.file_size;
-}
-
-static uint64_t get_start(const sqfs_inode_generic_t *inode)
-{
- if (inode->base.type == SQFS_INODE_EXT_FILE)
- return inode->data.file_ext.blocks_start;
-
- return inode->data.file.blocks_start;
-}
-
-static bool has_fragment(const struct file_ent *ent)
-{
- if (get_size(ent->inode) % block_size == 0)
- return false;
-
- return get_frag_off(ent->inode) < block_size &&
- (get_frag_idx(ent->inode) != 0xFFFFFFFF);
-}
-
static int compare_files(const void *l, const void *r)
{
+ uint32_t lhs_frag_idx, lhs_frag_off, rhs_frag_idx, rhs_frag_off;
+ uint64_t lhs_size, rhs_size, lhs_start, rhs_start;
const struct file_ent *lhs = l, *rhs = r;
+ sqfs_inode_get_frag_location(lhs->inode, &lhs_frag_idx, &lhs_frag_off);
+ sqfs_inode_get_file_block_start(lhs->inode, &lhs_start);
+ sqfs_inode_get_file_size(lhs->inode, &lhs_size);
+
+ sqfs_inode_get_frag_location(rhs->inode, &rhs_frag_idx, &rhs_frag_off);
+ sqfs_inode_get_file_block_start(rhs->inode, &rhs_start);
+ sqfs_inode_get_file_size(rhs->inode, &rhs_size);
+
/* Files with fragments come first, ordered by ID.
In case of tie, files without data blocks come first,
and the others are ordered by start block. */
- if (has_fragment(lhs)) {
- if (!(has_fragment(rhs)))
+ if ((lhs_size % block_size) && (lhs_frag_off < block_size) &&
+ (lhs_frag_idx != 0xFFFFFFFF)) {
+ if ((rhs_size % block_size) && (rhs_frag_off < block_size) &&
+ (rhs_frag_idx != 0xFFFFFFFF))
return -1;
- if (get_frag_idx(lhs->inode) < get_frag_idx(rhs->inode))
+ if (lhs_frag_idx < rhs_frag_idx)
return -1;
- if (get_frag_idx(lhs->inode) > get_frag_idx(rhs->inode))
+ if (lhs_frag_idx > rhs_frag_idx)
return 1;
- if (get_size(lhs->inode) < block_size)
- return (get_size(rhs->inode) < block_size) ? 0 : -1;
+ if (lhs_size < block_size)
+ return (rhs_size < block_size) ? 0 : -1;
- if (get_size(rhs->inode) < block_size)
+ if (rhs_size < block_size)
return 1;
goto order_by_start;
}
- if (has_fragment(rhs))
+ if ((rhs_size % block_size) && (rhs_frag_off < block_size) &&
+ (rhs_frag_idx != 0xFFFFFFFF))
return 1;
/* order the rest by start block */
order_by_start:
- return get_start(lhs->inode) < get_start(rhs->inode) ? -1 :
- get_start(lhs->inode) > get_start(rhs->inode) ? 1 : 0;
+ return lhs_start < rhs_start ? -1 : lhs_start > rhs_start ? 1 : 0;
}
static int add_file(const sqfs_tree_node_t *node)
diff --git a/unpack/list_files.c b/unpack/list_files.c
index 11e18cb..ae259bd 100644
--- a/unpack/list_files.c
+++ b/unpack/list_files.c
@@ -87,13 +87,12 @@ static void print_node_size(const sqfs_tree_node_t *n, char *buffer)
case S_IFLNK:
print_size(strlen(n->inode->slink_target), buffer);
break;
- case S_IFREG:
- if (n->inode->base.type == SQFS_INODE_EXT_FILE) {
- print_size(n->inode->data.file_ext.file_size, buffer);
- } else {
- print_size(n->inode->data.file.file_size, buffer);
- }
+ case S_IFREG: {
+ uint64_t size;
+ sqfs_inode_get_file_size(n->inode, &size);
+ print_size(size, buffer);
break;
+ }
case S_IFDIR:
if (n->inode->base.type == SQFS_INODE_EXT_DIR) {
print_size(n->inode->data.dir_ext.size, buffer);
diff --git a/unpack/restore_fstree.c b/unpack/restore_fstree.c
index afa4abb..5b82de4 100644
--- a/unpack/restore_fstree.c
+++ b/unpack/restore_fstree.c
@@ -101,27 +101,7 @@ static int set_xattr(sqfs_xattr_reader_t *xattr, const sqfs_tree_node_t *n)
size_t i;
int ret;
- switch (n->inode->base.type) {
- case SQFS_INODE_EXT_DIR:
- index = n->inode->data.dir_ext.xattr_idx;
- break;
- case SQFS_INODE_EXT_FILE:
- index = n->inode->data.file_ext.xattr_idx;
- break;
- case SQFS_INODE_EXT_SLINK:
- index = n->inode->data.slink_ext.xattr_idx;
- break;
- case SQFS_INODE_EXT_BDEV:
- case SQFS_INODE_EXT_CDEV:
- index = n->inode->data.dev_ext.xattr_idx;
- break;
- case SQFS_INODE_EXT_FIFO:
- case SQFS_INODE_EXT_SOCKET:
- index = n->inode->data.ipc_ext.xattr_idx;
- break;
- default:
- return 0;
- }
+ sqfs_inode_get_xattr_index(n->inode, &index);
if (index == 0xFFFFFFFF)
return 0;