Hello user process

This commit is contained in:
2025-09-01 23:22:47 +02:00
parent 13ab117b1b
commit 2015e0e0aa
28 changed files with 744 additions and 65 deletions

View File

@ -27,6 +27,22 @@ int32_t kvfs_read(struct VfsMountPoint *vmp, const char *key, uint8_t *const buf
return E_OK;
}
int32_t kvfs_stat(struct VfsMountPoint *vmp, const char *key, struct VfsStat *stat) {
KvfsNode *node = NULL;
spinlock_acquire(&vmp->spinlock);
HSHTB_GET(&vmp->fs.kvfs, nodes, (char *)key, key_, node);
spinlock_release(&vmp->spinlock);
if (node == NULL) {
return E_NOENTRY;
}
stat->type = VFS_TYPE_FILE;
stat->size = KVFS_BUFFER_SIZE;
return E_OK;
}
int32_t kvfs_write(struct VfsMountPoint *vmp, const char *key, const uint8_t *const buffer, size_t n, size_t off) {
KvfsNode *node = NULL;
@ -85,7 +101,7 @@ int32_t kvfs_create(struct VfsMountPoint *vmp, const char *path, int32_t type) {
bool kvfs_check(void) {
int32_t ret;
ret = vfs_create("tmpvars", "hello", VFS_CREATE_FILE);
ret = vfs_create("tmpvars", "hello", VFS_TYPE_FILE);
if (ret != E_OK) return false;
char *hello = "WAWAWAWA!!!";

View File

@ -5,6 +5,7 @@
#include <stdbool.h>
struct VfsMountPoint;
struct VfsStat;
#define KVFS_NODE_KEY_MAX 128
#define KVFS_NODES_MAX 256
@ -21,6 +22,7 @@ typedef struct {
} Kvfs;
int32_t kvfs_read(struct VfsMountPoint *vmp, const char *key, uint8_t *const buffer, size_t n, size_t off);
int32_t kvfs_stat(struct VfsMountPoint *vmp, const char *key, struct VfsStat *stat);
int32_t kvfs_write(struct VfsMountPoint *vmp, const char *key, const uint8_t *const buffer, size_t n, size_t off);
int32_t kvfs_remove(struct VfsMountPoint *vmp, const char *key);
int32_t kvfs_create(struct VfsMountPoint *vmp, const char *path, int32_t type);

View File

@ -9,7 +9,6 @@
#define CHECK(err) \
do { \
int ok = (err); \
kprintf("ok = %d\n", ok); \
if (ok < 0) goto bad; \
} while(0)
@ -27,7 +26,29 @@ int32_t littlefs_read(struct VfsMountPoint *vmp, const char *path, uint8_t *cons
return E_OK;
bad:
spinlock_release(&vmp->spinlock);
return E_GENERIC_ERROR;
return E_BADIO;
}
int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, struct VfsStat *stat) {
spinlock_acquire(&vmp->spinlock);
LittleFs *fs = &vmp->fs.littlefs;
struct lfs_info stat1;
CHECK(lfs_stat(&fs->instance, path, &stat1));
if (stat1.type == LFS_TYPE_REG) {
stat->type = VFS_TYPE_FILE;
} else if (stat1.type == LFS_TYPE_DIR) {
stat->type = VFS_TYPE_DIR;
}
stat->size = stat1.size;
spinlock_release(&vmp->spinlock);
return E_OK;
bad:
spinlock_release(&vmp->spinlock);
return E_BADIO;
}
int32_t littlefs_write(struct VfsMountPoint *vmp, const char *path, const uint8_t *const buffer, size_t n, size_t off) {
@ -44,7 +65,7 @@ int32_t littlefs_write(struct VfsMountPoint *vmp, const char *path, const uint8_
return E_OK;
bad:
spinlock_release(&vmp->spinlock);
return E_GENERIC_ERROR;
return E_BADIO;
}
int32_t littlefs_remove(struct VfsMountPoint *vmp, const char *path) {
@ -57,7 +78,7 @@ int32_t littlefs_remove(struct VfsMountPoint *vmp, const char *path) {
return E_OK;
bad:
spinlock_release(&vmp->spinlock);
return E_GENERIC_ERROR;
return E_BADIO;
}
int32_t littlefs_cleanup(struct VfsMountPoint *vmp) {
@ -67,7 +88,7 @@ int32_t littlefs_cleanup(struct VfsMountPoint *vmp) {
return err;
}
err = lfs_unmount(&vmp->fs.littlefs.instance);
if (err < 0) { return E_GENERIC_ERROR; }
if (err < 0) { return E_BADIO; }
return E_OK;
}
@ -76,10 +97,10 @@ int32_t littlefs_create(struct VfsMountPoint *vmp, const char *path, int32_t typ
LittleFs *fs = &vmp->fs.littlefs;
switch (type) {
case VFS_CREATE_DIR:
case VFS_TYPE_DIR:
CHECK(lfs_mkdir(&fs->instance, path));
break;
case VFS_CREATE_FILE: {
case VFS_TYPE_FILE: {
lfs_file_t file;
CHECK(lfs_file_open(&fs->instance, &file, path, LFS_O_CREAT | LFS_O_WRONLY));
CHECK(lfs_file_close(&fs->instance, &file));
@ -90,7 +111,7 @@ int32_t littlefs_create(struct VfsMountPoint *vmp, const char *path, int32_t typ
return E_OK;
bad:
spinlock_release(&vmp->spinlock);
return E_GENERIC_ERROR;
return E_BADIO;
}
bool littlefs_check(void) {

View File

@ -8,12 +8,14 @@
#define LITTLEFS_BLOCK_SIZE 4096
struct VfsMountPoint;
struct VfsStat;
typedef struct {
lfs_t instance;
} LittleFs;
int32_t littlefs_read(struct VfsMountPoint *vmp, const char *path, uint8_t *const buffer, size_t n, size_t off);
int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, struct VfsStat *stat);
int32_t littlefs_write(struct VfsMountPoint *vmp, const char *path, const uint8_t *const buffer, size_t n, size_t off);
int32_t littlefs_remove(struct VfsMountPoint *vmp, const char *path);
int32_t littlefs_create(struct VfsMountPoint *vmp, const char *path, int32_t type);