Implement storedevs, prepare to port littlefs

This commit is contained in:
2025-08-16 12:34:36 +02:00
parent c936910199
commit 2b0566c56f
91 changed files with 54963 additions and 37 deletions

39
kernel/storedev/ramsd.c Normal file
View File

@ -0,0 +1,39 @@
#include <stddef.h>
#include <stdint.h>
#include "spinlock/spinlock.h"
#include "errors.h"
#include "dlmalloc/malloc.h"
#include "ramsd.h"
#include "storedev.h"
#include "hal/hal.h"
#include "util/util.h"
int32_t ramsd_init(struct StoreDev *sd, void *extra) {
RamSdInitExtra *e = extra;
sd->sd.ramsd.capacity = e->capacity;
sd->sd.ramsd.buffer = dlmalloc(sd->sd.ramsd.capacity);
if (sd->sd.ramsd.buffer == NULL) {
return E_NOMEMORY;
}
return E_OK;
}
int32_t ramsd_read(struct StoreDev *sd, uint8_t *const buffer, size_t n, size_t off) {
spinlock_acquire(&sd->spinlock);
hal_memcpy(buffer, sd->sd.ramsd.buffer + off, MIN(n, sd->sd.ramsd.capacity - off));
spinlock_release(&sd->spinlock);
return E_OK;
}
int32_t ramsd_write(struct StoreDev *sd, const uint8_t *const buffer, size_t n, size_t off) {
spinlock_acquire(&sd->spinlock);
hal_memcpy(sd->sd.ramsd.buffer + off, buffer, MIN(n, sd->sd.ramsd.capacity - off));
spinlock_release(&sd->spinlock);
return E_OK;
}
int32_t ramsd_cleanup(struct StoreDev *sd) {
spinlock_acquire(&sd->spinlock);
dlfree(sd->sd.ramsd.buffer);
spinlock_release(&sd->spinlock);
}