mufs: add mufs_extend_tree() to extend the depth of a file tree

tags/0.1.0
S.J.R. van Schaik 8 years ago
parent c5c24788c8
commit 281c1abdfa
  1. 21
      source/fs/mufs/tree.c
  2. 1
      source/fs/mufs/tree.h

@ -95,3 +95,24 @@ void mufs_free_page(struct mufs *fs, struct mufs_tree *tree, uint32_t va)
{
mufs_do_free_page(fs, tree->root, tree->depth, va);
}
int mufs_extend_tree(struct mufs *fs, struct mufs_tree *tree, uint8_t depth)
{
uint32_t root;
for (; tree->depth < depth; ++tree->depth) {
if (mufs_alloc_block(fs, &root) < 0)
return -1;
if (!root)
continue;
if (flash_write(fs->dev, root << fs->dev->log2_block_size, &tree->root,
sizeof tree->root) == 0) {
mufs_free_block(fs, root);
return -1;
}
}
return 0;
}

@ -5,3 +5,4 @@ int mufs_lookup_page(struct mufs *fs, struct mufs_tree *tree, uint32_t *page,
int mufs_alloc_page(struct mufs *fs, struct mufs_tree *tree, uint32_t *page,
uint32_t va);
void mufs_free_page(struct mufs *fs, struct mufs_tree *tree, uint32_t va);
int mufs_extend_tree(struct mufs *fs, struct mufs_tree *tree, uint8_t depth);

Loading…
Cancel
Save