mufs: remove the page if there is only one entry left in mufs_rmpath()
This commit is contained in:
parent
17f4f90d64
commit
e837c07869
1 changed files with 29 additions and 1 deletions
|
@ -67,11 +67,34 @@ int mufs_mkpath(struct mufs *fs, const char *path, unsigned type)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int remove_page(struct mufs_tree *tree, uint32_t va)
|
||||
{
|
||||
struct mufs *fs = tree->fs;
|
||||
struct flash_dev *dev = fs->dev;
|
||||
uint32_t last_va, page;
|
||||
|
||||
last_va = align(tree->file_size - 1, dev->log2_block_size);
|
||||
|
||||
if (mufs_lookup_page(tree, &page, last_va) < 0)
|
||||
return -1;
|
||||
|
||||
mufs_free_page(tree, va);
|
||||
|
||||
if (va != last_va) {
|
||||
mufs_unmap_page(tree, last_va);
|
||||
mufs_map_page(tree, va, page);
|
||||
}
|
||||
|
||||
tree->file_size -= (UINT32_C(1) << dev->log2_block_size);
|
||||
|
||||
return mufs_sync_tree(tree);
|
||||
}
|
||||
|
||||
int mufs_rmpath(struct mufs *fs, const char *path, unsigned type)
|
||||
{
|
||||
struct flash_dev *dev = fs->dev;
|
||||
char data[1 << dev->log2_block_size];
|
||||
struct mufs_dentry *entry;
|
||||
struct mufs_dentry *entry, *next;
|
||||
struct mufs_tree *tree;
|
||||
char *s;
|
||||
uint32_t va, offset, len;
|
||||
|
@ -92,6 +115,11 @@ int mufs_rmpath(struct mufs *fs, const char *path, unsigned type)
|
|||
|
||||
entry = (struct mufs_dentry *)(data + offset);
|
||||
len = sizeof *entry + entry->path_len;
|
||||
next = (struct mufs_dentry *)(data + offset + len);
|
||||
|
||||
if (!offset && (len == (UINT32_C(1) << dev->log2_block_size) ||
|
||||
!next->type))
|
||||
return remove_page(tree, va);
|
||||
|
||||
memmove(data + offset, data + offset + len,
|
||||
(UINT32_C(1) << dev->log2_block_size) - offset - len);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue