diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/diskio/diskio_obsd.c | |
Add the files
Diffstat (limited to 'src/detection/diskio/diskio_obsd.c')
| -rw-r--r-- | src/detection/diskio/diskio_obsd.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/detection/diskio/diskio_obsd.c b/src/detection/diskio/diskio_obsd.c new file mode 100644 index 0000000..8dbc67e --- /dev/null +++ b/src/detection/diskio/diskio_obsd.c @@ -0,0 +1,39 @@ +#include "diskio.h" +#include "common/strutil.h" +#include "common/mallocHelper.h" + +#include <sys/disk.h> +#include <sys/sysctl.h> + +const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { + int mib[] = { CTL_HW, HW_DISKSTATS }; + size_t len; + if (sysctl(mib, ARRAY_SIZE(mib), NULL, &len, NULL, 0) < 0) { + return "sysctl({HW_DISKSTATS}, NULL) failed"; + } + uint32_t nDrive = (uint32_t) (len / sizeof(struct diskstats)); + + FF_AUTO_FREE struct diskstats* stats = malloc(len); + + if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, NULL, 0) < 0) { + return "sysctl({HW_DISKSTATS}, stats) failed"; + } + + for (uint32_t i = 0; i < nDrive; ++i) { + struct diskstats* st = &stats[i]; + + if (options->namePrefix.length && strncmp(st->ds_name, options->namePrefix.chars, options->namePrefix.length) != 0) { + continue; + } + + FFDiskIOResult* device = FF_LIST_ADD(FFDiskIOResult, *result); + ffStrbufInitF(&device->devPath, "/dev/%s", st->ds_name); + ffStrbufInitS(&device->name, st->ds_name); + device->bytesRead = st->ds_rbytes; + device->readCount = st->ds_rxfer; + device->bytesWritten = st->ds_wbytes; + device->writeCount = st->ds_wxfer; + } + + return NULL; +} |