summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-26 22:06:04 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-28 16:33:57 +0200
commit8b633067948a30a0d45091afcced0392dd28d105 (patch)
treed3cfdd43132da1cee604bd18b3569bd19ba8fdd8
parent0f1bedc90f4cb71d965e99446cf3e72a45909346 (diff)
Add fragment and block checksum fields to file_info_t
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/fstree.h12
-rw-r--r--lib/fstree/mknode.c7
-rw-r--r--lib/sqfs/data_reader.c2
-rw-r--r--lib/sqfs/data_writer.c4
-rw-r--r--lib/sqfs/tree_node_from_inode.c12
-rw-r--r--lib/sqfs/write_inode.c2
-rw-r--r--tests/mknode_reg.c2
7 files changed, 23 insertions, 18 deletions
diff --git a/include/fstree.h b/include/fstree.h
index eb7b65f..23634fc 100644
--- a/include/fstree.h
+++ b/include/fstree.h
@@ -78,9 +78,15 @@ struct file_info_t {
/* Byte offset into the fragment block. */
uint32_t fragment_offset;
- /* For each full data block, stores the compressed size.
- Bit (1 << 24) is set if the block is stored uncompressed. */
- uint32_t blocksizes[];
+ uint32_t fragment_chksum;
+
+ /* Stores data about each full data block. */
+ struct {
+ uint32_t chksum;
+
+ /* Bit (1 << 24) is set if the block is stored uncompressed. */
+ uint32_t size;
+ } blocks[];
};
/* Additional meta data stored in a tree_node_t for directories */
diff --git a/lib/fstree/mknode.c b/lib/fstree/mknode.c
index c6572fe..18602e4 100644
--- a/lib/fstree/mknode.c
+++ b/lib/fstree/mknode.c
@@ -31,7 +31,8 @@ tree_node_t *fstree_mknode(fstree_t *fs, tree_node_t *parent, const char *name,
if ((sb->st_size % fs->block_size) != 0)
++block_count;
- size += sizeof(*n->data.file) + block_count * sizeof(uint32_t);
+ size += sizeof(*n->data.file);
+ size += block_count * sizeof(n->data.file->blocks[0]);
if (extra != NULL)
size += strlen(extra) + 1;
break;
@@ -64,8 +65,8 @@ tree_node_t *fstree_mknode(fstree_t *fs, tree_node_t *parent, const char *name,
if (extra == NULL)
break;
- ptr = (char *)n->data.file->blocksizes;
- ptr += block_count * sizeof(uint32_t);
+ ptr = (char *)n->data.file->blocks;
+ ptr += block_count * sizeof(n->data.file->blocks[0]);
n->data.file->input_file = ptr;
strcpy(n->data.file->input_file, extra);
break;
diff --git a/lib/sqfs/data_reader.c b/lib/sqfs/data_reader.c
index 0e2e7ac..5facaa1 100644
--- a/lib/sqfs/data_reader.c
+++ b/lib/sqfs/data_reader.c
@@ -92,7 +92,7 @@ static int dump_blocks(data_reader_t *data, file_info_t *fi, int outfd,
void *ptr;
for (i = 0; i < count; ++i) {
- bs = fi->blocksizes[i];
+ bs = fi->blocks[i].size;
compressed = (bs & (1 << 24)) == 0;
bs &= (1 << 24) - 1;
diff --git a/lib/sqfs/data_writer.c b/lib/sqfs/data_writer.c
index ae8257c..aff296e 100644
--- a/lib/sqfs/data_writer.c
+++ b/lib/sqfs/data_writer.c
@@ -131,7 +131,7 @@ static int flush_data_block(data_writer_t *data, size_t size,
uint32_t out;
if (is_zero_block(data->block, size)) {
- fi->blocksizes[data->block_idx++] = 0;
+ fi->blocks[data->block_idx++].size = 0;
fi->sparse += size;
return 0;
}
@@ -152,7 +152,7 @@ static int flush_data_block(data_writer_t *data, size_t size,
if (write_compressed(data, data->block, size, &out, flags))
return -1;
- fi->blocksizes[data->block_idx++] = out;
+ fi->blocks[data->block_idx++].size = out;
}
return 0;
diff --git a/lib/sqfs/tree_node_from_inode.c b/lib/sqfs/tree_node_from_inode.c
index f35c046..034218c 100644
--- a/lib/sqfs/tree_node_from_inode.c
+++ b/lib/sqfs/tree_node_from_inode.c
@@ -38,13 +38,13 @@ static size_t compute_size(sqfs_inode_generic_t *inode, const char *name,
break;
}
- return size + block_count * sizeof(uint32_t);
+ return size + block_count * sizeof(((file_info_t *)0)->blocks[0]);
}
static void copy_block_sizes(sqfs_inode_generic_t *inode, tree_node_t *out,
size_t block_size)
{
- size_t block_count = out->data.file->size / block_size;
+ size_t i, block_count = out->data.file->size / block_size;
if ((out->data.file->size % block_size) != 0) {
if (out->data.file->fragment == 0xFFFFFFFF ||
@@ -53,12 +53,10 @@ static void copy_block_sizes(sqfs_inode_generic_t *inode, tree_node_t *out,
}
}
- out->name += block_count * sizeof(uint32_t);
+ out->name += block_count * sizeof(out->data.file->blocks[0]);
- if (block_count) {
- memcpy(out->data.file->blocksizes, inode->block_sizes,
- block_count * sizeof(uint32_t));
- }
+ for (i = 0; i < block_count; ++i)
+ out->data.file->blocks[i].size = inode->block_sizes[i];
}
tree_node_t *tree_node_from_inode(sqfs_inode_generic_t *inode,
diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c
index 7cef7a7..726206e 100644
--- a/lib/sqfs/write_inode.c
+++ b/lib/sqfs/write_inode.c
@@ -88,7 +88,7 @@ static int write_file_blocks(fstree_t *fs, file_info_t *fi, meta_writer_t *im)
}
for (i = 0; i < count; ++i) {
- bs = htole32(fi->blocksizes[i]);
+ bs = htole32(fi->blocks[i].size);
if (meta_writer_append(im, &bs, sizeof(bs)))
return -1;
diff --git a/tests/mknode_reg.c b/tests/mknode_reg.c
index b6b1a0b..7b9f961 100644
--- a/tests/mknode_reg.c
+++ b/tests/mknode_reg.c
@@ -31,7 +31,7 @@ int main(void)
assert((char *)node->name >= (char *)node->payload);
assert((char *)node->data.file >= (char *)node->payload);
assert(node->data.file->input_file > (char *)(node->data.file + 1) +
- sizeof(uint32_t) * 4);
+ sizeof(node->data.file->blocks[0]) * 4);
assert(node->name >= node->data.file->input_file + 6);
assert(strcmp(node->name, "filename") == 0);
assert(strcmp(node->data.file->input_file, "input") == 0);