summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/fstree.h21
-rw-r--r--lib/fstree/add_by_path.c4
-rw-r--r--lib/fstree/fstree.c2
-rw-r--r--lib/fstree/fstree_from_dir.c2
-rw-r--r--lib/fstree/mknode.c32
-rw-r--r--mkfs/mkfs.c24
-rw-r--r--tar/tar2sqfs.c14
7 files changed, 34 insertions, 65 deletions
diff --git a/include/fstree.h b/include/fstree.h
index 85e2258..c9ff574 100644
--- a/include/fstree.h
+++ b/include/fstree.h
@@ -76,26 +76,7 @@ struct file_info_t {
/* Path to the input file. */
char *input_file;
- uint64_t size;
-
void *user_ptr;
-
- /* Number of bytes not written to disk because they are 0 */
- uint64_t sparse;
-
- /* Absolute position of the first data block. */
- uint64_t startblock;
-
- /* If the size is not a multiple of the block size, this holds an
- index into the fragment table. */
- uint32_t fragment;
-
- /* Byte offset into the fragment block. */
- uint32_t fragment_offset;
-
- /* Stores data about each full data block. */
- /* Bit (1 << 24) is set if the block is stored uncompressed. */
- uint32_t block_size[];
};
/* Additional meta data stored in a tree_node_t for directories */
@@ -199,7 +180,7 @@ void fstree_cleanup(fstree_t *fs);
The resulting node can be freed with a single free() call.
*/
-tree_node_t *fstree_mknode(fstree_t *fs, tree_node_t *parent, const char *name,
+tree_node_t *fstree_mknode(tree_node_t *parent, const char *name,
size_t name_len, const char *extra,
const struct stat *sb);
diff --git a/lib/fstree/add_by_path.c b/lib/fstree/add_by_path.c
index fbc2ce7..87fa6ff 100644
--- a/lib/fstree/add_by_path.c
+++ b/lib/fstree/add_by_path.c
@@ -45,7 +45,7 @@ static tree_node_t *get_parent_node(fstree_t *fs, tree_node_t *root,
n = child_by_name(root, path, end - path);
if (n == NULL) {
- n = fstree_mknode(fs, root, path, end - path, NULL,
+ n = fstree_mknode(root, path, end - path, NULL,
&fs->defaults);
if (n == NULL)
return NULL;
@@ -89,5 +89,5 @@ tree_node_t *fstree_add_generic(fstree_t *fs, const char *path,
return child;
}
- return fstree_mknode(fs, parent, name, strlen(name), extra, sb);
+ return fstree_mknode(parent, name, strlen(name), extra, sb);
}
diff --git a/lib/fstree/fstree.c b/lib/fstree/fstree.c
index 6955c17..febf8af 100644
--- a/lib/fstree/fstree.c
+++ b/lib/fstree/fstree.c
@@ -125,7 +125,7 @@ int fstree_init(fstree_t *fs, size_t block_size, char *defaults)
return -1;
}
- fs->root = fstree_mknode(fs, NULL, "", 0, NULL, &fs->defaults);
+ fs->root = fstree_mknode(NULL, "", 0, NULL, &fs->defaults);
if (fs->root == NULL) {
perror("initializing file system tree");
diff --git a/lib/fstree/fstree_from_dir.c b/lib/fstree/fstree_from_dir.c
index 9aab5df..86f7fd8 100644
--- a/lib/fstree/fstree_from_dir.c
+++ b/lib/fstree/fstree_from_dir.c
@@ -180,7 +180,7 @@ static int populate_dir(fstree_t *fs, tree_node_t *root, dev_t devstart,
if (!(flags & DIR_SCAN_KEEP_TIME))
sb.st_mtim = fs->defaults.st_mtim;
- n = fstree_mknode(fs, root, ent->d_name, strlen(ent->d_name),
+ n = fstree_mknode(root, ent->d_name, strlen(ent->d_name),
extra, &sb);
if (n == NULL) {
perror("creating tree node");
diff --git a/lib/fstree/mknode.c b/lib/fstree/mknode.c
index ace99f3..19df268 100644
--- a/lib/fstree/mknode.c
+++ b/lib/fstree/mknode.c
@@ -13,11 +13,11 @@
#include <stdlib.h>
#include <errno.h>
-tree_node_t *fstree_mknode(fstree_t *fs, tree_node_t *parent, const char *name,
+tree_node_t *fstree_mknode(tree_node_t *parent, const char *name,
size_t name_len, const char *extra,
const struct stat *sb)
{
- size_t size = sizeof(tree_node_t), block_count = 0, total;
+ size_t size = sizeof(tree_node_t), total;
tree_node_t *n;
char *ptr;
@@ -37,19 +37,8 @@ tree_node_t *fstree_mknode(fstree_t *fs, tree_node_t *parent, const char *name,
goto fail_ov;
break;
case S_IFREG:
- block_count = (sb->st_size / fs->block_size);
- if ((sb->st_size % fs->block_size) != 0)
- ++block_count;
-
- if (SZ_MUL_OV(block_count, sizeof(n->data.file->block_size[0]),
- &total)) {
- goto fail_ov;
- }
-
- if (SZ_ADD_OV(size, sizeof(*n->data.file), &size) ||
- SZ_ADD_OV(size, total, &size)) {
+ if (SZ_ADD_OV(size, sizeof(*n->data.file), &size))
goto fail_ov;
- }
if (extra != NULL) {
if (SZ_ADD_OV(size, strlen(extra), &size) ||
@@ -86,16 +75,11 @@ tree_node_t *fstree_mknode(fstree_t *fs, tree_node_t *parent, const char *name,
break;
case S_IFREG:
n->data.file = (file_info_t *)n->payload;
- n->data.file->size = sb->st_size;
- n->data.file->fragment = 0xFFFFFFFF;
- n->data.file->fragment_offset = 0xFFFFFFFF;
- if (extra == NULL)
- break;
-
- ptr = (char *)n->data.file->block_size;
- ptr += block_count * sizeof(n->data.file->block_size[0]);
- n->data.file->input_file = ptr;
- strcpy(n->data.file->input_file, extra);
+ if (extra != NULL) {
+ ptr = (char *)n->payload + sizeof(file_info_t);
+ n->data.file->input_file = ptr;
+ strcpy(n->data.file->input_file, extra);
+ }
break;
case S_IFLNK:
n->mode = S_IFLNK | 0777;
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);
diff --git a/tar/tar2sqfs.c b/tar/tar2sqfs.c
index 583511f..e62985a 100644
--- a/tar/tar2sqfs.c
+++ b/tar/tar2sqfs.c
@@ -223,7 +223,7 @@ fail_arg:
}
static int write_file(tar_header_decoded_t *hdr, file_info_t *fi,
- data_writer_t *data)
+ data_writer_t *data, uint64_t filesize)
{
const sqfs_sparse_map_t *it;
sqfs_inode_generic_t *inode;
@@ -232,8 +232,8 @@ static int write_file(tar_header_decoded_t *hdr, file_info_t *fi,
uint64_t sum;
int ret;
- max_blk_count = fi->size / block_size;
- if (fi->size % block_size)
+ max_blk_count = filesize / block_size;
+ if (filesize % block_size)
++max_blk_count;
inode = alloc_flex(sizeof(*inode), sizeof(uint32_t), max_blk_count);
@@ -244,7 +244,7 @@ static int write_file(tar_header_decoded_t *hdr, file_info_t *fi,
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;
@@ -268,7 +268,7 @@ static int write_file(tar_header_decoded_t *hdr, file_info_t *fi,
return skip_padding(STDIN_FILENO, hdr->record_size);
}
- file = sqfs_get_stdin_file(fi->size);
+ file = sqfs_get_stdin_file(filesize);
if (file == NULL) {
perror("packing files");
return -1;
@@ -280,7 +280,7 @@ static int write_file(tar_header_decoded_t *hdr, file_info_t *fi,
if (ret)
return -1;
- return skip_padding(STDIN_FILENO, fi->size);
+ return skip_padding(STDIN_FILENO, filesize);
}
static int copy_xattr(fstree_t *fs, tree_node_t *node,
@@ -330,7 +330,7 @@ static int create_node_and_repack_data(tar_header_decoded_t *hdr, fstree_t *fs,
}
if (S_ISREG(hdr->sb.st_mode)) {
- if (write_file(hdr, node->data.file, data))
+ if (write_file(hdr, node->data.file, data, hdr->sb.st_size))
return -1;
}