summaryrefslogtreecommitdiff
path: root/mkfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-23 15:26:02 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-23 15:38:48 +0100
commitc2a093c9e9fb4889a11982797d75b8608c26da8f (patch)
tree613afb06c5eda3dba01c898ce073fcc81731eba2 /mkfs
parentc924d87a4cbbeb93825f34f997add1ca4573a368 (diff)
Turn file inode management completely over to the block processor
If the block processor allocates and dynamically resizes inodes on the fly, we can add data indefinitely without knowing the size of the file ahead of time. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/mkfs.c35
1 files changed, 5 insertions, 30 deletions
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index 691c754..0ef65ca 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -42,15 +42,13 @@ static int set_working_dir(options_t *opt)
static int pack_files(sqfs_block_processor_t *data, fstree_t *fs,
options_t *opt)
{
- sqfs_inode_generic_t *inode;
- size_t max_blk_count;
+ sqfs_inode_generic_t **inode_ptr;
sqfs_u64 filesize;
sqfs_file_t *file;
tree_node_t *node;
const char *path;
char *node_path;
file_info_t *fi;
- size_t size;
int flags;
int ret;
@@ -86,38 +84,15 @@ static int pack_files(sqfs_block_processor_t *data, fstree_t *fs,
return -1;
}
- filesize = file->get_size(file);
-
- max_blk_count = filesize / opt->cfg.block_size;
- if (filesize % opt->cfg.block_size)
- ++max_blk_count;
-
- if (SZ_MUL_OV(sizeof(sqfs_u32), max_blk_count, &size) ||
- SZ_ADD_OV(sizeof(*inode), size, &size)) {
- fputs("creating file inode: too many blocks\n",
- stderr);
- sqfs_destroy(file);
- free(node_path);
- return -1;
- }
-
- inode = calloc(1, size);
- if (inode == NULL) {
- perror("creating file inode");
- sqfs_destroy(file);
- free(node_path);
- return -1;
- }
-
- inode->base.type = SQFS_INODE_FILE;
- fi->user_ptr = inode;
-
flags = 0;
+ filesize = file->get_size(file);
if (opt->no_tail_packing && filesize > opt->cfg.block_size)
flags |= SQFS_BLK_DONT_FRAGMENT;
- ret = write_data_from_file(path, data, inode, file, flags);
+ inode_ptr = (sqfs_inode_generic_t **)&fi->user_ptr;
+
+ ret = write_data_from_file(path, data, inode_ptr, file, flags);
sqfs_destroy(file);
free(node_path);