Skip to content

Commit

Permalink
DiskIO: print serial number in json format
Browse files Browse the repository at this point in the history
Always init serial property
  • Loading branch information
CarterLi committed Dec 17, 2023
1 parent 9339a0f commit e7c7871
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/detection/diskio/diskio_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
continue;

FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
ffStrbufInit(&device->serial);
ffStrbufInitS(&device->name, deviceName);
ffStrbufInit(&device->devPath);
device->type = FF_DISKIO_PHYSICAL_TYPE_UNKNOWN;
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 @@ -47,6 +47,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)

FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
ffStrbufInitF(&device->devPath, "/dev/%s", provider->lg_name);
ffStrbufInit(&device->serial);
ffStrbufInit(&device->interconnect);
switch (snapIter->device_type & DEVSTAT_TYPE_IF_MASK)
{
Expand Down
4 changes: 4 additions & 0 deletions src/detection/diskio/diskio_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)

DWORD retSize = 0;

ffStrbufInit(&device->serial);
char sddBuffer[4096];
if(DeviceIoControl(
hDevice,
Expand All @@ -83,7 +84,10 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
{
STORAGE_DEVICE_DESCRIPTOR* sdd = (STORAGE_DEVICE_DESCRIPTOR*) sddBuffer;
if (sdd->SerialNumberOffset != 0)
{
ffStrbufSetS(&device->serial, (const char*) sddBuffer + sdd->SerialNumberOffset);
ffStrbufTrim(&device->serial, ' ');
}
}

DEVICE_SEEK_PENALTY_DESCRIPTOR dspd = {};
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 11
#define FF_DISKIO_NUM_FORMAT_ARGS 12

static int sortDevices(const FFDiskIOResult* left, const FFDiskIOResult* right)
{
Expand Down Expand Up @@ -102,6 +102,7 @@ void ffPrintDiskIO(FFDiskIOOptions* options)
{FF_FORMAT_ARG_TYPE_UINT64, &dev->readCount},
{FF_FORMAT_ARG_TYPE_UINT64, &dev->writeCount},
{FF_FORMAT_ARG_TYPE_STRBUF, &sizePretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &dev->serial},
});
}
++index;
Expand Down Expand Up @@ -202,6 +203,7 @@ void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, y
yyjson_mut_obj_add_uint(doc, obj, "readCount", dev->readCount);
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);
}

FF_LIST_FOR_EACH(FFDiskIOResult, dev, result)
Expand All @@ -226,6 +228,7 @@ void ffPrintDiskIOHelpFormat(void)
"Number of reads",
"Number of writes",
"Device size (formatted)",
"Serial number",
});
}

Expand Down

0 comments on commit e7c7871

Please sign in to comment.