From e4dd1ed8c9cea1761092e8206d572f60a9d95a58 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 12 Jul 2019 12:08:32 +0200 Subject: fstree: mknode: initialize fragment data, add extra blocksize slot This commit makes sure that regular file tree nodes have one more slot than necessary to support files that don't have fragments. Also, it initializes the fragment data, which should help to deduplicate some code ahead. Signed-off-by: David Oberhollenzer --- lib/fstree/mknode.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/fstree/mknode.c b/lib/fstree/mknode.c index e4620f5..4b4cdfd 100644 --- a/lib/fstree/mknode.c +++ b/lib/fstree/mknode.c @@ -8,7 +8,7 @@ tree_node_t *fstree_mknode(fstree_t *fs, 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); + size_t size = sizeof(tree_node_t), block_count = 0; tree_node_t *n; char *ptr; @@ -20,8 +20,11 @@ tree_node_t *fstree_mknode(fstree_t *fs, tree_node_t *parent, const char *name, size += sizeof(*n->data.dir); break; case S_IFREG: - size += sizeof(*n->data.file); - size += (sb->st_size / fs->block_size) * sizeof(uint32_t); + block_count = (sb->st_size / fs->block_size); + if ((sb->st_size % fs->block_size) != 0) + ++block_count; + + size += sizeof(*n->data.file) + block_count * sizeof(uint32_t); if (extra != NULL) size += strlen(extra) + 1; break; @@ -48,11 +51,13 @@ tree_node_t *fstree_mknode(fstree_t *fs, tree_node_t *parent, const char *name, 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->blocksizes; - ptr += (sb->st_size / fs->block_size) * sizeof(uint32_t); + ptr += block_count * sizeof(uint32_t); n->data.file->input_file = ptr; strcpy(n->data.file->input_file, extra); break; -- cgit v1.2.3