vfs_delete() implement deleting files
This commit is contained in:
@ -117,6 +117,16 @@ int32_t littlefs_mkdir(struct VfsMountPoint *vmp, const char *path) {
|
|||||||
return E_OK;
|
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) {
|
struct VfsObj *littlefs_open(struct VfsMountPoint *vmp, const char *path, uint32_t flags) {
|
||||||
VfsObj *vobj = dlmalloc(sizeof(*vobj));
|
VfsObj *vobj = dlmalloc(sizeof(*vobj));
|
||||||
if (vobj == NULL) {
|
if (vobj == NULL) {
|
||||||
|
|||||||
@ -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_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_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_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_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);
|
int portlfs_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size);
|
||||||
|
|||||||
@ -44,11 +44,12 @@ void vfs_init_littlefs(VfsMountPoint *mp, bool format) {
|
|||||||
ERR("vfs", "Little FS mount failed %d\n", err);
|
ERR("vfs", "Little FS mount failed %d\n", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
mp->cleanup = &littlefs_cleanup;
|
mp->cleanup = &littlefs_cleanup;
|
||||||
mp->open = &littlefs_open;
|
mp->open = &littlefs_open;
|
||||||
mp->stat = &littlefs_stat;
|
mp->stat = &littlefs_stat;
|
||||||
mp->fetchdirent = &littlefs_fetchdirent;
|
mp->fetchdirent = &littlefs_fetchdirent;
|
||||||
mp->mkdir = &littlefs_mkdir;
|
mp->mkdir = &littlefs_mkdir;
|
||||||
|
mp->delete = &littlefs_delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vfs_stat(char *mountpoint, const char *path, FsStat *stat) {
|
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);
|
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) {
|
int32_t vfs_mount(char *mountpoint, int32_t fstype, StoreDev *backingsd, bool format) {
|
||||||
VfsMountPoint *mp = NULL;
|
VfsMountPoint *mp = NULL;
|
||||||
|
|
||||||
|
|||||||
@ -53,6 +53,7 @@ typedef struct VfsMountPoint {
|
|||||||
int32_t (*stat)(struct VfsMountPoint *vmp, const char *path, FsStat *statbuf);
|
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 (*fetchdirent)(struct VfsMountPoint *vmp, const char *path, FsDirent *direntbuf, size_t idx);
|
||||||
int32_t (*mkdir)(struct VfsMountPoint *vmp, const char *path);
|
int32_t (*mkdir)(struct VfsMountPoint *vmp, const char *path);
|
||||||
|
int32_t (*delete)(struct VfsMountPoint *vmp, const char *path);
|
||||||
|
|
||||||
union {
|
union {
|
||||||
LittleFs littlefs;
|
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_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_fetchdirent(char *mountpoint, const char *path, FsDirent *direntbuf, size_t idx);
|
||||||
int32_t vfs_mkdir(char *mountpoint, const char *path);
|
int32_t vfs_mkdir(char *mountpoint, const char *path);
|
||||||
|
int32_t vfs_delete(char *mountpoint, const char *path);
|
||||||
|
|
||||||
#endif // VFS_VFS_H_
|
#endif // VFS_VFS_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user