From 5c21931a097def94a1424938723434791c13c2c2 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 3 Nov 2024 18:05:56 +0800 Subject: [PATCH] DiskIO (DragonFly): add support --- CMakeLists.txt | 4 +++ src/detection/diskio/diskio_bsd.c | 42 ++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea929c28d..6cb725dba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1428,6 +1428,10 @@ elseif(FreeBSD) target_link_libraries(libfastfetch PRIVATE "geom" ) + else() + target_link_libraries(libfastfetch + PRIVATE "devstat" + ) endif() elseif(OpenBSD) target_link_libraries(libfastfetch diff --git a/src/detection/diskio/diskio_bsd.c b/src/detection/diskio/diskio_bsd.c index 42d2ab920..afb271a10 100644 --- a/src/detection/diskio/diskio_bsd.c +++ b/src/detection/diskio/diskio_bsd.c @@ -61,9 +61,49 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) return NULL; } + #else + +#include +#include + const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { - return "Fastfetch was compiled without libgeom support"; + if (checkversion() < 0) + return "checkversion() failed"; + + struct statinfo stats = { + .dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)), + }; + if (getdevs(&stats) < 0) + return "getdevs() failed"; + + for (int i = 0; i < stats.dinfo->numdevs; i++) + { + struct devstat* current = &stats.dinfo->devices[i]; + if (current->device_type & DEVSTAT_TYPE_PASS) + continue; + + char deviceName[128]; + snprintf(deviceName, sizeof(deviceName), "%s%d", current->device_name, current->unit_number); + + if (options->namePrefix.length && strncmp(deviceName, options->namePrefix.chars, options->namePrefix.length) != 0) + continue; + + FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result); + ffStrbufInitS(&device->name, deviceName); + ffStrbufInitF(&device->devPath, "/dev/%s", deviceName); + device->bytesRead = current->bytes_read; + device->readCount = current->num_reads; + device->bytesWritten = current->bytes_written; + device->writeCount = current->num_writes; + } + + if (stats.dinfo->mem_ptr) + free(stats.dinfo->mem_ptr); + free(stats.dinfo); + + return NULL; } + #endif