Skip to content

Commit 89bc7eb

Browse files
committed
DiskIO: move device info detected in PhysicalDisk module
1 parent 3cd81ec commit 89bc7eb

File tree

7 files changed

+13
-241
lines changed

7 files changed

+13
-241
lines changed

src/detection/diskio/diskio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ const char* ffDetectDiskIO(FFlist* result, FFDiskIOOptions* options)
4747
{
4848
FFDiskIOResult* icPrev = (FFDiskIOResult*)ffListGet(&ioCounters1, i);
4949
FFDiskIOResult* icCurr = (FFDiskIOResult*)ffListGet(result, i);
50-
if (!ffStrbufEqual(&icPrev->name, &icCurr->name))
51-
return "Physical disk name changed";
50+
if (!ffStrbufEqual(&icPrev->devPath, &icCurr->devPath))
51+
return "Physical disk device path changed";
5252

5353
static_assert(sizeof(FFDiskIOResult) - offsetof(FFDiskIOResult, bytesRead) == sizeof(uint64_t) * 4, "Unexpected struct FFDiskIOResult layout");
5454
for (size_t off = offsetof(FFDiskIOResult, bytesRead); off < sizeof(FFDiskIOResult); off += sizeof(uint64_t))

src/detection/diskio/diskio.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,10 @@
22

33
#include "fastfetch.h"
44

5-
typedef enum FFDiskIOPhysicalType
6-
{
7-
FF_DISKIO_PHYSICAL_TYPE_UNKNOWN,
8-
FF_DISKIO_PHYSICAL_TYPE_HDD,
9-
FF_DISKIO_PHYSICAL_TYPE_SSD,
10-
} FFDiskIOPhysicalType;
11-
125
typedef struct FFDiskIOResult
136
{
147
FFstrbuf name;
15-
FFstrbuf interconnect;
16-
FFstrbuf serial;
178
FFstrbuf devPath;
18-
FFDiskIOPhysicalType type;
19-
uint64_t size;
20-
bool removable;
219
uint64_t bytesRead;
2210
uint64_t readCount;
2311
uint64_t bytesWritten;

src/detection/diskio/diskio_apple.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,8 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
4646
continue;
4747

4848
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
49-
ffStrbufInit(&device->serial);
5049
ffStrbufInitS(&device->name, deviceName);
5150
ffStrbufInit(&device->devPath);
52-
device->removable = false;
53-
device->type = FF_DISKIO_PHYSICAL_TYPE_UNKNOWN;
54-
device->size = 0;
55-
56-
FF_CFTYPE_AUTO_RELEASE CFBooleanRef removable = IORegistryEntryCreateCFProperty(entryPartition, CFSTR(kIOMediaRemovableKey), kCFAllocatorDefault, kNilOptions);
57-
device->removable = !!CFBooleanGetValue(removable);
5851

5952
ffCfDictGetInt64(statistics, CFSTR(kIOBlockStorageDriverStatisticsBytesReadKey), (int64_t*) &device->bytesRead);
6053
ffCfDictGetInt64(statistics, CFSTR(kIOBlockStorageDriverStatisticsBytesWrittenKey), (int64_t*) &device->bytesWritten);
@@ -67,36 +60,6 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
6760
ffCfStrGetString(bsdName, &device->devPath);
6861
ffStrbufPrependS(&device->devPath, "/dev/");
6962
}
70-
71-
FF_CFTYPE_AUTO_RELEASE CFNumberRef mediaSize = IORegistryEntryCreateCFProperty(entryPartition, CFSTR(kIOMediaSizeKey), kCFAllocatorDefault, kNilOptions);
72-
if (mediaSize)
73-
ffCfNumGetInt64(mediaSize, (int64_t*) &device->size);
74-
else
75-
device->size = 0;
76-
77-
ffStrbufInit(&device->interconnect);
78-
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryPhysical = 0;
79-
if (IORegistryEntryGetParentEntry(entryDriver, kIOServicePlane, &entryPhysical) == KERN_SUCCESS)
80-
{
81-
FF_CFTYPE_AUTO_RELEASE CFDictionaryRef protocolCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyProtocolCharacteristicsKey), kCFAllocatorDefault, kNilOptions);
82-
if (protocolCharacteristics)
83-
ffCfDictGetString(protocolCharacteristics, CFSTR(kIOPropertyPhysicalInterconnectTypeKey), &device->interconnect);
84-
85-
FF_CFTYPE_AUTO_RELEASE CFDictionaryRef deviceCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyDeviceCharacteristicsKey), kCFAllocatorDefault, kNilOptions);
86-
if (deviceCharacteristics)
87-
{
88-
ffCfDictGetString(deviceCharacteristics, CFSTR(kIOPropertyProductSerialNumberKey), &device->serial);
89-
90-
CFStringRef mediumType = (CFStringRef) CFDictionaryGetValue(deviceCharacteristics, CFSTR(kIOPropertyMediumTypeKey));
91-
if (mediumType)
92-
{
93-
if (CFStringCompare(mediumType, CFSTR(kIOPropertyMediumTypeSolidStateKey), 0) == 0)
94-
device->type = FF_DISKIO_PHYSICAL_TYPE_SSD;
95-
else if (CFStringCompare(mediumType, CFSTR(kIOPropertyMediumTypeRotationalKey), 0) == 0)
96-
device->type = FF_DISKIO_PHYSICAL_TYPE_HDD;
97-
}
98-
}
99-
}
10063
}
10164

10265
return NULL;

src/detection/diskio/diskio_bsd.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,25 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
3232
if (provider->lg_geom->lg_rank != 1)
3333
continue;
3434

35-
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateS(provider->lg_name);
36-
FF_STRBUF_AUTO_DESTROY identifier = ffStrbufCreate();
37-
FFDiskIOPhysicalType type = FF_DISKIO_PHYSICAL_TYPE_UNKNOWN;
35+
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
3836
for (struct gconfig* ptr = provider->lg_config.lh_first; ptr; ptr = ptr->lg_config.le_next)
3937
{
4038
if (ffStrEquals(ptr->lg_name, "descr"))
4139
ffStrbufSetS(&name, ptr->lg_val);
42-
else if (ffStrEquals(ptr->lg_name, "rotationrate") && !ffStrEquals(ptr->lg_val, "unknown"))
43-
type = ffStrEquals(ptr->lg_val, "0") ? FF_DISKIO_PHYSICAL_TYPE_SSD : FF_DISKIO_PHYSICAL_TYPE_HDD;
44-
else if (ffStrEquals(ptr->lg_name, "ident"))
45-
ffStrbufSetS(&identifier, ptr->lg_val);
4640
}
41+
if (name.length == 0)
42+
ffStrbufSetS(&name, provider->lg_name);
4743

4844
if (options->namePrefix.length && !ffStrbufStartsWith(&name, &options->namePrefix))
4945
continue;
5046

5147
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
5248
ffStrbufInitF(&device->devPath, "/dev/%s", provider->lg_name);
53-
ffStrbufInitMove(&device->serial, &identifier);
54-
ffStrbufInit(&device->interconnect);
55-
device->removable = false;
56-
switch (snapIter->device_type & DEVSTAT_TYPE_IF_MASK)
57-
{
58-
case DEVSTAT_TYPE_IF_SCSI: ffStrbufAppendS(&device->interconnect, "SCSI"); break;
59-
case DEVSTAT_TYPE_IF_IDE: ffStrbufAppendS(&device->interconnect, "IDE"); break;
60-
case DEVSTAT_TYPE_IF_OTHER: ffStrbufAppendS(&device->interconnect, "OTHER"); break;
61-
}
6249
device->bytesRead = snapIter->bytes[DEVSTAT_READ];
6350
device->readCount = snapIter->operations[DEVSTAT_READ];
6451
device->bytesWritten = snapIter->bytes[DEVSTAT_WRITE];
6552
device->writeCount = snapIter->operations[DEVSTAT_WRITE];
66-
device->size = (uint64_t) provider->lg_mediasize;
6753
ffStrbufInitMove(&device->name, &name);
68-
device->type = type;
6954
}
7055

7156
geom_stats_snapshot_free(snap);

src/detection/diskio/diskio_linux.c

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
2020
if (devName[0] == '.')
2121
continue;
2222

23-
2423
char pathSysBlock[PATH_MAX];
2524
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s", devName);
2625

@@ -58,22 +57,6 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
5857
}
5958
}
6059

61-
{
62-
ffStrbufInit(&device->interconnect);
63-
if (strstr(pathSysDeviceReal, "/usb") != NULL)
64-
ffStrbufSetS(&device->interconnect, "usb");
65-
else
66-
{
67-
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/transport", devName);
68-
if (!ffAppendFileBuffer(pathSysBlock, &device->interconnect))
69-
{
70-
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/uevent", devName);
71-
if (ffParsePropFile(pathSysBlock, "DEVTYPE=", &device->interconnect))
72-
ffStrbufSubstrBeforeLastC(&device->interconnect, '_');
73-
}
74-
}
75-
}
76-
7760
// I/Os merges sectors ticks ...
7861
uint64_t nRead, sectorRead, nWritten, sectorWritten;
7962
{
@@ -91,40 +74,6 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
9174
device->bytesWritten = sectorWritten * 512;
9275
device->readCount = nRead;
9376
device->writeCount = nWritten;
94-
95-
{
96-
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/queue/rotational", devName);
97-
char isRotationalChar = '1';
98-
if (ffReadFileData(pathSysBlock, 1, &isRotationalChar))
99-
device->type = isRotationalChar == '1' ? FF_DISKIO_PHYSICAL_TYPE_HDD : FF_DISKIO_PHYSICAL_TYPE_SSD;
100-
else
101-
device->type = FF_DISKIO_PHYSICAL_TYPE_UNKNOWN;
102-
}
103-
104-
{
105-
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/size", devName);
106-
char blkSize[32];
107-
ssize_t fileSize = ffReadFileData(pathSysBlock, sizeof(blkSize) - 1, blkSize);
108-
if (fileSize > 0)
109-
{
110-
blkSize[fileSize] = 0;
111-
device->size = (uint64_t) strtoul(blkSize, NULL, 10) * 512;
112-
}
113-
else
114-
device->size = 0;
115-
}
116-
117-
{
118-
char removableChar = '0';
119-
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/removable", devName);
120-
device->removable = removableChar == '1';
121-
}
122-
123-
{
124-
ffStrbufInit(&device->serial);
125-
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/serial", devName);
126-
ffReadFileBuffer(pathSysBlock, &device->serial);
127-
}
12877
}
12978

13079
return NULL;

src/detection/diskio/diskio_windows.c

Lines changed: 6 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "diskio.h"
22
#include "common/io/io.h"
3-
#include "util/windows/registry.h"
43
#include "util/windows/unicode.h"
54

5+
#include <windows.h>
66
#include <winioctl.h>
77

88
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
@@ -52,13 +52,18 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
5252
ffStrbufTrimRight(&device->name, ' ');
5353
}
5454

55+
if (!device->name.length)
56+
ffStrbufAppendF(&device->name, "PhysicalDrive%u", (unsigned) idev);
57+
5558
if (options->namePrefix.length && !ffStrbufStartsWith(&device->name, &options->namePrefix))
5659
{
5760
ffStrbufDestroy(&device->name);
5861
result->length--;
5962
continue;
6063
}
6164

65+
ffStrbufInitWS(&device->devPath, szDevice);
66+
6267
DISK_PERFORMANCE dp = {};
6368
if (DeviceIoControl(hDevice, IOCTL_DISK_PERFORMANCE, NULL, 0, &dp, sizeof(dp), &retSize, NULL))
6469
{
@@ -73,74 +78,6 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
7378
result->length--;
7479
continue;
7580
}
76-
77-
ffStrbufInitWS(&device->devPath, szDevice);
78-
ffStrbufInit(&device->serial);
79-
if (sdd->SerialNumberOffset != 0)
80-
{
81-
ffStrbufSetS(&device->serial, (const char*) sddBuffer + sdd->SerialNumberOffset);
82-
ffStrbufTrim(&device->serial, ' ');
83-
}
84-
85-
device->removable = !!sdd->RemovableMedia;
86-
87-
ffStrbufInit(&device->interconnect);
88-
switch (sdd->BusType)
89-
{
90-
case BusTypeUnknown: ffStrbufSetStatic(&device->interconnect, "Unknown"); break;
91-
case BusTypeScsi: ffStrbufSetStatic(&device->interconnect, "Scsi"); break;
92-
case BusTypeAtapi: ffStrbufSetStatic(&device->interconnect, "Atapi"); break;
93-
case BusTypeAta: ffStrbufSetStatic(&device->interconnect, "Ata"); break;
94-
case BusType1394: ffStrbufSetStatic(&device->interconnect, "1394"); break;
95-
case BusTypeSsa: ffStrbufSetStatic(&device->interconnect, "Ssa"); break;
96-
case BusTypeFibre: ffStrbufSetStatic(&device->interconnect, "Fibra"); break;
97-
case BusTypeUsb: ffStrbufSetStatic(&device->interconnect, "Usb"); break;
98-
case BusTypeRAID: ffStrbufSetStatic(&device->interconnect, "RAID"); break;
99-
case BusTypeiScsi: ffStrbufSetStatic(&device->interconnect, "iScsi"); break;
100-
case BusTypeSas: ffStrbufSetStatic(&device->interconnect, "Sas"); break;
101-
case BusTypeSata: ffStrbufSetStatic(&device->interconnect, "Sata"); break;
102-
case BusTypeSd: ffStrbufSetStatic(&device->interconnect, "Sd"); break;
103-
case BusTypeMmc: ffStrbufSetStatic(&device->interconnect, "Mmc"); break;
104-
case BusTypeVirtual: ffStrbufSetStatic(&device->interconnect, "Virtual"); break;
105-
case BusTypeFileBackedVirtual: ffStrbufSetStatic(&device->interconnect, "FileBackedVirtual"); break;
106-
case BusTypeSpaces: ffStrbufSetStatic(&device->interconnect, "Spaces"); break;
107-
case BusTypeNvme: ffStrbufSetStatic(&device->interconnect, "Nvme"); break;
108-
case BusTypeSCM: ffStrbufSetStatic(&device->interconnect, "SCM"); break;
109-
case BusTypeUfs: ffStrbufSetStatic(&device->interconnect, "Ufs"); break;
110-
default: ffStrbufSetF(&device->interconnect, "Unknown (%d)", (int) sdd->BusType); break;
111-
}
112-
113-
DEVICE_SEEK_PENALTY_DESCRIPTOR dspd = {};
114-
if(DeviceIoControl(
115-
hDevice,
116-
IOCTL_STORAGE_QUERY_PROPERTY,
117-
&(STORAGE_PROPERTY_QUERY) {
118-
.PropertyId = StorageDeviceSeekPenaltyProperty,
119-
.QueryType = PropertyStandardQuery,
120-
},
121-
sizeof(STORAGE_PROPERTY_QUERY),
122-
&dspd,
123-
sizeof(dspd),
124-
&retSize,
125-
NULL
126-
) && retSize == sizeof(dspd))
127-
device->type = dspd.IncursSeekPenalty ? FF_DISKIO_PHYSICAL_TYPE_HDD : FF_DISKIO_PHYSICAL_TYPE_SSD;
128-
else
129-
device->type = FF_DISKIO_PHYSICAL_TYPE_UNKNOWN;
130-
131-
DISK_GEOMETRY_EX dge = {};
132-
if(DeviceIoControl(
133-
hDevice,
134-
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
135-
NULL,
136-
0,
137-
&dge,
138-
sizeof(dge),
139-
&retSize,
140-
NULL))
141-
device->size = (uint64_t) dge.DiskSize.QuadPart;
142-
else
143-
device->size = 0;
14481
}
14582

14683
return NULL;

0 commit comments

Comments
 (0)