diff --git a/kernel/syscall/devctl.c b/kernel/syscall/devctl.c index 11763e4..8b20add 100644 --- a/kernel/syscall/devctl.c +++ b/kernel/syscall/devctl.c @@ -52,6 +52,44 @@ int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) { goto done; } } break; + case DEVCTL_DEVLS_SZ: { + size_t n = 0; + spinlock_acquire(&DEVTABLE.spinlock); + for (size_t i = 0; i < LEN(DEVTABLE.devs); i++) { + if (DEVTABLE.devs[i]._hshtbstate == HSHTB_TAKEN) { + n++; + } + } + spinlock_release(&DEVTABLE.spinlock); + ret = n; + } break; + case DEVCTL_DEVLS_STAT: { + DevStat *devstat = (DevStat *)buffer1; + size_t idx = (size_t)len1; + + if (devstat == NULL) { + ret = E_INVALIDARGUMENT; + goto done; + } + + devstat->present = false; + + spinlock_acquire(&DEVTABLE.spinlock); + for (size_t i = 0; i < LEN(DEVTABLE.devs); i++) { + if (i == idx && DEVTABLE.devs[i]._hshtbstate == HSHTB_TAKEN) { + Dev *dev = &DEVTABLE.devs[i]; + hal_memcpy(devstat->name, dev->ident, sizeof(dev->ident)); + for (size_t j = 0; j < DEV_FNS_MAX; j++) { + if (dev->fns[j] != NULL) { + devstat->nfns++; + } + } + devstat->present = true; + break; + } + } + spinlock_release(&DEVTABLE.spinlock); + } break; default: { if (devh == NULL) { ret = E_INVALIDARGUMENT; diff --git a/share/sysdefs/devctl.h b/share/sysdefs/devctl.h index 2963128..f579d4f 100644 --- a/share/sysdefs/devctl.h +++ b/share/sysdefs/devctl.h @@ -2,6 +2,8 @@ #define SHARE_SYSDEFS_DEVCTL_H_ #define DEVCTL_GET_HANDLE 100 +#define DEVCTL_DEVLS_SZ 101 +#define DEVCTL_DEVLS_STAT 102 #define DEV_TERMDEV_PUTCH 0 @@ -25,6 +27,12 @@ typedef struct { uint8_t fontw, fonth; } FbDevGetInfo; +typedef struct { + bool present; + char name[0x100]; + size_t nfns; +} DevStat; + #endif #endif // SHARE_SYSDEFS_DEVCTL_H_