Files
fastfetch/src/detection/diskio/diskio_obsd.c
T

40 lines
1.3 KiB
C
Raw Normal View History

2024-11-01 15:21:47 +08:00
#include "diskio.h"
2026-05-28 15:58:08 +08:00
#include "common/strutil.h"
2026-01-06 09:48:38 +08:00
#include "common/mallocHelper.h"
2024-11-01 15:21:47 +08:00
#include <sys/disk.h>
#include <sys/sysctl.h>
2026-03-29 09:28:49 +08:00
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) {
2026-03-30 10:27:23 +08:00
int mib[] = { CTL_HW, HW_DISKSTATS };
2024-11-01 15:21:47 +08:00
size_t len;
2026-07-10 18:08:04 +08:00
if (sysctl(mib, ARRAY_SIZE(mib), nullptr, &len, nullptr, 0) < 0) {
return "sysctl({HW_DISKSTATS}, nullptr) failed";
2026-03-29 09:28:49 +08:00
}
2024-11-01 15:21:47 +08:00
uint32_t nDrive = (uint32_t) (len / sizeof(struct diskstats));
2025-03-26 16:42:39 +08:00
FF_AUTO_FREE struct diskstats* stats = malloc(len);
2024-11-01 15:21:47 +08:00
2026-07-10 18:08:04 +08:00
if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, nullptr, 0) < 0) {
2024-11-01 15:21:47 +08:00
return "sysctl({HW_DISKSTATS}, stats) failed";
2026-03-29 09:28:49 +08:00
}
2024-11-01 15:21:47 +08:00
2026-03-29 09:28:49 +08:00
for (uint32_t i = 0; i < nDrive; ++i) {
2024-11-01 15:21:47 +08:00
struct diskstats* st = &stats[i];
2026-03-29 09:28:49 +08:00
if (options->namePrefix.length && strncmp(st->ds_name, options->namePrefix.chars, options->namePrefix.length) != 0) {
2024-11-01 15:21:47 +08:00
continue;
2026-03-29 09:28:49 +08:00
}
2024-11-01 15:21:47 +08:00
2026-04-14 10:41:18 +08:00
FFDiskIOResult* device = FF_LIST_ADD(FFDiskIOResult, *result);
2024-11-01 15:21:47 +08:00
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;
}
2026-07-10 18:08:04 +08:00
return nullptr;
2024-11-01 15:21:47 +08:00
}