33#include "sys/scsi/generic/inquiry.h"
44
55#include <libdevinfo.h>
6+ #include <sys/stat.h>
67
78struct FFWalkTreeBundle
89{
910 FFPhysicalDiskOptions * options ;
1011 FFlist * disks ;
1112};
1213
13- static int walkDevTree (di_node_t node , struct FFWalkTreeBundle * bundle )
14+ static int walkDevTree (di_node_t node , di_minor_t minor , struct FFWalkTreeBundle * bundle )
1415{
15- if (ffStrEquals (di_node_name (node ), "sd" ))
16+ if (di_minor_spectype (minor ) != S_IFCHR || !ffStrEquals (di_minor_name (minor ), "a,raw" )) return DI_WALK_CONTINUE ;
17+
18+ char * productId ;
19+ char * vendorId ;
20+ if (di_prop_lookup_strings (DDI_DEV_T_ANY , node , "inquiry-product-id" , & productId ) > 0
21+ && di_prop_lookup_strings (DDI_DEV_T_ANY , node , "inquiry-vendor-id" , & vendorId ) > 0 )
1622 {
17- char * productId ;
18- char * vendorId ;
19- if (di_prop_lookup_strings (DDI_DEV_T_ANY , node , "inquiry-product-id" , & productId ) > 0
20- && di_prop_lookup_strings (DDI_DEV_T_ANY , node , "inquiry-vendor-id" , & vendorId ) > 0 )
21- {
22- FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateF ("%s %s" , vendorId , productId );
23- if (bundle -> options -> namePrefix .length && !ffStrbufStartsWithIgnCase (& name , & bundle -> options -> namePrefix ))
24- return DI_WALK_CONTINUE ;
23+ FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateF ("%s %s" , vendorId , productId );
24+ if (bundle -> options -> namePrefix .length && !ffStrbufStartsWithIgnCase (& name , & bundle -> options -> namePrefix ))
25+ return DI_WALK_CONTINUE ;
2526
26- FFPhysicalDiskResult * device = (FFPhysicalDiskResult * ) ffListAdd (bundle -> disks );
27- ffStrbufInitMove (& device -> name , & name );
28- ffStrbufInit (& device -> devPath );
29- ffStrbufInit (& device -> serial );
30- ffStrbufInit (& device -> revision );
31- ffStrbufInit (& device -> interconnect );
32- device -> temperature = FF_PHYSICALDISK_TEMP_UNSET ;
33- device -> type = FF_PHYSICALDISK_TYPE_NONE ;
34- device -> size = 0 ;
27+ FFPhysicalDiskResult * device = (FFPhysicalDiskResult * ) ffListAdd (bundle -> disks );
28+ ffStrbufInitMove (& device -> name , & name );
29+ ffStrbufInitF (& device -> devPath , "/devices%s" , di_devfs_path ( node ) );
30+ ffStrbufInit (& device -> serial );
31+ ffStrbufInit (& device -> revision );
32+ ffStrbufInit (& device -> interconnect );
33+ device -> temperature = FF_PHYSICALDISK_TEMP_UNSET ;
34+ device -> type = FF_PHYSICALDISK_TYPE_NONE ;
35+ device -> size = 0 ;
3536
36- char * buf ;
37- if (di_prop_lookup_strings (DDI_DEV_T_ANY , node , "inquiry-serial-no" , & buf ) > 0 )
38- ffStrbufSetS (& device -> serial , buf );
39- if (di_prop_lookup_strings (DDI_DEV_T_ANY , node , "inquiry-revision-id" , & buf ) > 0 )
40- ffStrbufSetS (& device -> revision , buf );
41- if (di_prop_lookup_strings (DDI_DEV_T_ANY , node , "class" , & buf ) > 0 )
42- ffStrbufSetS (& device -> interconnect , buf );
37+ char * buf ;
38+ if (di_prop_lookup_strings (DDI_DEV_T_ANY , node , "inquiry-serial-no" , & buf ) > 0 )
39+ ffStrbufSetS (& device -> serial , buf );
40+ if (di_prop_lookup_strings (DDI_DEV_T_ANY , node , "inquiry-revision-id" , & buf ) > 0 )
41+ ffStrbufSetS (& device -> revision , buf );
42+ if (di_prop_lookup_strings (DDI_DEV_T_ANY , node , "class" , & buf ) > 0 )
43+ ffStrbufSetS (& device -> interconnect , buf );
4344
44- device -> type |= di_prop_find (DDI_DEV_T_ANY , node , "removable-media" ) ? FF_PHYSICALDISK_TYPE_REMOVABLE : FF_PHYSICALDISK_TYPE_FIXED ;
45+ device -> type |= di_prop_find (DDI_DEV_T_ANY , node , "removable-media" ) ? FF_PHYSICALDISK_TYPE_REMOVABLE : FF_PHYSICALDISK_TYPE_FIXED ;
4546
46- int * value ;
47- if (di_prop_lookup_ints (DDI_DEV_T_ANY , node , "device-solid-state" , & value ) > 0 )
48- device -> type |= * value ? FF_PHYSICALDISK_TYPE_SSD : FF_PHYSICALDISK_TYPE_HDD ;
49- if (di_prop_lookup_ints (DDI_DEV_T_ANY , node , "inquiry-device-type" , & value ) > 0 )
50- device -> type |= * value == DTYPE_DIRECT ? FF_PHYSICALDISK_TYPE_READWRITE : * value == DTYPE_RODIRECT ? FF_PHYSICALDISK_TYPE_READONLY : 0 ;
47+ int * value ;
48+ if (di_prop_lookup_ints (DDI_DEV_T_ANY , node , "device-solid-state" , & value ) > 0 )
49+ device -> type |= * value ? FF_PHYSICALDISK_TYPE_SSD : FF_PHYSICALDISK_TYPE_HDD ;
50+ if (di_prop_lookup_ints (DDI_DEV_T_ANY , node , "inquiry-device-type" , & value ) > 0 )
51+ device -> type |= * value == DTYPE_DIRECT ? FF_PHYSICALDISK_TYPE_READWRITE : * value == DTYPE_RODIRECT ? FF_PHYSICALDISK_TYPE_READONLY : 0 ;
5152
52- int64_t * nblocks ;
53- if (di_prop_lookup_int64 (DDI_DEV_T_ANY , node , "device-nblocks" , & nblocks ) > 0
54- && di_prop_lookup_ints (DDI_DEV_T_ANY , node , "device-blksize" , & value ) > 0 )
55- device -> size = (uint64_t ) ((uint64_t ) * nblocks * (uint64_t ) * value );
56- }
53+ int64_t * nblocks ;
54+ if (di_prop_lookup_int64 (DDI_DEV_T_ANY , node , "device-nblocks" , & nblocks ) > 0
55+ && di_prop_lookup_ints (DDI_DEV_T_ANY , node , "device-blksize" , & value ) > 0 )
56+ device -> size = (uint64_t ) ((uint64_t ) * nblocks * (uint64_t ) * value );
5757 }
5858
5959 return DI_WALK_CONTINUE ;
@@ -64,7 +64,7 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
6464 di_node_t rootNode = di_init ("/" , DINFOCPYALL );
6565 if (rootNode == DI_NODE_NIL )
6666 return "di_init() failed" ;
67- di_walk_node (rootNode , DI_WALK_CLDFIRST , & (struct FFWalkTreeBundle ) { options , result }, (void * ) walkDevTree );
67+ di_walk_minor (rootNode , DDI_NT_BLOCK , DI_WALK_CLDFIRST , & (struct FFWalkTreeBundle ) { options , result }, (void * ) walkDevTree );
6868 di_fini (rootNode );
6969
7070 return NULL ;
0 commit comments