2026-03-01 14:01:18 +08:00
|
|
|
#include "common/kmod.h"
|
2026-05-28 15:58:08 +08:00
|
|
|
#include "common/strutil.h"
|
2026-03-01 14:01:18 +08:00
|
|
|
|
|
|
|
|
#include <sys/module.h>
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
2026-04-09 16:20:59 +08:00
|
|
|
typedef struct FF_A_PACKED FFNbsdModList {
|
2026-03-01 14:01:18 +08:00
|
|
|
int len;
|
|
|
|
|
modstat_t mods[];
|
|
|
|
|
} FFNbsdModList;
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
bool ffKmodLoaded(const char* modName) {
|
2026-07-10 18:08:04 +08:00
|
|
|
static FFNbsdModList* list = nullptr;
|
2026-03-01 14:01:18 +08:00
|
|
|
|
2026-07-10 18:08:04 +08:00
|
|
|
if (list == nullptr) {
|
2026-03-01 14:01:18 +08:00
|
|
|
struct iovec iov = {};
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
for (size_t len = 8192;; len = iov.iov_len) {
|
2026-03-01 14:01:18 +08:00
|
|
|
iov.iov_len = len;
|
|
|
|
|
iov.iov_base = realloc(iov.iov_base, len);
|
2026-03-29 09:28:49 +08:00
|
|
|
if (modctl(MODCTL_STAT, &iov) < 0) {
|
2026-03-01 14:01:18 +08:00
|
|
|
free(iov.iov_base);
|
|
|
|
|
return true; // ignore errors
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (len >= iov.iov_len) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-03-01 14:01:18 +08:00
|
|
|
}
|
|
|
|
|
list = (FFNbsdModList*) iov.iov_base;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
for (int i = 0; i < list->len; i++) {
|
|
|
|
|
if (ffStrEquals(list->mods[i].ms_name, modName)) {
|
2026-03-01 14:01:18 +08:00
|
|
|
return true;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2026-03-01 14:01:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|