Working port of Little FS
This commit is contained in:
@ -32,14 +32,10 @@ int32_t kvfs_write(struct VfsMountPoint *vmp, const char *key, const uint8_t *co
|
||||
|
||||
spinlock_acquire(&vmp->spinlock);
|
||||
HSHTB_GET(&vmp->fs.kvfs, nodes, (char *)key, key_, node);
|
||||
if (node == NULL) {
|
||||
HSHTB_ALLOC(&vmp->fs.kvfs, nodes, (char *)key, key_, node);
|
||||
if (node == NULL) {
|
||||
spinlock_release(&vmp->spinlock);
|
||||
return E_NOMEMORY;
|
||||
}
|
||||
}
|
||||
spinlock_release(&vmp->spinlock);
|
||||
if (node == NULL) {
|
||||
return E_NOENTRY;
|
||||
}
|
||||
|
||||
spinlock_acquire(&node->spinlock);
|
||||
vmp->backingsd->write(vmp->backingsd, buffer, n, off);
|
||||
@ -72,9 +68,26 @@ int32_t kvfs_cleanup(struct VfsMountPoint *vmp) {
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t kvfs_create(struct VfsMountPoint *vmp, const char *path, int32_t type) {
|
||||
(void)type;
|
||||
KvfsNode *node = NULL;
|
||||
|
||||
spinlock_acquire(&vmp->spinlock);
|
||||
HSHTB_ALLOC(&vmp->fs.kvfs, nodes, (char *)path, key_, node);
|
||||
spinlock_release(&vmp->spinlock);
|
||||
|
||||
if (node == NULL) {
|
||||
return E_NOMEMORY;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
bool kvfs_check(void) {
|
||||
int32_t ret;
|
||||
|
||||
ret = vfs_create("tmpvars", "hello", VFS_CREATE_FILE);
|
||||
if (ret != E_OK) return false;
|
||||
|
||||
char *hello = "WAWAWAWA!!!";
|
||||
ret = vfs_write("tmpvars", "hello", hello, hal_strlen(hello)+1, 0);
|
||||
if (ret != E_OK) return false;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef FS_KVFS_KVFS_H_
|
||||
#define FS_KVFS_KVFS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct VfsMountPoint;
|
||||
@ -22,6 +23,7 @@ typedef struct {
|
||||
int32_t kvfs_read(struct VfsMountPoint *vmp, const char *key, uint8_t *const buffer, size_t n, size_t off);
|
||||
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);
|
||||
int32_t kvfs_cleanup(struct VfsMountPoint *vmp);
|
||||
bool kvfs_check(void);
|
||||
|
||||
|
Reference in New Issue
Block a user