mufs: add mufs_write() to write data using a file tree
This commit is contained in:
parent
233d991328
commit
a7d71e84cf
2 changed files with 37 additions and 0 deletions
|
@ -195,3 +195,38 @@ size_t mufs_read(struct mufs *fs, struct mufs_tree *tree, void *data,
|
|||
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
static size_t mufs_do_write(struct mufs *fs, struct mufs_tree *tree,
|
||||
void *data, uint32_t va, size_t len)
|
||||
{
|
||||
uint32_t page, offset;
|
||||
|
||||
offset = va & ((UINT32_C(1) << fs->dev->log2_block_size) - 1);
|
||||
va = align(va, fs->dev->log2_block_size);
|
||||
|
||||
memset(data, 0, len);
|
||||
len = min(len, (UINT32_C(1) << fs->dev->log2_block_size) - offset);
|
||||
|
||||
if (mufs_alloc_page(fs, tree, &page, va) < 0)
|
||||
return 0;
|
||||
|
||||
return flash_write(fs->dev, page, data, len);
|
||||
}
|
||||
|
||||
size_t mufs_write(struct mufs *fs, struct mufs_tree *tree, void *data,
|
||||
uint32_t va, size_t len)
|
||||
{
|
||||
uint8_t *buf = data;
|
||||
size_t ret, nbytes = 0;
|
||||
|
||||
while (len) {
|
||||
if ((ret = mufs_do_write(fs, tree, buf, va, len)) == 0)
|
||||
return nbytes;
|
||||
|
||||
buf += ret;
|
||||
va += ret;
|
||||
len -= ret;
|
||||
}
|
||||
|
||||
return nbytes;
|
||||
}
|
||||
|
|
|
@ -9,3 +9,5 @@ int mufs_extend_tree(struct mufs *fs, struct mufs_tree *tree, uint8_t depth);
|
|||
int mufs_shrink_tree(struct mufs *fs, struct mufs_tree *tree, uint32_t max_size);
|
||||
size_t mufs_read(struct mufs *fs, struct mufs_tree *tree, void *data,
|
||||
uint32_t va, size_t len);
|
||||
size_t mufs_write(struct mufs *fs, struct mufs_tree *tree, void *data,
|
||||
uint32_t va, size_t len);
|
||||
|
|
Loading…
Add table
Reference in a new issue