mufs: add find_dirent_size() to determine how many bytes are used within a directory bin
This commit is contained in:
parent
7107daa4b5
commit
f2d4d60c01
3 changed files with 37 additions and 0 deletions
|
@ -182,6 +182,39 @@ void mufs_closedir(struct mufs_dir *dir)
|
|||
free(dir);
|
||||
}
|
||||
|
||||
size_t find_dirent_size(struct mufs *fs, struct mufs_tree *tree,
|
||||
uint32_t va)
|
||||
{
|
||||
struct flash_dev *dev = fs->dev;
|
||||
size_t block_size = 1 << dev->log2_block_size;
|
||||
char data[block_size];
|
||||
struct mufs_dentry *entry;
|
||||
uint32_t offset, len;
|
||||
|
||||
va = align(va, dev->log2_block_size);
|
||||
|
||||
if (mufs_tree_read(tree, data, va, 1 << dev->log2_block_size) == 0)
|
||||
return 0;
|
||||
|
||||
for (offset = 0; offset < block_size; offset += len) {
|
||||
entry = (struct mufs_dentry *)(data + offset);
|
||||
len = sizeof *entry;
|
||||
|
||||
if (block_size - offset < len)
|
||||
break;
|
||||
|
||||
if (!entry->type)
|
||||
break;
|
||||
|
||||
len += entry->path_len;
|
||||
|
||||
if (block_size - offset < len)
|
||||
break;
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
size_t read_dirent(struct mufs *fs, struct mufs_tree *tree,
|
||||
struct mufs_dirent *dirent, uint32_t va)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,8 @@ struct mufs_dentry {
|
|||
|
||||
struct mufs_tree *resolve_path(struct mufs *fs, const char *path,
|
||||
struct mufs_stat *stat);
|
||||
size_t find_dirent_size(struct mufs *fs, struct mufs_tree *tree,
|
||||
uint32_t va);
|
||||
size_t read_dirent(struct mufs *fs, struct mufs_tree *tree,
|
||||
struct mufs_dirent *dirent, uint32_t va);
|
||||
size_t write_dirent(struct mufs_tree *tree,
|
||||
|
|
|
@ -53,6 +53,8 @@ int mufs_mkpath(struct mufs *fs, const char *path, unsigned type)
|
|||
dirent.tree.root = 0;
|
||||
dirent.tree.depth = 0;
|
||||
|
||||
tree->file_size = find_dirent_size(fs, tree, tree->file_size);
|
||||
|
||||
if (!is_aligned(tree->file_size, fs->dev->log2_block_size) &&
|
||||
write_dirent(tree, tree->file_size, &dirent) > 0)
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue