mufs: reduce memory footprint of mufs_shrink_tree()
This commit is contained in:
parent
4ef4aa7036
commit
58c93eecf4
1 changed files with 7 additions and 11 deletions
|
@ -181,8 +181,6 @@ int mufs_shrink_tree(struct mufs_tree *tree, uint32_t max_size)
|
||||||
{
|
{
|
||||||
struct mufs *fs = tree->fs;
|
struct mufs *fs = tree->fs;
|
||||||
struct flash_dev *dev = fs->dev;
|
struct flash_dev *dev = fs->dev;
|
||||||
char data[1 << dev->log2_block_size];
|
|
||||||
uint32_t *table = (uint32_t *)data;
|
|
||||||
size_t index;
|
size_t index;
|
||||||
uint32_t base, size;
|
uint32_t base, size;
|
||||||
uint8_t depth;
|
uint8_t depth;
|
||||||
|
@ -198,11 +196,10 @@ int mufs_shrink_tree(struct mufs_tree *tree, uint32_t max_size)
|
||||||
index = max_size >> ((depth - 1) * fs->log2_nentries +
|
index = max_size >> ((depth - 1) * fs->log2_nentries +
|
||||||
dev->log2_block_size);
|
dev->log2_block_size);
|
||||||
|
|
||||||
if (flash_read(dev, base, data, sizeof data) == 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (index <= 1) {
|
if (index <= 1) {
|
||||||
tree->root = table[0];
|
if (flash_read(dev, base, &tree->root, sizeof tree->root) == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
--tree->depth;
|
--tree->depth;
|
||||||
|
|
||||||
mufs_free_block(fs, base);
|
mufs_free_block(fs, base);
|
||||||
|
@ -210,12 +207,11 @@ int mufs_shrink_tree(struct mufs_tree *tree, uint32_t max_size)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; index < (UINT32_C(1) << fs->log2_nentries); ++index) {
|
if (flash_write0(dev, base + index * sizeof(uint32_t), (UINT32_C(1) <<
|
||||||
table[index] = 0;
|
dev->log2_block_size) - index * sizeof(uint32_t)) == 0)
|
||||||
}
|
return -1;
|
||||||
|
|
||||||
if (flash_write(dev, base << dev->log2_block_size, data,
|
if (flash_sync(dev) < 0)
|
||||||
sizeof data) == 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue