Compare commits
2 Commits
b72f3ee00d
...
b624214433
Author | SHA1 | Date | |
---|---|---|---|
b624214433 | |||
26517e8e28 |
@ -107,6 +107,16 @@ int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, IoctlStat *st
|
|||||||
return E_OK;
|
return E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t littlefs_mkdir(struct VfsMountPoint *vmp, const char *path) {
|
||||||
|
spinlock_acquire(&vmp->spinlock);
|
||||||
|
int ok = lfs_mkdir(&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) {
|
||||||
|
@ -19,6 +19,7 @@ int32_t littlefs_cleanup(struct VfsMountPoint *vmp);
|
|||||||
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);
|
||||||
int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, IoctlStat *statbuf);
|
int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, IoctlStat *statbuf);
|
||||||
int32_t littlefs_fetchdirent(struct VfsMountPoint *vmp, const char *path, IoctlDirent *direntbuf, size_t idx);
|
int32_t littlefs_fetchdirent(struct VfsMountPoint *vmp, const char *path, IoctlDirent *direntbuf, size_t idx);
|
||||||
|
int32_t littlefs_mkdir(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);
|
||||||
|
@ -177,6 +177,23 @@ int32_t SYSCALL5(sys_ioctl, ioh1, cmd1, arg1, arg2, arg3) {
|
|||||||
|
|
||||||
ret = vfs_fetchdirent(mp, path, direntbuf, idx);
|
ret = vfs_fetchdirent(mp, path, direntbuf, idx);
|
||||||
} break;
|
} break;
|
||||||
|
case IOCTL_MKDIR: {
|
||||||
|
const char *opath = (const char *)arg1;
|
||||||
|
|
||||||
|
if (opath == NULL) {
|
||||||
|
ret = E_INVALIDARGUMENT;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t idx = (size_t)arg3;
|
||||||
|
|
||||||
|
char mp[IOCTL_MP_MAX];
|
||||||
|
char path[IOCTL_PATH_MAX];
|
||||||
|
|
||||||
|
path_parse(opath, mp, path);
|
||||||
|
|
||||||
|
ret = vfs_mkdir(mp, path);
|
||||||
|
} break;
|
||||||
default: {
|
default: {
|
||||||
ret = E_INVALIDARGUMENT;
|
ret = E_INVALIDARGUMENT;
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -48,6 +48,7 @@ void vfs_init_littlefs(VfsMountPoint *mp, bool format) {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vfs_stat(char *mountpoint, const char *path, IoctlStat *stat) {
|
int32_t vfs_stat(char *mountpoint, const char *path, IoctlStat *stat) {
|
||||||
@ -64,6 +65,20 @@ int32_t vfs_stat(char *mountpoint, const char *path, IoctlStat *stat) {
|
|||||||
return mp->stat(mp, path, stat);
|
return mp->stat(mp, path, stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t vfs_mkdir(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->mkdir(mp, path);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t vfs_fetchdirent(char *mountpoint, const char *path, IoctlDirent *direntbuf, size_t idx) {
|
int32_t vfs_fetchdirent(char *mountpoint, const char *path, IoctlDirent *direntbuf, size_t idx) {
|
||||||
VfsMountPoint *mp = NULL;
|
VfsMountPoint *mp = NULL;
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ typedef struct VfsMountPoint {
|
|||||||
int32_t (*cleanup)(struct VfsMountPoint *vmp);
|
int32_t (*cleanup)(struct VfsMountPoint *vmp);
|
||||||
int32_t (*stat)(struct VfsMountPoint *vmp, const char *path, IoctlStat *statbuf);
|
int32_t (*stat)(struct VfsMountPoint *vmp, const char *path, IoctlStat *statbuf);
|
||||||
int32_t (*fetchdirent)(struct VfsMountPoint *vmp, const char *path, IoctlDirent *direntbuf, size_t idx);
|
int32_t (*fetchdirent)(struct VfsMountPoint *vmp, const char *path, IoctlDirent *direntbuf, size_t idx);
|
||||||
|
int32_t (*mkdir)(struct VfsMountPoint *vmp, const char *path);
|
||||||
|
|
||||||
union {
|
union {
|
||||||
LittleFs littlefs;
|
LittleFs littlefs;
|
||||||
@ -73,5 +74,6 @@ void vfs_close(VfsObj *vobj);
|
|||||||
VfsObj *vfs_open(char *mountpoint, const char *path, uint32_t flags);
|
VfsObj *vfs_open(char *mountpoint, const char *path, uint32_t flags);
|
||||||
int32_t vfs_stat(char *mountpoint, const char *path, IoctlStat *stat);
|
int32_t vfs_stat(char *mountpoint, const char *path, IoctlStat *stat);
|
||||||
int32_t vfs_fetchdirent(char *mountpoint, const char *path, IoctlDirent *direntbuf, size_t idx);
|
int32_t vfs_fetchdirent(char *mountpoint, const char *path, IoctlDirent *direntbuf, size_t idx);
|
||||||
|
int32_t vfs_mkdir(char *mountpoint, const char *path);
|
||||||
|
|
||||||
#endif // VFS_VFS_H_
|
#endif // VFS_VFS_H_
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#define IOCTL_STAT 3
|
#define IOCTL_STAT 3
|
||||||
#define IOCTL_WRITE 4
|
#define IOCTL_WRITE 4
|
||||||
#define IOCTL_FETCHDIRENT 5
|
#define IOCTL_FETCHDIRENT 5
|
||||||
|
#define IOCTL_MKDIR 6
|
||||||
|
|
||||||
#define IOCTL_F_READ (1<<0)
|
#define IOCTL_F_READ (1<<0)
|
||||||
#define IOCTL_F_WRITE (1<<1)
|
#define IOCTL_F_WRITE (1<<1)
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <ulib.h>
|
#include <ulib.h>
|
||||||
|
|
||||||
extern void fs_fetch(void);
|
#define CMDS(X) \
|
||||||
extern void fs_mkf(void);
|
X(fetch) X(mkf) X(mkd)
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
if (argslen() == 0) {
|
if (argslen() == 0) {
|
||||||
@ -12,11 +12,13 @@ void main(void) {
|
|||||||
|
|
||||||
char *cmd = args()[0];
|
char *cmd = args()[0];
|
||||||
|
|
||||||
if (string_strcmp(cmd, "fetch") == 0) {
|
#define X(name) if (string_strcmp(cmd, #name) == 0) { \
|
||||||
fs_fetch();
|
extern void fs_ ## name(void); \
|
||||||
} else if (string_strcmp(cmd, "mkf") == 0) {
|
fs_ ## name(); \
|
||||||
fs_mkf();
|
return; \
|
||||||
} else {
|
}
|
||||||
|
CMDS(X)
|
||||||
|
#undef X
|
||||||
|
|
||||||
uprintf("fs: unknown command %s\n", cmd);
|
uprintf("fs: unknown command %s\n", cmd);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
17
user/fs/mkd.c
Normal file
17
user/fs/mkd.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ulib.h>
|
||||||
|
|
||||||
|
void fs_mkd(void) {
|
||||||
|
if (argslen() < 2) {
|
||||||
|
uprintf("fs: Not enough arguments\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *path = *(args()+1);
|
||||||
|
|
||||||
|
int32_t r = ioctl(IOCTL_NOHANDLE, IOCTL_MKDIR, (uint64_t)path, 0, 0);
|
||||||
|
if (r != E_OK) {
|
||||||
|
uprintf("fs: could not create %s\n", path);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user