Skip to content

Commit b05023f

Browse files
committed
DiskIO (OpenBSD): add support
1 parent 0f3ce42 commit b05023f

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ elseif(OpenBSD)
773773
src/detection/dns/dns_linux.c
774774
src/detection/physicaldisk/physicaldisk_nosupport.c
775775
src/detection/physicalmemory/physicalmemory_nosupport.c
776-
src/detection/diskio/diskio_nosupport.c
776+
src/detection/diskio/diskio_obsd.c
777777
src/detection/displayserver/linux/displayserver_linux.c
778778
src/detection/displayserver/linux/drm.c
779779
src/detection/displayserver/linux/wayland/wayland.c

src/detection/diskio/diskio_obsd.c

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

0 commit comments

Comments
 (0)