aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-12 12:08:32 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-12 15:44:14 +0200
commite4dd1ed8c9cea1761092e8206d572f60a9d95a58 (patch)
tree205fdfbb5ce9c9dccd6d822433076cb089e711ca /lib
parenta5428e0b6d430c490a3d7b930f358a5d9057160f (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/fstree/mknode.c13
1 files changed, 9 insertions, 4 deletions
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;