Expose storedevs to the outside world via dev interface

This commit is contained in:
2025-10-11 02:35:15 +02:00
parent 3996f71316
commit 6b0e05e506
18 changed files with 137 additions and 18 deletions

View File

@ -7,6 +7,10 @@
#include "dlmalloc/malloc.h"
#include "ramsd.h"
#include "util/util.h"
#include "dev/dev.h"
#include "hshtb.h"
#include "hal/hal.h"
#include "randcrypto/uniqid.h"
StoreDevList STOREDEV_LIST;
@ -17,6 +21,36 @@ void storedev_init(void) {
LOG("storedev", "init\n");
}
void storedev_register_dev_entry(StoreDev *sd, int32_t sdtype) {
char uniq[5];
randcrypto_gen_uniqid(uniq, 4);
char key[20];
hal_memset(key, 0, sizeof(key));
if (sdtype == STOREDEV_RAMSD) {
ksprintf(key, "ramsd-%s", uniq);
}
spinlock_acquire(&DEVTABLE.spinlock);
Dev *dev = NULL;
HSHTB_ALLOC(DEVTABLE.devs, ident, key, dev);
spinlock_release(&DEVTABLE.spinlock);
if (dev == NULL) {
ERR("storedev", "could not register dev entry for storedev");
return;
}
spinlock_init(&dev->spinlock);
dev->extra = (void *)sd;
}
void storedev_unregister_dev_entry(Dev *dev) {
spinlock_acquire(&DEVTABLE.spinlock);
HSHTB_DELETE(DEVTABLE.devs, ident, dev->ident);
spinlock_release(&DEVTABLE.spinlock);
}
StoreDev *storedev_create(int32_t sdtype, void *extra) {
StoreDev *sd = dlmalloc(sizeof(*sd));
if (sd == NULL) {
@ -25,6 +59,8 @@ StoreDev *storedev_create(int32_t sdtype, void *extra) {
spinlock_acquire(&STOREDEV_LIST.spinlock);
sd->_magic = STOREDEV_MAGIC;
switch (sdtype) {
case STOREDEV_RAMSD: {
spinlock_init(&sd->spinlock);
@ -47,6 +83,9 @@ StoreDev *storedev_create(int32_t sdtype, void *extra) {
return NULL;
}
spinlock_release(&STOREDEV_LIST.spinlock);
storedev_register_dev_entry(sd, sdtype);
return sd;
}

View File

@ -6,6 +6,9 @@
#include "spinlock/spinlock.h"
#include "ramsd.h"
#include "compiler/attr.h"
#include "dev/dev.h"
#define STOREDEV_MAGIC 0x50FA
enum {
STOREDEV_RAMSD,
@ -16,6 +19,7 @@ UNUSED static const char *storedev_strings[] = {
};
typedef struct StoreDev {
uint32_t _magic;
struct StoreDev *next;
int32_t sdtype;
@ -43,4 +47,7 @@ void storedev_init(void);
StoreDev *storedev_create(int32_t sdtype, void *extra);
int32_t storedev_delete(StoreDev *sd);
void storedev_register_dev_entry(StoreDev *sd, int32_t sdtype);
void storedev_unregister_dev_entry(Dev *dev);
#endif // STOREDEV_STOREDEV_H_