mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Disk (Windows): detect disk physical type
This commit is contained in:
@@ -5,6 +5,13 @@
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
typedef enum FFDiskPhysicalType
|
||||
{
|
||||
FF_DISK_TYPE_UNKNOWN,
|
||||
FF_DISK_TYPE_HDD,
|
||||
FF_DISK_TYPE_SSD,
|
||||
} FFDiskPhysicalType;
|
||||
|
||||
typedef struct FFDisk
|
||||
{
|
||||
FFstrbuf mountFrom;
|
||||
@@ -12,6 +19,7 @@ typedef struct FFDisk
|
||||
FFstrbuf filesystem;
|
||||
FFstrbuf name;
|
||||
FFDiskVolumeType type;
|
||||
FFDiskPhysicalType physicalType;
|
||||
|
||||
uint64_t bytesUsed;
|
||||
uint64_t bytesFree;
|
||||
|
||||
@@ -64,14 +64,15 @@ const char* ffDetectDisksImpl(FFlist* disks)
|
||||
if(!ffStrStartsWith(fs->f_mntfromname, "/dev/") && !ffStrEquals(fs->f_fstypename, "zfs"))
|
||||
continue;
|
||||
|
||||
FFDisk* disk = ffListAdd(disks);
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
// f_bavail and f_ffree are signed on FreeBSD...
|
||||
if(fs->f_bavail < 0) fs->f_bavail = 0;
|
||||
if(fs->f_ffree < 0) fs->f_ffree = 0;
|
||||
#endif
|
||||
|
||||
FFDisk* disk = ffListAdd(disks);
|
||||
disk->physicalType = FF_DISK_TYPE_UNKNOWN;
|
||||
|
||||
disk->bytesTotal = fs->f_blocks * fs->f_bsize;
|
||||
disk->bytesFree = (uint64_t)fs->f_bfree * fs->f_bsize;
|
||||
disk->bytesAvailable = (uint64_t)fs->f_bavail * fs->f_bsize;
|
||||
|
||||
@@ -277,6 +277,7 @@ 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_TYPE_UNKNOWN;
|
||||
|
||||
//detect mountFrom
|
||||
ffStrbufInitS(&disk->mountFrom, device->mnt_fsname);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "disk.h"
|
||||
#include "common/io/io.h"
|
||||
#include "util/windows/unicode.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <winioctl.h>
|
||||
#include <assert.h>
|
||||
|
||||
const char* ffDetectDisksImpl(FFlist* disks)
|
||||
@@ -26,8 +28,37 @@ const char* ffDetectDisksImpl(FFlist* disks)
|
||||
ffStrbufInitWS(&disk->mountpoint, mountpoint);
|
||||
|
||||
wchar_t volumeName[64];
|
||||
|
||||
disk->physicalType = FF_DISK_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 = {};
|
||||
if(DeviceIoControl(
|
||||
handle,
|
||||
IOCTL_STORAGE_QUERY_PROPERTY,
|
||||
&(STORAGE_PROPERTY_QUERY) {
|
||||
.PropertyId = StorageDeviceSeekPenaltyProperty,
|
||||
.QueryType = PropertyStandardQuery,
|
||||
},
|
||||
sizeof(STORAGE_PROPERTY_QUERY),
|
||||
&dspd,
|
||||
sizeof(dspd),
|
||||
NULL,
|
||||
NULL
|
||||
))
|
||||
disk->physicalType = dspd.IncursSeekPenalty ? FF_DISK_TYPE_HDD : FF_DISK_TYPE_SSD;
|
||||
}
|
||||
}
|
||||
|
||||
if(GetVolumeNameForVolumeMountPointW(mountpoint, volumeName, sizeof(volumeName) / sizeof(*volumeName)))
|
||||
{
|
||||
ffStrbufInitWS(&disk->mountFrom, volumeName);
|
||||
}
|
||||
else
|
||||
ffStrbufInit(&disk->mountFrom);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user