devctl commands for getting device info

This commit is contained in:
2025-10-08 19:32:37 +02:00
parent 3830af45c8
commit 0ac80c76b0
2 changed files with 46 additions and 0 deletions

View File

@ -52,6 +52,44 @@ int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
goto done; goto done;
} }
} break; } 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: { default: {
if (devh == NULL) { if (devh == NULL) {
ret = E_INVALIDARGUMENT; ret = E_INVALIDARGUMENT;

View File

@ -2,6 +2,8 @@
#define SHARE_SYSDEFS_DEVCTL_H_ #define SHARE_SYSDEFS_DEVCTL_H_
#define DEVCTL_GET_HANDLE 100 #define DEVCTL_GET_HANDLE 100
#define DEVCTL_DEVLS_SZ 101
#define DEVCTL_DEVLS_STAT 102
#define DEV_TERMDEV_PUTCH 0 #define DEV_TERMDEV_PUTCH 0
@ -25,6 +27,12 @@ typedef struct {
uint8_t fontw, fonth; uint8_t fontw, fonth;
} FbDevGetInfo; } FbDevGetInfo;
typedef struct {
bool present;
char name[0x100];
size_t nfns;
} DevStat;
#endif #endif
#endif // SHARE_SYSDEFS_DEVCTL_H_ #endif // SHARE_SYSDEFS_DEVCTL_H_