mufs: implement mufs_rmpath() to remove file system nodes
This commit is contained in:
parent
1d52ca46a6
commit
eb9b4853c0
2 changed files with 36 additions and 0 deletions
|
@ -67,6 +67,41 @@ int mufs_mkpath(struct mufs *fs, const char *path, unsigned type)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int mufs_rmpath(struct mufs *fs, const char *path, unsigned type)
|
||||
{
|
||||
struct flash_dev *dev = fs->dev;
|
||||
char data[1 << dev->log2_block_size];
|
||||
struct mufs_dentry *entry;
|
||||
struct mufs_tree *tree;
|
||||
char *s;
|
||||
uint32_t va, offset, len;
|
||||
|
||||
if (!(s = mufs_abspath(path)))
|
||||
return -1;
|
||||
|
||||
if (!(tree = resolve_path(fs, s, NULL))) {
|
||||
free(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
offset = tree->va & ((UINT32_C(1) << dev->log2_block_size) - 1);
|
||||
va = align(tree->va, dev->log2_block_size);
|
||||
|
||||
if (mufs_tree_read(tree, data, va, 1 << dev->log2_block_size) == 0)
|
||||
return -1;
|
||||
|
||||
entry = (struct mufs_dentry *)(data + offset);
|
||||
len = sizeof *entry + entry->path_len;
|
||||
|
||||
memmove(data + offset, data + offset + len,
|
||||
(UINT32_C(1) << dev->log2_block_size) - offset - len);
|
||||
|
||||
if (mufs_tree_write(tree, data, va, 1 << dev->log2_block_size) == 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mufs_stat(struct mufs *fs, const char *path, struct mufs_stat *stat)
|
||||
{
|
||||
if (!resolve_path(fs, path, stat))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
int mufs_mkpath(struct mufs *fs, const char *path, unsigned type);
|
||||
int mufs_rmpath(struct mufs *fs, const char *path, unsigned type);
|
||||
|
|
Loading…
Add table
Reference in a new issue