mufs: clean up code for tree management

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent 2a62bd1f15
commit 0ee4779e5c
  1. 16
      source/fs/mufs/tree.c

@ -44,8 +44,7 @@ static int mufs_do_lookup(struct mufs *fs, uint32_t *page,
unsigned alloc)
{
struct flash_dev *dev = fs->dev;
uint32_t entry;
size_t index;
uint32_t offset, entry;
if (!base)
return -1;
@ -55,11 +54,10 @@ static int mufs_do_lookup(struct mufs *fs, uint32_t *page,
return 0;
}
base <<= dev->log2_block_size;
index = mufs_get_index(fs, va, depth);
base += index * sizeof entry;
offset = mufs_get_index(fs, va, depth) * sizeof entry;
offset += base << dev->log2_block_size;
if (flash_read(dev, base, &entry, sizeof entry) == 0)
if (flash_read(dev, offset, &entry, sizeof entry) == 0)
return -1;
if (!entry) {
@ -71,7 +69,7 @@ static int mufs_do_lookup(struct mufs *fs, uint32_t *page,
}
}
if (flash_write(dev, base, &entry, sizeof entry) == 0)
if (flash_write(dev, offset, &entry, sizeof entry) == 0)
return -1;
if (flash_sync(dev) < 0)
@ -92,7 +90,7 @@ int mufs_map_page(struct mufs_tree *tree, uint32_t va, uint32_t page)
{
struct mufs *fs = tree->fs;
if (!tree->root && mufs_alloc_block(fs, &tree->root) < 0)
if (tree->root == 0 && mufs_alloc_block(fs, &tree->root) < 0)
return -1;
return mufs_do_lookup(fs, &page, tree->root, tree->depth, va, page, 1);
@ -103,7 +101,7 @@ int mufs_alloc_page(struct mufs_tree *tree, uint32_t *page,
{
struct mufs *fs = tree->fs;
if (!tree->root && mufs_alloc_block(fs, &tree->root) < 0)
if (tree->root == 0 && mufs_alloc_block(fs, &tree->root) < 0)
return -1;
return mufs_do_lookup(fs, page, tree->root, tree->depth, va, 0, 1);

Loading…
Cancel
Save