From 17f4f90d640f43d64e5dbbe07cd16eff9dc2775e Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Mon, 12 Jun 2017 14:32:48 +0200 Subject: [PATCH] mufs: fix issue in tree allocation --- source/fs/mufs/tree.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/source/fs/mufs/tree.c b/source/fs/mufs/tree.c index 2a3927a..7d8ebb5 100644 --- a/source/fs/mufs/tree.c +++ b/source/fs/mufs/tree.c @@ -36,11 +36,13 @@ static int mufs_do_lookup(struct mufs *fs, uint32_t *page, index = va & ((1 << ((depth - 1) * fs->log2_nentries)) - 1); if (!table[index]) { - if (depth > 1 && alloc && mufs_alloc_block(fs, &table[index]) < 0) - return -1; - - if (depth == 1 && new_page) - table[index] = new_page; + if (alloc) { + if (depth == 1 && new_page) { + table[index] = new_page; + } else if (mufs_alloc_block(fs, &table[index]) < 0) { + return -1; + } + } if (flash_write(dev, base << dev->log2_block_size, data, sizeof data) == 0) @@ -72,10 +74,10 @@ int mufs_alloc_page(struct mufs_tree *tree, uint32_t *page, { struct mufs *fs = tree->fs; - if (mufs_alloc_block(fs, page) < 0) + if (!tree->root && mufs_alloc_block(fs, &tree->root) < 0) return -1; - return mufs_map_page(tree, va, *page); + return mufs_do_lookup(fs, page, tree->root, tree->depth, va, 0, 1); } static int mufs_do_free_page(struct mufs *fs, uint32_t base,