PhysicalDisk: detect temp

This commit is contained in:
李通洲
2023-12-26 19:23:26 +08:00
parent 0ee892f2de
commit 0972eb6986
7 changed files with 70 additions and 0 deletions
@@ -1,5 +1,7 @@
#include "fastfetch.h"
#define FF_PHYSICALDISK_TEMP_UNSET (0/0.0)
typedef enum FFPhysicalDiskType
{
FF_PHYSICALDISK_TYPE_NONE = 0,
@@ -24,6 +26,7 @@ typedef struct FFPhysicalDiskResult
FFstrbuf revision;
FFPhysicalDiskType type;
uint64_t size;
double temperature;
} FFPhysicalDiskResult;
const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options);
@@ -92,6 +92,7 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
}
}
}
device->temperature = FF_PHYSICALDISK_TEMP_UNSET;
}
return NULL;
@@ -67,6 +67,7 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
type |= acw ? FF_PHYSICALDISK_TYPE_READONLY : FF_PHYSICALDISK_TYPE_READWRITE;
device->type = type;
device->temperature = FF_PHYSICALDISK_TEMP_UNSET;
}
geom_stats_snapshot_free(snap);
@@ -1,6 +1,7 @@
#include "physicaldisk.h"
#include "common/io/io.h"
#include "common/properties.h"
#include "detection/temps/temps_linux.h"
#include "util/stringUtils.h"
#include <ctype.h>
@@ -129,6 +130,21 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
if (ffReadFileBuffer(pathSysBlock, &device->revision))
ffStrbufTrimRightSpace(&device->revision);
}
device->temperature = FF_PHYSICALDISK_TEMP_UNSET;
if (options->temp)
{
const FFlist* tempsResult = ffDetectTemps();
FF_LIST_FOR_EACH(FFTempValue, value, *tempsResult)
{
if (ffStrStartsWith(devName, value->deviceName.chars)) // nvme0 - nvme0n1
{
device->temperature = value->value;
break;
}
}
}
}
return NULL;
@@ -151,6 +151,26 @@ static bool detectPhysicalDisk(const wchar_t* szDevice, FFlist* result, FFPhysic
device->size = (uint64_t) diskInfo->NumberMediaSides * diskInfo->TracksPerCylinder * diskInfo->SectorsPerTrack * diskInfo->BytesPerSector;
}
device->temperature = FF_PHYSICALDISK_TEMP_UNSET;
if (options->temp)
{
STORAGE_TEMPERATURE_DATA_DESCRIPTOR stdd = {};
if(DeviceIoControl(
hDevice,
IOCTL_STORAGE_QUERY_PROPERTY,
&(STORAGE_PROPERTY_QUERY) {
.PropertyId = StorageDeviceTemperatureProperty,
.QueryType = PropertyStandardQuery,
},
sizeof(STORAGE_PROPERTY_QUERY),
&stdd,
sizeof(stdd),
&retSize,
NULL
) && retSize == sizeof(stdd))
device->temperature = stdd.TemperatureInfo[0].Temperature;
}
return true;
}