mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
DiskIO: add property removable
This commit is contained in:
@@ -16,6 +16,7 @@ typedef struct FFDiskIOResult
|
||||
FFstrbuf serial;
|
||||
FFDiskIOPhysicalType type;
|
||||
uint64_t size;
|
||||
bool removable;
|
||||
FFstrbuf devPath;
|
||||
uint64_t bytesRead;
|
||||
uint64_t readCount;
|
||||
|
||||
@@ -49,6 +49,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
|
||||
ffStrbufInit(&device->serial);
|
||||
ffStrbufInitS(&device->name, deviceName);
|
||||
ffStrbufInit(&device->devPath);
|
||||
device->removable = false;
|
||||
device->type = FF_DISKIO_PHYSICAL_TYPE_UNKNOWN;
|
||||
device->size = 0;
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
|
||||
ffStrbufInitF(&device->devPath, "/dev/%s", provider->lg_name);
|
||||
ffStrbufInit(&device->serial);
|
||||
ffStrbufInit(&device->interconnect);
|
||||
device->removable = false;
|
||||
switch (snapIter->device_type & DEVSTAT_TYPE_IF_MASK)
|
||||
{
|
||||
case DEVSTAT_TYPE_IF_SCSI: ffStrbufAppendS(&device->interconnect, "SCSI"); break;
|
||||
|
||||
@@ -114,6 +114,12 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
|
||||
device->size = 0;
|
||||
}
|
||||
|
||||
{
|
||||
char removableChar = '0';
|
||||
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/removable", devName);
|
||||
device->removable = removableChar == '1';
|
||||
}
|
||||
|
||||
{
|
||||
ffStrbufInit(&device->serial);
|
||||
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/serial", devName);
|
||||
|
||||
@@ -74,6 +74,8 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
|
||||
continue;
|
||||
}
|
||||
|
||||
device->removable = !!sdd->RemovableMedia;
|
||||
|
||||
ffStrbufInit(&device->interconnect);
|
||||
switch (sdd->BusType)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#define FF_DISKIO_DISPLAY_NAME "Disk IO"
|
||||
#define FF_DISKIO_NUM_FORMAT_ARGS 12
|
||||
#define FF_DISKIO_NUM_FORMAT_ARGS 13
|
||||
|
||||
static int sortDevices(const FFDiskIOResult* left, const FFDiskIOResult* right)
|
||||
{
|
||||
@@ -103,6 +103,7 @@ void ffPrintDiskIO(FFDiskIOOptions* options)
|
||||
{FF_FORMAT_ARG_TYPE_UINT64, &dev->writeCount},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &sizePretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &dev->serial},
|
||||
{FF_FORMAT_ARG_TYPE_BOOL, &dev->removable},
|
||||
});
|
||||
}
|
||||
++index;
|
||||
@@ -204,6 +205,7 @@ void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, y
|
||||
yyjson_mut_obj_add_uint(doc, obj, "writeCount", dev->writeCount);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "size", dev->size);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "serial", &dev->serial);
|
||||
yyjson_mut_obj_add_bool(doc, obj, "removable", dev->removable);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFDiskIOResult, dev, result)
|
||||
@@ -229,6 +231,7 @@ void ffPrintDiskIOHelpFormat(void)
|
||||
"Number of writes",
|
||||
"Device size (formatted)",
|
||||
"Serial number",
|
||||
"Removable",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user