Skip to content

Commit 0f3ce42

Browse files
committed
DiskIO (NetBSD): add support
1 parent 7d46b2a commit 0f3ce42

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ elseif(NetBSD)
691691
src/detection/dns/dns_linux.c
692692
src/detection/physicaldisk/physicaldisk_nosupport.c
693693
src/detection/physicalmemory/physicalmemory_nosupport.c
694-
src/detection/diskio/diskio_nosupport.c
694+
src/detection/diskio/diskio_nbsd.c
695695
src/detection/displayserver/linux/displayserver_linux.c
696696
src/detection/displayserver/linux/drm.c
697697
src/detection/displayserver/linux/wayland/wayland.c

src/detection/diskio/diskio_nbsd.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "diskio.h"
2+
#include "util/stringUtils.h"
3+
#include "util/mallocHelper.h"
4+
5+
#include <sys/iostat.h>
6+
#include <sys/sysctl.h>
7+
8+
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
9+
{
10+
int mib[] = {CTL_HW, HW_IOSTATS, sizeof(struct io_sysctl)};
11+
size_t len;
12+
if (sysctl(mib, ARRAY_SIZE(mib), NULL, &len, NULL, 0) < 0)
13+
return "sysctl({HW_IOSTATS}, NULL) failed";
14+
uint32_t nDrive = (uint32_t) (len / sizeof(struct io_sysctl));
15+
16+
struct io_sysctl* stats = malloc(len);
17+
18+
if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, NULL, 0) < 0)
19+
return "sysctl({HW_IOSTATS}, stats) failed";
20+
21+
for (uint32_t i = 0; i < nDrive; ++i)
22+
{
23+
struct io_sysctl* st = &stats[i];
24+
25+
if (options->namePrefix.length && strncmp(st->name, options->namePrefix.chars, options->namePrefix.length) != 0)
26+
continue;
27+
28+
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
29+
ffStrbufInitF(&device->devPath, "/dev/%s", st->name);
30+
ffStrbufInitS(&device->name, st->name);
31+
device->bytesRead = st->rbytes;
32+
device->readCount = st->rxfer;
33+
device->bytesWritten = st->wbytes;
34+
device->writeCount = st->wxfer;
35+
}
36+
37+
return NULL;
38+
}

0 commit comments

Comments
 (0)