Skip to content

Commit 5c21931

Browse files
committed
DiskIO (DragonFly): add support
1 parent 3c04b0a commit 5c21931

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,10 @@ elseif(FreeBSD)
14281428
target_link_libraries(libfastfetch
14291429
PRIVATE "geom"
14301430
)
1431+
else()
1432+
target_link_libraries(libfastfetch
1433+
PRIVATE "devstat"
1434+
)
14311435
endif()
14321436
elseif(OpenBSD)
14331437
target_link_libraries(libfastfetch

src/detection/diskio/diskio_bsd.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,49 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
6161

6262
return NULL;
6363
}
64+
6465
#else
66+
67+
#include <devstat.h>
68+
#include <memory.h>
69+
6570
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
6671
{
67-
return "Fastfetch was compiled without libgeom support";
72+
if (checkversion() < 0)
73+
return "checkversion() failed";
74+
75+
struct statinfo stats = {
76+
.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)),
77+
};
78+
if (getdevs(&stats) < 0)
79+
return "getdevs() failed";
80+
81+
for (int i = 0; i < stats.dinfo->numdevs; i++)
82+
{
83+
struct devstat* current = &stats.dinfo->devices[i];
84+
if (current->device_type & DEVSTAT_TYPE_PASS)
85+
continue;
86+
87+
char deviceName[128];
88+
snprintf(deviceName, sizeof(deviceName), "%s%d", current->device_name, current->unit_number);
89+
90+
if (options->namePrefix.length && strncmp(deviceName, options->namePrefix.chars, options->namePrefix.length) != 0)
91+
continue;
92+
93+
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
94+
ffStrbufInitS(&device->name, deviceName);
95+
ffStrbufInitF(&device->devPath, "/dev/%s", deviceName);
96+
device->bytesRead = current->bytes_read;
97+
device->readCount = current->num_reads;
98+
device->bytesWritten = current->bytes_written;
99+
device->writeCount = current->num_writes;
100+
}
101+
102+
if (stats.dinfo->mem_ptr)
103+
free(stats.dinfo->mem_ptr);
104+
free(stats.dinfo);
105+
106+
return NULL;
68107
}
108+
69109
#endif

0 commit comments

Comments
 (0)