Skip to content

Commit b76d6e9

Browse files
committed
DiskIO (FreeBSD): add support
1 parent 2d2e0dd commit b76d6e9

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ elseif(BSD)
890890
target_link_libraries(libfastfetch
891891
PRIVATE "m"
892892
PRIVATE "usbhid"
893+
PRIVATE "devstat"
893894
)
894895
elseif(ANDROID)
895896
CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC)

src/detection/diskio/diskio_bsd.c

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
11
#include "diskio.h"
2-
#include "common/io/io.h"
3-
#include "util/stringUtils.h"
42

5-
#include <ctype.h>
6-
#include <limits.h>
3+
#include <devstat.h>
4+
#include <memory.h>
75

86
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
97
{
10-
return "Not supported on this platform";
8+
if (devstat_checkversion(NULL) < 0)
9+
return "devstat_checkversion() failed";
10+
11+
struct statinfo stats = {
12+
.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)),
13+
};
14+
if (devstat_getdevs(NULL, &stats) < 0)
15+
return "devstat_getdevs() failed";
16+
17+
for (int i = 0; i < stats.dinfo->numdevs; i++)
18+
{
19+
struct devstat* current = &stats.dinfo->devices[i];
20+
21+
char deviceName[128];
22+
snprintf(deviceName, sizeof(deviceName), "%s%d", current->device_name, current->unit_number);
23+
24+
if (options->namePrefix.length && strncmp(deviceName, options->namePrefix.chars, options->namePrefix.length) != 0)
25+
continue;
26+
27+
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
28+
ffStrbufInitS(&device->name, deviceName);
29+
ffStrbufInitF(&device->devPath, "/dev/%s", deviceName);
30+
31+
ffStrbufInit(&device->type);
32+
switch (current->device_type & DEVSTAT_TYPE_IF_MASK)
33+
{
34+
case DEVSTAT_TYPE_IF_SCSI: ffStrbufAppendS(&device->type, "SCSI"); break;
35+
case DEVSTAT_TYPE_IF_IDE: ffStrbufAppendS(&device->type, "IDE"); break;
36+
case DEVSTAT_TYPE_IF_OTHER: ffStrbufAppendS(&device->type, "OTHER"); break;
37+
}
38+
device->bytesRead = current->bytes[DEVSTAT_READ];
39+
device->readCount = current->operations[DEVSTAT_READ];
40+
device->bytesWritten = current->bytes[DEVSTAT_WRITE];
41+
device->writeCount = current->operations[DEVSTAT_WRITE];
42+
}
43+
44+
if (stats.dinfo->mem_ptr)
45+
free(stats.dinfo->mem_ptr);
46+
free(stats.dinfo);
47+
48+
return NULL;
1149
}

0 commit comments

Comments
 (0)