mufs: add mufs_extend_tree() to extend the depth of a file tree
This commit is contained in:
parent
c5c24788c8
commit
281c1abdfa
2 changed files with 22 additions and 0 deletions
|
@ -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…
Add table
Reference in a new issue