summaryrefslogtreecommitdiff
path: root/unpack/rdsquashfs.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-04 23:20:28 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-04 23:20:28 +0200
commita2750dee0e4c374ae51f83eead7eb7df3c018d95 (patch)
treeeb02eafaecd5a966d216cb2d97b272ab2731f121 /unpack/rdsquashfs.c
parent09bdcdb1f3f2d7810ea956842bc7551d9ca26f92 (diff)
rdsquashfs: malloc extraction buffers ahead of time
Instead of malloc/freeing the buffers for every file, allocate them once, ahead of time. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack/rdsquashfs.c')
-rw-r--r--unpack/rdsquashfs.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/unpack/rdsquashfs.c b/unpack/rdsquashfs.c
index 3c80853..c286a78 100644
--- a/unpack/rdsquashfs.c
+++ b/unpack/rdsquashfs.c
@@ -110,6 +110,23 @@ static char *get_path(char *old, const char *arg)
return path;
}
+static int alloc_buffers(unsqfs_info_t *info, sqfs_super_t *super)
+{
+ info->buffer = malloc(super->block_size);
+ if (info->buffer == NULL) {
+ perror("allocating block buffer");
+ return -1;
+ }
+
+ info->scratch = malloc(super->block_size);
+ if (info->scratch == NULL) {
+ perror("allocating scrtach buffer for extracting blocks");
+ return -1;
+ }
+
+ return 0;
+}
+
static int load_fragment_table(unsqfs_info_t *info, sqfs_super_t *super)
{
if (super->fragment_entry_count == 0)
@@ -274,6 +291,9 @@ int main(int argc, char **argv)
if (load_fragment_table(&info, &super))
goto out_fs;
+ if (alloc_buffers(&info, &super))
+ goto out_fs;
+
if (extract_file(n->data.file, &info, STDOUT_FILENO))
goto out_fs;
break;
@@ -291,6 +311,9 @@ int main(int argc, char **argv)
if (load_fragment_table(&info, &super))
goto out_fs;
+ if (alloc_buffers(&info, &super))
+ goto out_fs;
+
if (restore_fstree(unpack_root, n, &info))
goto out_fs;
break;
@@ -307,6 +330,8 @@ out_fd:
close(info.sqfsfd);
out_cmd:
free(cmdpath);
+ free(info.buffer);
+ free(info.scratch);
return status;
fail_arg:
fprintf(stderr, "Try `%s --help' for more information.\n", __progname);