|
|
|
@ -14,7 +14,6 @@ static int mufs_do_lookup(struct mufs *fs, uint32_t *page, |
|
|
|
|
char data[1 << fs->dev->log2_block_size]; |
|
|
|
|
uint32_t *table = (uint32_t *)data; |
|
|
|
|
size_t index; |
|
|
|
|
uint8_t log2_nentries = fs->dev->log2_block_size - ilog2(sizeof(uint32_t)); |
|
|
|
|
|
|
|
|
|
if (!base) |
|
|
|
|
return -1; |
|
|
|
@ -28,7 +27,7 @@ static int mufs_do_lookup(struct mufs *fs, uint32_t *page, |
|
|
|
|
sizeof data) == 0) |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
index = va & ((1 << (log2_nentries * (depth - 1))) - 1); |
|
|
|
|
index = va & ((1 << ((depth - 1) * fs->log2_nentries)) - 1); |
|
|
|
|
|
|
|
|
|
if (!table[index]) { |
|
|
|
|
if (!alloc || mufs_alloc_block(fs, &table[index]) < 0) |
|
|
|
@ -56,7 +55,6 @@ static int mufs_do_free_page(struct mufs *fs, uint32_t base, |
|
|
|
|
char data[1 << fs->dev->log2_block_size]; |
|
|
|
|
uint32_t *table = (uint32_t *)data; |
|
|
|
|
size_t index; |
|
|
|
|
uint8_t log2_nentries = fs->dev->log2_block_size - ilog2(sizeof(uint32_t)); |
|
|
|
|
|
|
|
|
|
if (!base) |
|
|
|
|
return -1; |
|
|
|
@ -70,14 +68,14 @@ static int mufs_do_free_page(struct mufs *fs, uint32_t base, |
|
|
|
|
sizeof data) == 0) |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
index = va & ((1 << (log2_nentries * (depth - 1))) - 1); |
|
|
|
|
index = va & ((1 << (fs->log2_nentries * (depth - 1))) - 1); |
|
|
|
|
|
|
|
|
|
if (mufs_do_free_page(fs, table[index], depth - 1, va) < 0) |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
table[index] = 0; |
|
|
|
|
|
|
|
|
|
for (index = 0; index < (UINT32_C(1) << log2_nentries); ++index) { |
|
|
|
|
for (index = 0; index < (UINT32_C(1) << fs->log2_nentries); ++index) { |
|
|
|
|
if (!table[index]) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
@ -123,18 +121,17 @@ int mufs_shrink_tree(struct mufs *fs, struct mufs_tree *tree, uint32_t max_size) |
|
|
|
|
uint32_t *table = (uint32_t *)data; |
|
|
|
|
size_t index; |
|
|
|
|
uint32_t base, size; |
|
|
|
|
uint8_t log2_nentries = fs->dev->log2_block_size - ilog2(sizeof(uint32_t)); |
|
|
|
|
uint8_t depth; |
|
|
|
|
|
|
|
|
|
base = tree->root; |
|
|
|
|
|
|
|
|
|
for (depth = tree->depth; depth; --depth) { |
|
|
|
|
size = 1 << (depth * log2_nentries + fs->dev->log2_block_size); |
|
|
|
|
size = 1 << (depth * fs->log2_nentries + fs->dev->log2_block_size); |
|
|
|
|
|
|
|
|
|
if (size < max_size) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
index = max_size >> ((depth - 1) * log2_nentries + |
|
|
|
|
index = max_size >> ((depth - 1) * fs->log2_nentries + |
|
|
|
|
fs->dev->log2_block_size); |
|
|
|
|
|
|
|
|
|
if (flash_read(fs->dev, base, data, sizeof data) == 0) |
|
|
|
@ -149,7 +146,7 @@ int mufs_shrink_tree(struct mufs *fs, struct mufs_tree *tree, uint32_t max_size) |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (; index < (UINT32_C(1) << log2_nentries); ++index) { |
|
|
|
|
for (; index < (UINT32_C(1) << fs->log2_nentries); ++index) { |
|
|
|
|
table[index] = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|