@@ -27,6 +27,17 @@ static double detectNvmeTemp(int devfd) {
2727}
2828
2929static void parsePhysicalDisk (int dfd , const char * devName , FFPhysicalDiskOptions * options , FFlist * result ) {
30+ uint64_t size = 0 ;
31+
32+ {
33+ char blkSize [32 ];
34+ ssize_t fileSize = ffReadFileDataRelative (dfd , "size" , ARRAY_SIZE (blkSize ) - 1 , blkSize );
35+ if (fileSize > 0 ) {
36+ blkSize [fileSize ] = 0 ;
37+ size = (uint64_t ) strtoul (blkSize , NULL , 10 ) * 512 ;
38+ }
39+ }
40+
3041 int devfd = openat (dfd , "device" , O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY );
3142
3243 FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate ();
@@ -75,8 +86,9 @@ static void parsePhysicalDisk(int dfd, const char* devName, FFPhysicalDiskOption
7586 ffStrbufInit (& device -> serial );
7687 ffStrbufInit (& device -> revision );
7788 ffStrbufInit (& device -> interconnect );
78- device -> type = devfd > 0 ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_VIRTUAL ;
79- device -> size = 0 ;
89+ device -> type = (devfd > 0 ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_VIRTUAL ) |
90+ (size > 0 ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_UNKNOWN );
91+ device -> size = size ;
8092 device -> temperature = FF_PHYSICALDISK_TEMP_UNSET ;
8193
8294 bool isVirtio = false;
@@ -132,17 +144,6 @@ static void parsePhysicalDisk(int dfd, const char* devName, FFPhysicalDiskOption
132144 }
133145 }
134146
135- {
136- char blkSize [32 ];
137- ssize_t fileSize = ffReadFileDataRelative (dfd , "size" , ARRAY_SIZE (blkSize ) - 1 , blkSize );
138- if (fileSize > 0 ) {
139- blkSize [fileSize ] = 0 ;
140- device -> size = (uint64_t ) strtoul (blkSize , NULL , 10 ) * 512 ;
141- } else {
142- device -> size = 0 ;
143- }
144- }
145-
146147 {
147148 char removableChar = '0' ;
148149 if (ffReadFileDataRelative (dfd , "removable" , 1 , & removableChar ) > 0 ) {
0 commit comments