summaryrefslogtreecommitdiff
path: root/mkfs
diff options
context:
space:
mode:
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/mkfs.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index e67b517..acb3202 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -32,6 +32,7 @@ static int pack_files(data_writer_t *data, fstree_t *fs, options_t *opt)
{
sqfs_inode_generic_t *inode;
size_t max_blk_count;
+ uint64_t filesize;
sqfs_file_t *file;
file_info_t *fi;
int ret;
@@ -43,31 +44,34 @@ static int pack_files(data_writer_t *data, fstree_t *fs, options_t *opt)
if (!opt->quiet)
printf("packing %s\n", fi->input_file);
- max_blk_count = fi->size / fs->block_size;
- if (fi->size % fs->block_size)
+ file = sqfs_open_file(fi->input_file,
+ SQFS_FILE_OPEN_READ_ONLY);
+ if (file == NULL) {
+ perror(fi->input_file);
+ return -1;
+ }
+
+ filesize = file->get_size(file);
+
+ max_blk_count = filesize / fs->block_size;
+ if (filesize % fs->block_size)
++max_blk_count;
inode = alloc_flex(sizeof(*inode), sizeof(uint32_t),
max_blk_count);
if (inode == NULL) {
perror("creating file inode");
+ file->destroy(file);
return -1;
}
inode->block_sizes = (uint32_t *)inode->extra;
inode->base.type = SQFS_INODE_FILE;
- sqfs_inode_set_file_size(inode, fi->size);
+ sqfs_inode_set_file_size(inode, filesize);
sqfs_inode_set_frag_location(inode, 0xFFFFFFFF, 0xFFFFFFFF);
fi->user_ptr = inode;
- file = sqfs_open_file(fi->input_file,
- SQFS_FILE_OPEN_READ_ONLY);
- if (file == NULL) {
- perror(fi->input_file);
- return -1;
- }
-
ret = write_data_from_file(data, inode, file, 0);
file->destroy(file);