Compare commits

...

5 Commits

Author SHA1 Message Date
7936eb92f6 fs Implement del command 2025-10-15 20:11:07 +02:00
e917e81e78 Expose fs_delete() via ulib 2025-10-15 20:10:56 +02:00
ac6ebce112 Add fs_delete() syscall 2025-10-15 20:10:26 +02:00
371d777a7c vfs_delete() implement deleting files 2025-10-15 20:10:00 +02:00
a81d4e0c3b qemu-x86_64.sh run with system.img drive 2025-10-15 19:57:18 +02:00
13 changed files with 86 additions and 6 deletions

View File

@ -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) {

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_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);

View File

@ -224,3 +224,23 @@ int32_t SYSCALL1(sys_fs_mkdir, opath1) {
done: done:
return ret; return ret;
} }
int32_t SYSCALL1(sys_fs_delete, opath1) {
int32_t ret = E_BADIO;
const char *opath = (const char *)opath1;
if (opath == NULL) {
ret = E_INVALIDARGUMENT;
goto done;
}
char mp[_MP_MAX];
char path[_PATH_MAX];
path_parse(opath, mp, path);
ret = vfs_delete(mp, path);
done:
return ret;
}

View File

@ -12,5 +12,6 @@ int32_t SYSCALL4(sys_fs_read, fsh1, buffer1, len1, off1);
int32_t SYSCALL2(sys_fs_stat, opath1, fsstat1); int32_t SYSCALL2(sys_fs_stat, opath1, fsstat1);
int32_t SYSCALL3(sys_fs_fetchdirent, opath1, direntbuf1, idx1); int32_t SYSCALL3(sys_fs_fetchdirent, opath1, direntbuf1, idx1);
int32_t SYSCALL1(sys_fs_mkdir, opath1); int32_t SYSCALL1(sys_fs_mkdir, opath1);
int32_t SYSCALL1(sys_fs_delete, opath1);
#endif // SYSCALL_FS_H_ #endif // SYSCALL_FS_H_

View File

@ -47,6 +47,7 @@ SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
[SYS_FS_STAT] = &sys_fs_stat, [SYS_FS_STAT] = &sys_fs_stat,
[SYS_FS_FETCHDIRENT] = &sys_fs_fetchdirent, [SYS_FS_FETCHDIRENT] = &sys_fs_fetchdirent,
[SYS_FS_MKDIR] = &sys_fs_mkdir, [SYS_FS_MKDIR] = &sys_fs_mkdir,
[SYS_FS_DELETE] = &sys_fs_delete,
[SYS_DEV_GETHANDLE] = &sys_dev_gethandle, [SYS_DEV_GETHANDLE] = &sys_dev_gethandle,
[SYS_DEV_LISTSIZE] = &sys_dev_listsize, [SYS_DEV_LISTSIZE] = &sys_dev_listsize,
[SYS_DEV_STAT] = &sys_dev_stat, [SYS_DEV_STAT] = &sys_dev_stat,

View File

@ -49,6 +49,7 @@ void vfs_init_littlefs(VfsMountPoint *mp, bool format) {
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;

View File

@ -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_

View File

@ -2,4 +2,11 @@
set -x set -x
qemu-system-x86_64 -cpu IvyBridge -m 4G -cdrom mop2.iso -boot d -serial stdio $@ qemu-system-x86_64 \
-cpu IvyBridge \
-m 4G \
-cdrom mop2.iso \
-boot d \
-serial stdio \
-drive file=system.img,format=raw,if=ide \
$@

View File

@ -29,6 +29,7 @@
#define SYS_FS_WRITE 30 #define SYS_FS_WRITE 30
#define SYS_FS_FETCHDIRENT 31 #define SYS_FS_FETCHDIRENT 31
#define SYS_FS_MKDIR 32 #define SYS_FS_MKDIR 32
#define SYS_FS_DELETE 37
#define SYS_DEV_GETHANDLE 33 #define SYS_DEV_GETHANDLE 33
#define SYS_DEV_LISTSIZE 34 #define SYS_DEV_LISTSIZE 34
#define SYS_DEV_STAT 35 #define SYS_DEV_STAT 35

View File

@ -119,6 +119,10 @@ int32_t fs_mkdir(char *path) {
return syscall(SYS_FS_MKDIR, (uint64_t)path, 0, 0, 0, 0, 0); return syscall(SYS_FS_MKDIR, (uint64_t)path, 0, 0, 0, 0, 0);
} }
int32_t fs_delete(char *path) {
return syscall(SYS_FS_DELETE, (uint64_t)path, 0, 0, 0, 0, 0);
}
int32_t dev_gethandle(Dev_t *dev, char *name) { int32_t dev_gethandle(Dev_t *dev, char *name) {
return syscall(SYS_DEV_GETHANDLE, (uint64_t)dev, (uint64_t)name, 0, 0, 0, 0); return syscall(SYS_DEV_GETHANDLE, (uint64_t)dev, (uint64_t)name, 0, 0, 0, 0);
} }

View File

@ -36,6 +36,7 @@ int32_t fs_read(int32_t fsh, uint8_t *const buffer, size_t len, size_t off);
int32_t fs_stat(char *path, FsStat *statbuf); int32_t fs_stat(char *path, FsStat *statbuf);
int32_t fs_fetchdirent(char *path, FsDirent *direntbuf, size_t idx); int32_t fs_fetchdirent(char *path, FsDirent *direntbuf, size_t idx);
int32_t fs_mkdir(char *path); int32_t fs_mkdir(char *path);
int32_t fs_delete(char *path);
int32_t dev_gethandle(Dev_t *dev, char *name); int32_t dev_gethandle(Dev_t *dev, char *name);
int32_t dev_listsize(void); int32_t dev_listsize(void);
int32_t dev_stat(DevStat *devstatbuf, size_t idx); int32_t dev_stat(DevStat *devstatbuf, size_t idx);

17
user/fs/del.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdint.h>
#include <stddef.h>
#include <ulib.h>
void fs_del(void) {
if (argslen() < 2) {
uprintf("fs: Not enough arguments\n");
return;
}
char *path = *(args()+1);
int32_t r = fs_delete(path);
if (r != E_OK) {
uprintf("fs: could not delete %s\n", path);
}
}

View File

@ -4,7 +4,7 @@
#define CMDS(X) \ #define CMDS(X) \
X(fetch) X(mkf) X(mkd) \ X(fetch) X(mkf) X(mkd) \
X(tree) X(mount) X(tree) X(mount) X(del)
void main(void) { void main(void) {
if (argslen() == 0) { if (argslen() == 0) {