From 643db92cd1d827976418e2b612bb9ebabfd2c8ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Apr 2026 15:08:02 +0800 Subject: [PATCH] PhysicalDisk (Linux): adds type unknown detection --- .../physicaldisk/physicaldisk_linux.c | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/detection/physicaldisk/physicaldisk_linux.c b/src/detection/physicaldisk/physicaldisk_linux.c index f21a3cef4..50e4999d8 100644 --- a/src/detection/physicaldisk/physicaldisk_linux.c +++ b/src/detection/physicaldisk/physicaldisk_linux.c @@ -27,6 +27,17 @@ static double detectNvmeTemp(int devfd) { } static void parsePhysicalDisk(int dfd, const char* devName, FFPhysicalDiskOptions* options, FFlist* result) { + uint64_t size = 0; + + { + char blkSize[32]; + ssize_t fileSize = ffReadFileDataRelative(dfd, "size", ARRAY_SIZE(blkSize) - 1, blkSize); + if (fileSize > 0) { + blkSize[fileSize] = 0; + size = (uint64_t) strtoul(blkSize, NULL, 10) * 512; + } + } + int devfd = openat(dfd, "device", O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY); FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate(); @@ -75,8 +86,9 @@ static void parsePhysicalDisk(int dfd, const char* devName, FFPhysicalDiskOption ffStrbufInit(&device->serial); ffStrbufInit(&device->revision); ffStrbufInit(&device->interconnect); - device->type = devfd > 0 ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_VIRTUAL; - device->size = 0; + device->type = (devfd > 0 ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_VIRTUAL) | + (size > 0 ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_UNKNOWN); + device->size = size; device->temperature = FF_PHYSICALDISK_TEMP_UNSET; bool isVirtio = false; @@ -132,17 +144,6 @@ static void parsePhysicalDisk(int dfd, const char* devName, FFPhysicalDiskOption } } - { - char blkSize[32]; - ssize_t fileSize = ffReadFileDataRelative(dfd, "size", ARRAY_SIZE(blkSize) - 1, blkSize); - if (fileSize > 0) { - blkSize[fileSize] = 0; - device->size = (uint64_t) strtoul(blkSize, NULL, 10) * 512; - } else { - device->size = 0; - } - } - { char removableChar = '0'; if (ffReadFileDataRelative(dfd, "removable", 1, &removableChar) > 0) {