diff --git a/src/detection/physicaldisk/physicaldisk_linux.c b/src/detection/physicaldisk/physicaldisk_linux.c index b5a3bbc2a..5d78f57ba 100644 --- a/src/detection/physicaldisk/physicaldisk_linux.c +++ b/src/detection/physicaldisk/physicaldisk_linux.c @@ -7,6 +7,29 @@ #include #include +static double detectNvmeTemp(const char* devName) +{ + char pathSysBlock[PATH_MAX]; + int index = snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/hwmon$/temp1_input", devName); + if (index <= 0) return FF_PHYSICALDISK_TEMP_UNSET; + index -= (int) sizeof("/temp1_input"); + + for (char c = '0'; c <= '9'; c++) // hopefully there's only one digit + { + pathSysBlock[index] = c; + char buffer[64]; + ssize_t size = ffReadFileData(pathSysBlock, sizeof(buffer), buffer); + if (size > 0) + { + buffer[size] = '\0'; + double temp = strtod(buffer, NULL); + return temp > 0 ? temp / 1000 : FF_PHYSICALDISK_TEMP_UNSET; + } + } + + return FF_PHYSICALDISK_TEMP_UNSET; +} + const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) { FF_AUTO_CLOSE_DIR DIR* sysBlockDirp = opendir("/sys/block/"); @@ -157,20 +180,10 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) } } - 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; - } - } - } + device->temperature = detectNvmeTemp(devName); + else + device->temperature = FF_PHYSICALDISK_TEMP_UNSET; } return NULL;