mufs: calculate log2_nentries during mount

tags/0.1.0
S.J.R. van Schaik 8 years ago
parent b634e3c715
commit 9480a91ecc
  1. 3
      include/fs/mufs.h
  2. 2
      source/fs/mufs/super.c
  3. 15
      source/fs/mufs/tree.c

@ -9,9 +9,10 @@ struct mufs_tree {
};
struct mufs {
struct mufs_tree root;
struct flash_dev *dev;
uint32_t nblocks;
struct mufs_tree root;
uint8_t log2_nentries;
};
int mufs_mount(struct mufs *fs, struct flash_dev *dev);

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <bitops.h>
#include <flash.h>
#include <fs/mufs.h>
@ -29,6 +30,7 @@ int mufs_mount(struct mufs *fs, struct flash_dev *dev)
fs->dev = dev;
fs->nblocks = super.nblocks;
fs->log2_nentries = fs->dev->log2_block_size - ilog2(sizeof(uint32_t));
fs->root.file_size = super.file_size;
fs->root.root = super.root;

@ -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;
}

Loading…
Cancel
Save