vfs_delete() implement deleting files

This commit is contained in:
2025-10-15 20:10:00 +02:00
parent a81d4e0c3b
commit 371d777a7c
4 changed files with 32 additions and 4 deletions

View File

@ -117,6 +117,16 @@ int32_t littlefs_mkdir(struct VfsMountPoint *vmp, const char *path) {
return E_OK;
}
int32_t littlefs_delete(struct VfsMountPoint *vmp, const char *path) {
spinlock_acquire(&vmp->spinlock);
int ok = lfs_remove(&vmp->fs.littlefs.instance, path);
spinlock_release(&vmp->spinlock);
if (ok < 0) {
return E_BADIO;
}
return E_OK;
}
struct VfsObj *littlefs_open(struct VfsMountPoint *vmp, const char *path, uint32_t flags) {
VfsObj *vobj = dlmalloc(sizeof(*vobj));
if (vobj == NULL) {

View File

@ -20,6 +20,7 @@ struct VfsObj *littlefs_open(struct VfsMountPoint *vmp, const char *path, uint32
int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, FsStat *statbuf);
int32_t littlefs_fetchdirent(struct VfsMountPoint *vmp, const char *path, FsDirent *direntbuf, size_t idx);
int32_t littlefs_mkdir(struct VfsMountPoint *vmp, const char *path);
int32_t littlefs_delete(struct VfsMountPoint *vmp, const char *path);
int portlfs_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size);
int portlfs_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size);

View File

@ -49,6 +49,7 @@ void vfs_init_littlefs(VfsMountPoint *mp, bool format) {
mp->stat = &littlefs_stat;
mp->fetchdirent = &littlefs_fetchdirent;
mp->mkdir = &littlefs_mkdir;
mp->delete = &littlefs_delete;
}
int32_t vfs_stat(char *mountpoint, const char *path, FsStat *stat) {
@ -93,6 +94,20 @@ int32_t vfs_fetchdirent(char *mountpoint, const char *path, FsDirent *direntbuf,
return mp->fetchdirent(mp, path, direntbuf, idx);
}
int32_t vfs_delete(char *mountpoint, const char *path) {
VfsMountPoint *mp = NULL;
spinlock_acquire(&VFS_TABLE.spinlock);
HSHTB_GET(VFS_TABLE.mountpoints, label, mountpoint, mp);
spinlock_release(&VFS_TABLE.spinlock);
if (mp == NULL) {
return E_NOENTRY;
}
return mp->delete(mp, path);
}
int32_t vfs_mount(char *mountpoint, int32_t fstype, StoreDev *backingsd, bool format) {
VfsMountPoint *mp = NULL;

View File

@ -53,6 +53,7 @@ typedef struct VfsMountPoint {
int32_t (*stat)(struct VfsMountPoint *vmp, const char *path, FsStat *statbuf);
int32_t (*fetchdirent)(struct VfsMountPoint *vmp, const char *path, FsDirent *direntbuf, size_t idx);
int32_t (*mkdir)(struct VfsMountPoint *vmp, const char *path);
int32_t (*delete)(struct VfsMountPoint *vmp, const char *path);
union {
LittleFs littlefs;
@ -75,5 +76,6 @@ VfsObj *vfs_open(char *mountpoint, const char *path, uint32_t flags);
int32_t vfs_stat(char *mountpoint, const char *path, FsStat *stat);
int32_t vfs_fetchdirent(char *mountpoint, const char *path, FsDirent *direntbuf, size_t idx);
int32_t vfs_mkdir(char *mountpoint, const char *path);
int32_t vfs_delete(char *mountpoint, const char *path);
#endif // VFS_VFS_H_