mufs: fix issue in tree allocation

tags/0.1.0
S.J.R. van Schaik 8 years ago
parent eb9b4853c0
commit 17f4f90d64
  1. 16
      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,

Loading…
Cancel
Save