Skip to content

Commit

Permalink
DiskIO: add property removable
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Dec 17, 2023
1 parent 70f39e6 commit fb8c7d6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/detection/diskio/diskio.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef struct FFDiskIOResult
FFstrbuf serial;
FFDiskIOPhysicalType type;
uint64_t size;
bool removable;
FFstrbuf devPath;
uint64_t bytesRead;
uint64_t readCount;
Expand Down
1 change: 1 addition & 0 deletions src/detection/diskio/diskio_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/detection/diskio/diskio_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/detection/diskio/diskio_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/detection/diskio/diskio_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
continue;
}

device->removable = !!sdd->RemovableMedia;

ffStrbufInit(&device->interconnect);
switch (sdd->BusType)
{
Expand Down
5 changes: 4 additions & 1 deletion src/modules/diskio/diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -229,6 +231,7 @@ void ffPrintDiskIOHelpFormat(void)
"Number of writes",
"Device size (formatted)",
"Serial number",
"Removable",
});
}

Expand Down

0 comments on commit fb8c7d6

Please sign in to comment.