Compare commits
3 Commits
a349154545
...
26e5d92947
| Author | SHA1 | Date | |
|---|---|---|---|
| 26e5d92947 | |||
| d81d1133dd | |||
| 7e3b162591 |
@ -19,6 +19,7 @@ size_t hal_strspn(const char *s, const char *accept);
|
|||||||
char *hal_strcpy(char *dest, const char *src);
|
char *hal_strcpy(char *dest, const char *src);
|
||||||
char *hal_strchr(const char *s, int c);
|
char *hal_strchr(const char *s, int c);
|
||||||
char *hal_strstr(const char *str, const char *substring);
|
char *hal_strstr(const char *str, const char *substring);
|
||||||
|
char *hal_string_combine(char *dest, const char *src);
|
||||||
void hal_wait(uint32_t ms);
|
void hal_wait(uint32_t ms);
|
||||||
int32_t hal_randnum(void);
|
int32_t hal_randnum(void);
|
||||||
|
|
||||||
|
|||||||
@ -140,3 +140,13 @@ char *hal_strstr(const char *str, const char *substring)
|
|||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *hal_string_combine(char *dest, const char *src) {
|
||||||
|
size_t i, j;
|
||||||
|
for(i = 0; dest[i] != '\0'; i++);
|
||||||
|
for(j = 0; src[j] != '\0'; j++) {
|
||||||
|
dest[i+j] = src[j];
|
||||||
|
}
|
||||||
|
dest[i+j] = '\0';
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|||||||
@ -224,9 +224,7 @@ void proc_sched(void *cpustate) {
|
|||||||
hal_intr_disable();
|
hal_intr_disable();
|
||||||
sched_ticks++;
|
sched_ticks++;
|
||||||
|
|
||||||
IntrStackFrame *frame = cpustate;
|
hal_memcpy(&PROCS.current->platformdata.trapframe, cpustate, sizeof(IntrStackFrame));
|
||||||
|
|
||||||
PROCS.current->platformdata.trapframe = *frame;
|
|
||||||
|
|
||||||
PROCS.current = proc_nextready();
|
PROCS.current = proc_nextready();
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,28 @@
|
|||||||
#include "dlmalloc/malloc.h"
|
#include "dlmalloc/malloc.h"
|
||||||
|
|
||||||
VfsTable VFS_TABLE;
|
VfsTable VFS_TABLE;
|
||||||
|
VfsBusyObjs VFS_BUSY_VOBJS;
|
||||||
|
|
||||||
|
#define CHECK_BUSY_VFSOBJ() \
|
||||||
|
char *tmpbuf = dlmalloc(VFS_MOUNTPOINT_LABEL_MAX+1+VFS_PATH_MAX); \
|
||||||
|
\
|
||||||
|
hal_memset(tmpbuf, 0, VFS_MOUNTPOINT_LABEL_MAX+1+VFS_PATH_MAX); \
|
||||||
|
hal_string_combine(tmpbuf, mountpoint); \
|
||||||
|
hal_string_combine(tmpbuf, ":"); \
|
||||||
|
hal_string_combine(tmpbuf, path); \
|
||||||
|
\
|
||||||
|
bool busy = false; \
|
||||||
|
VfsObj *vobj, *vobjtmp; \
|
||||||
|
spinlock_acquire(&VFS_BUSY_VOBJS.spinlock); \
|
||||||
|
LL_FOREACH_SAFE(VFS_BUSY_VOBJS.vobjs, vobj, vobjtmp) { \
|
||||||
|
if (hal_strcmp(vobj->path, tmpbuf) == 0) { \
|
||||||
|
busy = true; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
spinlock_release(&VFS_BUSY_VOBJS.spinlock); \
|
||||||
|
\
|
||||||
|
dlfree(tmpbuf);
|
||||||
|
|
||||||
void vfs_init_littlefs(VfsMountPoint *mp, bool format) {
|
void vfs_init_littlefs(VfsMountPoint *mp, bool format) {
|
||||||
struct lfs_config *cfg = dlmalloc(sizeof(*cfg));
|
struct lfs_config *cfg = dlmalloc(sizeof(*cfg));
|
||||||
@ -95,6 +117,12 @@ int32_t vfs_fetchdirent(char *mountpoint, const char *path, FsDirent *direntbuf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t vfs_delete(char *mountpoint, const char *path) {
|
int32_t vfs_delete(char *mountpoint, const char *path) {
|
||||||
|
CHECK_BUSY_VFSOBJ()
|
||||||
|
|
||||||
|
if (busy) {
|
||||||
|
return E_NOTYET;
|
||||||
|
}
|
||||||
|
|
||||||
VfsMountPoint *mp = NULL;
|
VfsMountPoint *mp = NULL;
|
||||||
|
|
||||||
spinlock_acquire(&VFS_TABLE.spinlock);
|
spinlock_acquire(&VFS_TABLE.spinlock);
|
||||||
@ -156,6 +184,12 @@ int32_t vfs_unmount(char *mountpoint) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VfsObj *vfs_open(char *mountpoint, const char *path, uint32_t flags) {
|
VfsObj *vfs_open(char *mountpoint, const char *path, uint32_t flags) {
|
||||||
|
CHECK_BUSY_VFSOBJ()
|
||||||
|
|
||||||
|
if (busy) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
VfsMountPoint *mp = NULL;
|
VfsMountPoint *mp = NULL;
|
||||||
|
|
||||||
spinlock_acquire(&VFS_TABLE.spinlock);
|
spinlock_acquire(&VFS_TABLE.spinlock);
|
||||||
@ -166,16 +200,34 @@ VfsObj *vfs_open(char *mountpoint, const char *path, uint32_t flags) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mp->open(mp, path, flags);
|
VfsObj *vobj1 = mp->open(mp, path, flags);
|
||||||
|
if (vobj1 == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hal_string_combine(vobj1->path, mountpoint);
|
||||||
|
hal_string_combine(vobj1->path, ":");
|
||||||
|
hal_string_combine(vobj1->path, path);
|
||||||
|
|
||||||
|
spinlock_acquire(&VFS_BUSY_VOBJS.spinlock);
|
||||||
|
LL_APPEND(VFS_BUSY_VOBJS.vobjs, vobj1);
|
||||||
|
spinlock_release(&VFS_BUSY_VOBJS.spinlock);
|
||||||
|
|
||||||
|
return vobj1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vfs_close(VfsObj *vobj) {
|
void vfs_close(VfsObj *vobj) {
|
||||||
|
spinlock_acquire(&VFS_BUSY_VOBJS.spinlock);
|
||||||
|
LL_REMOVE(VFS_BUSY_VOBJS.vobjs, vobj);
|
||||||
|
spinlock_release(&VFS_BUSY_VOBJS.spinlock);
|
||||||
vobj->cleanup(vobj);
|
vobj->cleanup(vobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vfs_init(void) {
|
void vfs_init(void) {
|
||||||
hal_memset(&VFS_TABLE, 0, sizeof(VFS_TABLE));
|
hal_memset(&VFS_TABLE, 0, sizeof(VFS_TABLE));
|
||||||
spinlock_init(&VFS_TABLE.spinlock);
|
spinlock_init(&VFS_TABLE.spinlock);
|
||||||
|
hal_memset(&VFS_BUSY_VOBJS, 0, sizeof(VFS_BUSY_VOBJS));
|
||||||
|
spinlock_init(&VFS_BUSY_VOBJS.spinlock);
|
||||||
|
|
||||||
{
|
{
|
||||||
RamSdInitExtra extra = { .capacity = baseimg_getsize(), .preallocbuffer = (uint8_t *)baseimg_getaddr() };
|
RamSdInitExtra extra = { .capacity = baseimg_getsize(), .preallocbuffer = (uint8_t *)baseimg_getaddr() };
|
||||||
|
|||||||
@ -30,7 +30,9 @@ enum {
|
|||||||
#define VFS_PATH_MAX 1024
|
#define VFS_PATH_MAX 1024
|
||||||
|
|
||||||
typedef struct VfsObj {
|
typedef struct VfsObj {
|
||||||
|
struct VfsObj *next;
|
||||||
SpinLock spinlock;
|
SpinLock spinlock;
|
||||||
|
char path[VFS_MOUNTPOINT_LABEL_MAX+1+VFS_PATH_MAX];
|
||||||
void *extra;
|
void *extra;
|
||||||
size_t extrasize;
|
size_t extrasize;
|
||||||
struct VfsMountPoint *vmp;
|
struct VfsMountPoint *vmp;
|
||||||
@ -40,6 +42,13 @@ typedef struct VfsObj {
|
|||||||
void (*cleanup)(struct VfsObj *vobj);
|
void (*cleanup)(struct VfsObj *vobj);
|
||||||
} VfsObj;
|
} VfsObj;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SpinLock spinlock;
|
||||||
|
VfsObj *vobjs;
|
||||||
|
} VfsBusyObjs;
|
||||||
|
|
||||||
|
extern VfsBusyObjs VFS_BUSY_VOBJS;
|
||||||
|
|
||||||
typedef struct VfsMountPoint {
|
typedef struct VfsMountPoint {
|
||||||
int _hshtbstate;
|
int _hshtbstate;
|
||||||
char label[VFS_MOUNTPOINT_LABEL_MAX];
|
char label[VFS_MOUNTPOINT_LABEL_MAX];
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
#ifndef DIAGDUMMY_BLOCK_H_
|
|
||||||
#define DIAGDUMMY_BLOCK_H_
|
|
||||||
|
|
||||||
void diagdummy_block(void);
|
|
||||||
|
|
||||||
#endif // DIAGDUMMY_BLOCK_H_
|
|
||||||
@ -1,5 +1,7 @@
|
|||||||
#include <ulib.h>
|
#include <ulib.h>
|
||||||
#include "block.h"
|
|
||||||
|
#define CMDS(X) \
|
||||||
|
X(block) X(openf)
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
if (argslen() == 0) {
|
if (argslen() == 0) {
|
||||||
@ -9,9 +11,13 @@ void main(void) {
|
|||||||
|
|
||||||
char *cmd = args()[0];
|
char *cmd = args()[0];
|
||||||
|
|
||||||
if (string_strcmp(cmd, "block") == 0) {
|
#define X(name) if (string_strcmp(cmd, #name) == 0) { \
|
||||||
diagdummy_block();
|
extern void diagdummy_ ## name(void); \
|
||||||
} else {
|
diagdummy_ ## name(); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
CMDS(X)
|
||||||
|
#undef X
|
||||||
|
|
||||||
uprintf("diagdummy: unknown cmd %s\n", cmd);
|
uprintf("diagdummy: unknown cmd %s\n", cmd);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
9
user/diagdummy/openf.c
Normal file
9
user/diagdummy/openf.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <ulib.h>
|
||||||
|
|
||||||
|
void diagdummy_openf(void) {
|
||||||
|
fsh_t h = fs_openf("base:/bin/init", FS_OF_READ);
|
||||||
|
uprintf("h = %d\n", h);
|
||||||
|
for(;;);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user