Disk: move physicalType to module DiskIO

Physical type applies to physical disks, not partitions
This commit is contained in:
李通洲
2023-10-09 16:23:42 +08:00
parent 4194e56912
commit 8fa6aee571
11 changed files with 112 additions and 159 deletions
-8
View File
@@ -5,13 +5,6 @@
#include "fastfetch.h"
typedef enum FFDiskPhysicalType
{
FF_DISK_PHYSICAL_TYPE_UNKNOWN,
FF_DISK_PHYSICAL_TYPE_HDD,
FF_DISK_PHYSICAL_TYPE_SSD,
} FFDiskPhysicalType;
typedef struct FFDisk
{
FFstrbuf mountFrom;
@@ -19,7 +12,6 @@ typedef struct FFDisk
FFstrbuf filesystem;
FFstrbuf name;
FFDiskVolumeType type;
FFDiskPhysicalType physicalType;
uint64_t bytesUsed;
uint64_t bytesFree;
-50
View File
@@ -25,8 +25,6 @@ static void detectFsInfo(struct statfs* fs, FFDisk* disk)
#include <sys/attr.h>
#include <unistd.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/storage/IOStorageDeviceCharacteristics.h>
struct VolAttrBuf {
uint32_t length;
@@ -34,51 +32,6 @@ struct VolAttrBuf {
char volNameSpace[MAXPATHLEN];
} __attribute__((aligned(4), packed));
void detectDiskType(FFDisk* disk) // Not thread safe
{
if (!ffStrbufStartsWithS(&disk->mountFrom, "/dev/disk")) return;
static uint8_t cache[100]; // disk_id => physical_type + 1
const char* numStart = disk->mountFrom.chars + strlen("/dev/disk");
char* numEnd = NULL;
unsigned long diskId = strtoul(numStart, &numEnd, 10);
if (numEnd == numStart || diskId >= 100)
return;
if (cache[diskId])
{
disk->physicalType = cache[diskId] - 1;
return;
}
io_iterator_t iterator;
char temp = *numEnd; *numEnd = '\0'; // Check for root disk directly
*numEnd = temp;
if(IOServiceGetMatchingServices(MACH_PORT_NULL, IOBSDNameMatching(MACH_PORT_NULL, 0, disk->mountFrom.chars + strlen("/dev/")), &iterator) == kIOReturnSuccess)
{
for (io_registry_entry_t registryEntry = IOIteratorNext(iterator); registryEntry; IORegistryEntryGetParentEntry(registryEntry, kIOServicePlane, &registryEntry))
{
FF_CFTYPE_AUTO_RELEASE CFDictionaryRef deviceCharacteristics = (CFDictionaryRef) IORegistryEntryCreateCFProperty(registryEntry, CFSTR(kIOPropertyDeviceCharacteristicsKey), kCFAllocatorDefault, kNilOptions);
if (!deviceCharacteristics)
continue;
CFStringRef diskType = (CFStringRef) CFDictionaryGetValue(deviceCharacteristics, CFSTR(kIOPropertyMediumTypeKey));
if (diskType)
{
if (CFStringCompare(diskType, CFSTR(kIOPropertyMediumTypeSolidStateKey), 0) == 0)
disk->physicalType = FF_DISK_PHYSICAL_TYPE_SSD;
else if (CFStringCompare(diskType, CFSTR(kIOPropertyMediumTypeRotationalKey), 0) == 0)
disk->physicalType = FF_DISK_PHYSICAL_TYPE_HDD;
}
break;
}
IOObjectRelease(iterator);
}
cache[diskId] = (uint8_t) (disk->physicalType + 1);
}
void detectFsInfo(struct statfs* fs, FFDisk* disk)
{
if(fs->f_flags & MNT_DONTBROWSE)
@@ -94,8 +47,6 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk)
.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME,
}, &attrBuf, sizeof(attrBuf), 0) == 0)
ffStrbufInitNS(&disk->name, attrBuf.volNameRef.attr_length - 1 /* excluding '\0' */, attrBuf.volNameSpace);
detectDiskType(disk);
}
#endif
@@ -122,7 +73,6 @@ const char* ffDetectDisksImpl(FFlist* disks)
#endif
FFDisk* disk = ffListAdd(disks);
disk->physicalType = FF_DISK_PHYSICAL_TYPE_UNKNOWN;
disk->bytesTotal = fs->f_blocks * fs->f_bsize;
disk->bytesFree = (uint64_t)fs->f_bfree * fs->f_bsize;
+5 -17
View File
@@ -195,7 +195,7 @@ static bool isSubvolume(const FFlist* disks, FFDisk* currentDisk)
return false;
}
static bool detectPhysicalTypeAndReturnRemovable(FFDisk* currentDisk)
static bool isRemovable(FFDisk* currentDisk)
{
// https://stackoverflow.com/a/73302025
// Note my USB mobile hard disk isn't detected as removable, but my USB flash disk does.
@@ -218,20 +218,10 @@ static bool detectPhysicalTypeAndReturnRemovable(FFDisk* currentDisk)
if (!ffStrStartsWith(partitionName, entry->d_name)) continue;
ffStrbufAppendS(&basePath, entry->d_name);
index = basePath.length;
// /sys/block/sdx/queue/rotational
ffStrbufAppendS(&basePath, "/queue/rotational");
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
if (ffReadFileBuffer(basePath.chars, &buffer))
currentDisk->physicalType = ffStrbufEqualS(&buffer, "1") ? FF_DISK_PHYSICAL_TYPE_HDD : FF_DISK_PHYSICAL_TYPE_SSD;
else
currentDisk->physicalType = FF_DISK_PHYSICAL_TYPE_UNKNOWN;
ffStrbufSubstrBefore(&basePath, index);
// /sys/block/sdx/removable
ffStrbufAppendS(&basePath, entry->d_name);
ffStrbufAppendS(&basePath, "/removable");
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
return ffReadFileBuffer(basePath.chars, &buffer) && ffStrbufEqualS(&buffer, "1");
}
@@ -240,10 +230,9 @@ static bool detectPhysicalTypeAndReturnRemovable(FFDisk* currentDisk)
static void detectType(const FFlist* disks, FFDisk* currentDisk)
{
bool isRemovable = detectPhysicalTypeAndReturnRemovable(currentDisk);
if(currentDisk->type != FF_DISK_VOLUME_TYPE_NONE) return;
if(isRemovable)
if(isRemovable(currentDisk))
currentDisk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else if(isSubvolume(disks, currentDisk))
currentDisk->type = FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT;
@@ -289,7 +278,6 @@ const char* ffDetectDisksImpl(FFlist* disks)
//We have a valid device, add it to the list
FFDisk* disk = ffListAdd(disks);
disk->type = FF_DISK_VOLUME_TYPE_NONE;
disk->physicalType = FF_DISK_PHYSICAL_TYPE_UNKNOWN;
//detect mountFrom
ffStrbufInitS(&disk->mountFrom, device->mnt_fsname);
-28
View File
@@ -28,34 +28,6 @@ const char* ffDetectDisksImpl(FFlist* disks)
ffStrbufInitWS(&disk->mountpoint, mountpoint);
wchar_t volumeName[64];
disk->physicalType = FF_DISK_PHYSICAL_TYPE_UNKNOWN;
if(mountpoint[1] == ':')
{
memcpy(volumeName, L"\\\\.\\ :", sizeof(L"\\\\.\\ :"));
volumeName[4] = mountpoint[0];
FF_AUTO_CLOSE_FD HANDLE handle = CreateFileW(volumeName, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (handle != INVALID_HANDLE_VALUE)
{
DEVICE_SEEK_PENALTY_DESCRIPTOR dspd = {};
DWORD retSize = 0;
if(DeviceIoControl(
handle,
IOCTL_STORAGE_QUERY_PROPERTY,
&(STORAGE_PROPERTY_QUERY) {
.PropertyId = StorageDeviceSeekPenaltyProperty,
.QueryType = PropertyStandardQuery,
},
sizeof(STORAGE_PROPERTY_QUERY),
&dspd,
sizeof(dspd),
&retSize,
NULL
) && retSize == sizeof(dspd))
disk->physicalType = dspd.IncursSeekPenalty ? FF_DISK_PHYSICAL_TYPE_HDD : FF_DISK_PHYSICAL_TYPE_SSD;
}
}
if(GetVolumeNameForVolumeMountPointW(mountpoint, volumeName, sizeof(volumeName) / sizeof(*volumeName)))
ffStrbufInitWS(&disk->mountFrom, volumeName);
else
+9 -1
View File
@@ -2,10 +2,18 @@
#include "fastfetch.h"
typedef enum FFDiskIOPhysicalType
{
FF_DISKIO_PHYSICAL_TYPE_UNKNOWN,
FF_DISKIO_PHYSICAL_TYPE_HDD,
FF_DISKIO_PHYSICAL_TYPE_SSD,
} FFDiskIOPhysicalType;
typedef struct FFDiskIOResult
{
FFstrbuf name;
FFstrbuf type;
FFstrbuf interconnect;
FFDiskIOPhysicalType type;
FFstrbuf devPath;
uint64_t bytesRead;
uint64_t readCount;
+18 -2
View File
@@ -5,6 +5,7 @@
#include <IOKit/IOBSD.h>
#include <IOKit/storage/IOMedia.h>
#include <IOKit/storage/IOBlockStorageDriver.h>
#include <IOKit/storage/IOStorageDeviceCharacteristics.h>
#include <IOKit/storage/IOStorageProtocolCharacteristics.h>
static inline void wrapIoObjectRelease(io_service_t* service)
@@ -47,7 +48,8 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
ffStrbufInitS(&device->name, deviceName);
ffStrbufInit(&device->devPath);
ffStrbufInit(&device->type);
device->type = FF_DISKIO_PHYSICAL_TYPE_UNKNOWN;
ffCfDictGetInt64(statistics, CFSTR(kIOBlockStorageDriverStatisticsBytesReadKey), (int64_t*) &device->bytesRead);
ffCfDictGetInt64(statistics, CFSTR(kIOBlockStorageDriverStatisticsBytesWrittenKey), (int64_t*) &device->bytesWritten);
ffCfDictGetInt64(statistics, CFSTR(kIOBlockStorageDriverStatisticsReadsKey), (int64_t*) &device->readCount);
@@ -60,12 +62,26 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
ffStrbufPrependS(&device->devPath, "/dev/");
}
ffStrbufInit(&device->interconnect);
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryPhysical = 0;
if (IORegistryEntryGetParentEntry(entryDriver, kIOServicePlane, &entryPhysical) == KERN_SUCCESS)
{
FF_CFTYPE_AUTO_RELEASE CFDictionaryRef protocolCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyProtocolCharacteristicsKey), kCFAllocatorDefault, kNilOptions);
if (protocolCharacteristics)
ffCfDictGetString(protocolCharacteristics, CFSTR("Physical Interconnect"), &device->type);
ffCfDictGetString(protocolCharacteristics, CFSTR("Physical Interconnect"), &device->interconnect);
FF_CFTYPE_AUTO_RELEASE CFDictionaryRef deviceCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyDeviceCharacteristicsKey), kCFAllocatorDefault, kNilOptions);
if (deviceCharacteristics)
{
CFStringRef mediumType = (CFStringRef) CFDictionaryGetValue(deviceCharacteristics, CFSTR(kIOPropertyMediumTypeKey));
if (mediumType)
{
if (CFStringCompare(mediumType, CFSTR(kIOPropertyMediumTypeSolidStateKey), 0) == 0)
device->type = FF_DISKIO_PHYSICAL_TYPE_SSD;
else if (CFStringCompare(mediumType, CFSTR(kIOPropertyMediumTypeRotationalKey), 0) == 0)
device->type = FF_DISKIO_PHYSICAL_TYPE_HDD;
}
}
}
}
+5 -5
View File
@@ -29,13 +29,13 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
ffStrbufInitS(&device->name, deviceName);
ffStrbufInitF(&device->devPath, "/dev/%s", deviceName);
ffStrbufInit(&device->type);
device->type = FF_DISKIO_PHYSICAL_TYPE_UNKNOWN;
ffStrbufInit(&device->interconnect);
switch (current->device_type & DEVSTAT_TYPE_IF_MASK)
{
case DEVSTAT_TYPE_IF_SCSI: ffStrbufAppendS(&device->type, "SCSI"); break;
case DEVSTAT_TYPE_IF_IDE: ffStrbufAppendS(&device->type, "IDE"); break;
case DEVSTAT_TYPE_IF_OTHER: ffStrbufAppendS(&device->type, "OTHER"); break;
case DEVSTAT_TYPE_IF_SCSI: ffStrbufAppendS(&device->interconnect, "SCSI"); break;
case DEVSTAT_TYPE_IF_IDE: ffStrbufAppendS(&device->interconnect, "IDE"); break;
case DEVSTAT_TYPE_IF_OTHER: ffStrbufAppendS(&device->interconnect, "OTHER"); break;
}
device->bytesRead = current->bytes[DEVSTAT_READ];
device->readCount = current->operations[DEVSTAT_READ];
+13 -6
View File
@@ -53,10 +53,10 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
}
if (flag) continue;
char pathSysBlockStat[PATH_MAX];
snprintf(pathSysBlockStat, PATH_MAX, "/sys/block/%s/stat", devName);
char pathSysBlock[PATH_MAX];
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/stat", devName);
FF_AUTO_CLOSE_FILE FILE* sysBlockStat = fopen(pathSysBlockStat, "r");
FF_AUTO_CLOSE_FILE FILE* sysBlockStat = fopen(pathSysBlock, "r");
if (!sysBlockStat) continue;
// I/Os merges sectors ticks ...
@@ -73,19 +73,19 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
ffStrbufInitNS(&device->name, (uint32_t) (slash2 - slash - 1), slash + 1);
else
ffStrbufInitS(&device->name, slash + 1);
ffStrbufInitNS(&device->type, (uint32_t) (slash - entry->d_name), entry->d_name);
ffStrbufInitNS(&device->interconnect, (uint32_t) (slash - entry->d_name), entry->d_name);
}
else
{
ffStrbufInitS(&device->name, entry->d_name);
ffStrbufInit(&device->type);
ffStrbufInit(&device->interconnect);
}
ffStrbufReplaceAllC(&device->name, '_', ' ');
if (options->namePrefix.length && !ffStrbufStartsWith(&device->name, &options->namePrefix))
{
ffStrbufDestroy(&device->name);
ffStrbufDestroy(&device->type);
ffStrbufDestroy(&device->interconnect);
result->length--;
continue;
}
@@ -95,6 +95,13 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
device->bytesWritten = sectorWritten * 512;
device->readCount = nRead;
device->writeCount = nWritten;
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/queue/rotational", devName);
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
if (ffReadFileBuffer(pathSysBlock, &buffer))
device->type = ffStrbufEqualS(&buffer, "1") ? FF_DISKIO_PHYSICAL_TYPE_HDD : FF_DISKIO_PHYSICAL_TYPE_SSD;
else
device->type = FF_DISKIO_PHYSICAL_TYPE_UNKNOWN;
}
return NULL;
+22 -3
View File
@@ -31,14 +31,14 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
{
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
ffStrbufInit(&device->name);
ffStrbufInit(&device->type);
ffStrbufInit(&device->interconnect);
if (ffRegReadStrbuf(hKey, pNum, &device->name, NULL))
{
// SCSI\Disk&Ven_NVMe&Prod_WDC_PC_SN810_SDC\5&19cebb7&0&000000
uint32_t index = ffStrbufFirstIndexC(&device->name, '\\');
if (index != device->name.length)
{
ffStrbufAppendNS(&device->type, index, device->name.chars); // SCSI
ffStrbufAppendNS(&device->interconnect, index, device->name.chars); // SCSI
ffStrbufSubstrAfter(&device->name, index + 1);
}
ffStrbufSubstrBeforeLastC(&device->name, '\\');
@@ -53,7 +53,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
if (options->namePrefix.length && !ffStrbufStartsWith(&device->name, &options->namePrefix))
{
ffStrbufDestroy(&device->name);
ffStrbufDestroy(&device->type);
ffStrbufDestroy(&device->interconnect);
result->length--;
continue;
}
@@ -63,6 +63,25 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
device->readCount = (uint64_t) diskPerformance.ReadCount;
device->bytesWritten = (uint64_t) diskPerformance.BytesWritten.QuadPart;
device->writeCount = (uint64_t) diskPerformance.WriteCount;
DEVICE_SEEK_PENALTY_DESCRIPTOR dspd = {};
DWORD retSize = 0;
if(DeviceIoControl(
hDevice,
IOCTL_STORAGE_QUERY_PROPERTY,
&(STORAGE_PROPERTY_QUERY) {
.PropertyId = StorageDeviceSeekPenaltyProperty,
.QueryType = PropertyStandardQuery,
},
sizeof(STORAGE_PROPERTY_QUERY),
&dspd,
sizeof(dspd),
&retSize,
NULL
) && retSize == sizeof(dspd))
device->type = dspd.IncursSeekPenalty ? FF_DISKIO_PHYSICAL_TYPE_HDD : FF_DISKIO_PHYSICAL_TYPE_SSD;
else
device->type = FF_DISKIO_PHYSICAL_TYPE_UNKNOWN;
}
}
-27
View File
@@ -112,19 +112,6 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
bool isExternal = !!(disk->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT);
bool isReadOnly = !!(disk->type & FF_DISK_VOLUME_TYPE_READONLY_BIT);
const char* physicalType;
switch(disk->physicalType)
{
case FF_DISK_PHYSICAL_TYPE_HDD:
physicalType = "HDD";
break;
case FF_DISK_PHYSICAL_TYPE_SSD:
physicalType = "SSD";
break;
default:
physicalType = "Unknown";
break;
}
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
@@ -137,7 +124,6 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem},
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->name},
{FF_FORMAT_ARG_TYPE_BOOL, &isReadOnly},
{FF_FORMAT_ARG_TYPE_STRING, physicalType}
});
}
}
@@ -429,19 +415,6 @@ void ffGenerateDiskJson(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_
yyjson_mut_arr_add_str(doc, typeArr, "Hidden");
if(item->type & FF_DISK_VOLUME_TYPE_READONLY_BIT)
yyjson_mut_arr_add_str(doc, typeArr, "Read-only");
switch(item->physicalType)
{
case FF_DISK_PHYSICAL_TYPE_HDD:
yyjson_mut_obj_add_str(doc, obj, "physicalType", "HDD");
break;
case FF_DISK_PHYSICAL_TYPE_SSD:
yyjson_mut_obj_add_str(doc, obj, "physicalType", "SSD");
break;
default:
yyjson_mut_obj_add_null(doc, obj, "physicalType");
break;
}
}
FF_LIST_FOR_EACH(FFDisk, item, disks)
+40 -12
View File
@@ -28,7 +28,6 @@ static void formatKey(const FFDiskIOOptions* options, FFDiskIOResult* dev, uint3
ffParseFormatString(key, &options->moduleArgs.key, 2, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT, &index},
{FF_FORMAT_ARG_TYPE_STRBUF, &dev->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &dev->type},
{FF_FORMAT_ARG_TYPE_STRBUF, &dev->devPath},
});
}
@@ -75,11 +74,26 @@ void ffPrintDiskIO(FFDiskIOOptions* options)
ffParseSize(dev->bytesWritten, &buffer2);
ffStrbufAppendS(&buffer2, "/s");
const char* physicalType;
switch(dev->type)
{
case FF_DISKIO_PHYSICAL_TYPE_HDD:
physicalType = "HDD";
break;
case FF_DISKIO_PHYSICAL_TYPE_SSD:
physicalType = "SSD";
break;
default:
physicalType = "Unknown";
break;
}
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISKIO_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &buffer},
{FF_FORMAT_ARG_TYPE_STRBUF, &buffer2},
{FF_FORMAT_ARG_TYPE_STRBUF, &dev->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &dev->type},
{FF_FORMAT_ARG_TYPE_STRBUF, &dev->interconnect},
{FF_FORMAT_ARG_TYPE_STRING, physicalType},
{FF_FORMAT_ARG_TYPE_STRBUF, &dev->devPath},
{FF_FORMAT_ARG_TYPE_UINT64, &dev->bytesRead},
{FF_FORMAT_ARG_TYPE_UINT64, &dev->bytesWritten},
@@ -93,7 +107,7 @@ void ffPrintDiskIO(FFDiskIOOptions* options)
FF_LIST_FOR_EACH(FFDiskIOResult, dev, result)
{
ffStrbufDestroy(&dev->name);
ffStrbufDestroy(&dev->type);
ffStrbufDestroy(&dev->interconnect);
ffStrbufDestroy(&dev->devPath);
}
}
@@ -163,22 +177,36 @@ void ffGenerateDiskIOJson(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
FF_LIST_FOR_EACH(FFDiskIOResult, counter, result)
FF_LIST_FOR_EACH(FFDiskIOResult, dev, result)
{
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
yyjson_mut_obj_add_strbuf(doc, obj, "name", &counter->name);
yyjson_mut_obj_add_strbuf(doc, obj, "type", &counter->type);
yyjson_mut_obj_add_strbuf(doc, obj, "devPath", &counter->devPath);
yyjson_mut_obj_add_uint(doc, obj, "bytesRead", counter->bytesRead);
yyjson_mut_obj_add_uint(doc, obj, "bytesWritten", counter->bytesWritten);
yyjson_mut_obj_add_uint(doc, obj, "readCount", counter->readCount);
yyjson_mut_obj_add_uint(doc, obj, "writeCount", counter->writeCount);
yyjson_mut_obj_add_strbuf(doc, obj, "name", &dev->name);
yyjson_mut_obj_add_strbuf(doc, obj, "interconnect", &dev->interconnect);
yyjson_mut_obj_add_strbuf(doc, obj, "devPath", &dev->devPath);
switch(dev->type)
{
case FF_DISKIO_PHYSICAL_TYPE_HDD:
yyjson_mut_obj_add_str(doc, obj, "type", "HDD");
break;
case FF_DISKIO_PHYSICAL_TYPE_SSD:
yyjson_mut_obj_add_str(doc, obj, "type", "SSD");
break;
default:
yyjson_mut_obj_add_null(doc, obj, "type");
break;
}
yyjson_mut_obj_add_uint(doc, obj, "bytesRead", dev->bytesRead);
yyjson_mut_obj_add_uint(doc, obj, "bytesWritten", dev->bytesWritten);
yyjson_mut_obj_add_uint(doc, obj, "readCount", dev->readCount);
yyjson_mut_obj_add_uint(doc, obj, "writeCount", dev->writeCount);
}
FF_LIST_FOR_EACH(FFDiskIOResult, dev, result)
{
ffStrbufDestroy(&dev->name);
ffStrbufDestroy(&dev->type);
ffStrbufDestroy(&dev->interconnect);
ffStrbufDestroy(&dev->devPath);
}
}