Store devices as a hashtable

This commit is contained in:
2025-10-03 23:47:58 +02:00
parent 18d646ff8b
commit 04a4b1395c
11 changed files with 53 additions and 38 deletions

View File

@ -6,11 +6,9 @@
#include "spinlock/spinlock.h"
#include "proc/proc.h"
#include "sysdefs/devctl.h"
#include "dev/termdev.h"
#include "dev/ps2kbdev.h"
#include "util/util.h"
Dev *DEVS = NULL;
#include "hshtb.h"
#include "dev/dev.h"
int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
uint64_t *devh = (uint64_t *)devh1;
@ -23,16 +21,15 @@ int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
switch (cmd) {
case DEVCTL_GET_HANDLE: {
Dev *founddev = NULL;
size_t i = 0;
Dev *dev, *devtmp;
LL_FOREACH_SAFE_IDX(DEVS, dev, devtmp, i) {
if (i == buffer1) {
founddev = dev;
break;
}
char *ident = (char *)buffer1;
if (ident == NULL) {
ret = E_INVALIDARGUMENT;
goto done;
}
Dev *founddev;
HSHTB_GET(DEVTABLE.devs, ident, ident, founddev);
if (founddev == NULL) {
ret = E_NOENTRY;
goto done;