Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
985264d
Fastfetch: add `Directx Headers` to `--list-features`
CarterLi Oct 2, 2023
1985552
Disk (Windows): fix crashing on Windows 7 VM
CarterLi Oct 3, 2023
be86006
Users (Windows): fix crashing caused by uninitialized strings
CarterLi Oct 3, 2023
3eb9ace
Doc: update changelog
CarterLi Oct 3, 2023
1a4eb25
DisplayServer (Linux): add debug log for #568
CarterLi Oct 2, 2023
4a89b92
Disk: allow custiomize disk key with `mountFrom`
CarterLi Oct 3, 2023
27581d9
Disk (macOS): detect physical type
CarterLi Oct 3, 2023
f8aafb7
Monitor (macOS): better intel platform support
CarterLi Oct 3, 2023
8795d99
Brightness: add DDC/CI support for Intel
CarterLi Oct 4, 2023
9972c61
Sound (macOS): support non-controllable devices
CarterLi Oct 4, 2023
f78f97a
Revert "DisplayServer (Linux): add debug log for #568"
CarterLi Oct 4, 2023
1dfa031
Fix several `--help` command related issues (#572)
iamrasel Oct 5, 2023
23d2cc3
Version: print libc version used when compiling
CarterLi Oct 5, 2023
12208b2
Global: improve support of `--help *-format`
CarterLi Oct 7, 2023
c77a758
Packages (Linux): support opkg
CarterLi Oct 7, 2023
d7ef7bc
Doc: update changelog
CarterLi Oct 7, 2023
4c96d04
TerminalShell (Linux): add `ash` as a known shell
CarterLi Oct 7, 2023
41551ef
Sound: fix typo
CarterLi Oct 7, 2023
3077f88
Sound (macOS): ignore input devices
CarterLi Oct 7, 2023
90ea096
macOS: don't keep variable `matchDict`
CarterLi Oct 7, 2023
fe4eb56
NetIO: add missing `#pragma once`
CarterLi Oct 7, 2023
55f0f75
Packages (Linux): print opkg in JSON format
CarterLi Oct 7, 2023
b1d63e0
NetIO: fix `--help netio-format`
CarterLi Oct 7, 2023
276e22f
DiskIO: init module
CarterLi Oct 7, 2023
e4a6bf1
Terminal: support kgx (gnome console)
CarterLi Oct 8, 2023
49e2acd
Printing: fix `--help *-format`
CarterLi Oct 8, 2023
d7649d9
DiskIO: fix building
CarterLi Oct 8, 2023
4c9d9f6
TerminalFont (Linux): fix typo
CarterLi Oct 8, 2023
78249bf
CPU: add new option `--cpu-freq-ndigits`
CarterLi Oct 8, 2023
085d092
Brightness (Linux): try improving compatibility of ddcutil 2.0
CarterLi Oct 8, 2023
b213047
DiskIO (macOS): add support
CarterLi Oct 8, 2023
0b0e286
DiskIO: support `--diskio-name-prefix`
CarterLi Oct 8, 2023
5c5c66d
DiskIO: fix segfault...
CarterLi Oct 8, 2023
8df6409
DiskIO (Windows): better device name detection
CarterLi Oct 8, 2023
1f23e93
Logo: add Chimera Linux
JamiKettunen Oct 5, 2023
dc50e24
Doc: update changelog and readme
CarterLi Oct 8, 2023
2e60f34
DiskIO: add to `presets/all`
CarterLi Oct 8, 2023
fa46dce
CMake: detect uclibc and musl version
CarterLi Oct 8, 2023
685676b
CMake: don't hardcode system arch
CarterLi Oct 9, 2023
1188db9
CMake: simplify musl version detection
CarterLi Oct 9, 2023
430da15
Libc (macOS): detect `libSystem` version
CarterLi Oct 9, 2023
2d2e0dd
Libc (FreeBSD): detect FBSD version
CarterLi Oct 9, 2023
b76d6e9
DiskIO (FreeBSD): add support
CarterLi Oct 9, 2023
5ccd196
DiskIO: print `devPath`
CarterLi Oct 9, 2023
44b417d
DiskIO (FreeBSD): skip `/dev/pass*`
CarterLi Oct 9, 2023
a0343d6
CI: run `--format json`
CarterLi Oct 9, 2023
4194e56
DiskIO (Windows): better name detection for Github Action
CarterLi Oct 9, 2023
8fa6aee
Disk: move `physicalType` to module `DiskIO`
CarterLi Oct 9, 2023
d16bdb3
DiskIO: update formatting help messages; update json keys
CarterLi Oct 9, 2023
ccbb252
DiskIO: update doc and json schema
CarterLi Oct 9, 2023
42f6d02
Doc: update JSON schema; make it more IDE friendly
CarterLi Oct 9, 2023
e7df944
Temp (FreeBSD): improve CPU temp detection
CarterLi Oct 10, 2023
2feb531
Revert "CpuUsage (apple): simplify implementation"
CarterLi Oct 10, 2023
c96d21c
CPUUsage (Linux): count cpu cores separately
CarterLi Oct 10, 2023
6b008ed
CPUUsage (FreeBSD): count cpu cores separately
CarterLi Oct 10, 2023
42cf88b
CPUUsage: support display value per core
CarterLi Oct 10, 2023
e297144
CPUUsage: fix multi core data detection
CarterLi Oct 10, 2023
0847432
CPUUsage: rename `cpuusage-display-type` to `separate`
CarterLi Oct 10, 2023
4e75fa9
Logo (Builtin): add EndeavourSmall
CarterLi Oct 10, 2023
5493f41
Users: fix crashing on Windows; rename `tty` to more common name `ses…
CarterLi Oct 10, 2023
ab8448e
DiskIO (Windows): fix device name detection
CarterLi Oct 10, 2023
e319be1
Wifi (macOS): print `<unknown ssid>` when we can't get SSID
CarterLi Oct 11, 2023
1fe9273
macOS: embed `Info.plist`
CarterLi Oct 11, 2023
076324e
Wifi (macOS): remove undesired code
CarterLi Oct 11, 2023
643fed7
Doc: metion bug #581
CarterLi Oct 11, 2023
5827886
Doc: add information about how to make `Termux API` actually work
CarterLi Oct 11, 2023
ebab281
Processes (Linux): fix implementation
CarterLi Oct 11, 2023
839ff31
Wifi (macOS): work around #581
CarterLi Oct 13, 2023
42e87b4
Brightness (Linux): allow specifying busno for ddcutil
CarterLi Oct 13, 2023
af94596
Revert "Brightness (Linux): allow specifying busno for ddcutil"
CarterLi Oct 14, 2023
e9c2a43
Brightness: add `--brightness-ddcci-sleep` to set the sleep times (in…
CarterLi Oct 14, 2023
501803c
Logo (Builtin): add Xenia
CarterLi Oct 14, 2023
5e19838
Doc: update changelog
CarterLi Oct 14, 2023
98e8e59
Release v2.1.1
CarterLi Oct 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Disk: move physicalType to module DiskIO
Physical type applies to physical disks, not partitions
  • Loading branch information
CarterLi committed Oct 9, 2023
commit 8fa6aee571539f9c0c38c5a9528488e02dee765d
8 changes: 0 additions & 8 deletions src/detection/disk/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@

#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;
FFstrbuf mountpoint;
FFstrbuf filesystem;
FFstrbuf name;
FFDiskVolumeType type;
FFDiskPhysicalType physicalType;

uint64_t bytesUsed;
uint64_t bytesFree;
Expand Down
50 changes: 0 additions & 50 deletions src/detection/disk/disk_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,13 @@ 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;
attrreference_t volNameRef;
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)
Expand All @@ -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

Expand All @@ -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;
Expand Down
22 changes: 5 additions & 17 deletions src/detection/disk/disk_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 0 additions & 28 deletions src/detection/disk/disk_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/detection/diskio/diskio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions src/detection/diskio/diskio_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/detection/diskio/diskio_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
19 changes: 13 additions & 6 deletions src/detection/diskio/diskio_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
25 changes: 22 additions & 3 deletions src/detection/diskio/diskio_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, '\\');
Expand All @@ -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;
}
Expand All @@ -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;
}
}

Expand Down
Loading