@@ -927,65 +927,86 @@ void get_disk_stats_ioservice (char verbose) {
927
927
io_iterator_t dlist = 0 ;
928
928
mach_port_t port = 0 ;
929
929
io_registry_entry_t disk = 0 ;
930
- io_registry_entry_t name_plane = 0 ;
931
930
CFDictionaryRef props = 0 ;
931
+ CFDictionaryRef props2 = 0 ;
932
932
CFDictionaryRef dstats = 0 ;
933
933
CFNumberRef value = NULL ;
934
- io_name_t name ;
934
+ CFMutableDictionaryRef match ;
935
+ io_registry_entry_t parent ;
936
+ io_name_t name ;
937
+ char deviceFilePath [MAXPATHLEN ]; //MAXPATHLEN is defined in sys/param.h
938
+ CFStringRef name_str ;
935
939
936
940
t_iface_speed_stats stats ; /* local struct, used to calc total values */
937
941
t_iface_speed_stats tmp_if_stats ;
938
942
memset (& stats ,0 ,(size_t )sizeof (t_iface_speed_stats )); /* init it */
939
943
940
944
if (IOMasterPort (MACH_PORT_NULL , & port ))
941
945
deinit (1 ,"failure while initializing disk port\n" );
942
-
943
- if (IOServiceGetMatchingServices (port ,IOServiceMatching ("IOBlockStorageDriver" ),& dlist ))
946
+ match = IOServiceMatching ("IOMedia" );
947
+ CFDictionaryAddValue (match , CFSTR (kIOMediaWholeKey ), kCFBooleanTrue );
948
+ if (IOServiceGetMatchingServices (port , match , & dlist )!= KERN_SUCCESS )
944
949
deinit (1 ,"failure while getting disk list\n" );
945
-
946
950
while ( (disk = IOIteratorNext (dlist )) ) {
947
951
IORegistryEntryCreateCFProperties (disk ,(CFMutableDictionaryRef * ) & props ,kCFAllocatorDefault ,kNilOptions );
948
952
if (props ) {
949
- dstats = CFDictionaryGetValue (props , CFSTR (kIOBlockStorageDriverStatisticsKey ));
950
- if (dstats ) {
951
- value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsBytesReadKey ));
952
- if (value )
953
- CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .bytes .in );
954
- value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsBytesWrittenKey ));
955
- if (value )
956
- CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .bytes .out );
957
- value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsReadsKey ));
958
- if (value )
959
- CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .packets .in );
960
- value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsWritesKey ));
961
- if (value )
962
- CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .packets .out );
963
- value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsReadErrorsKey ));
964
- if (value )
965
- CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .errors .in );
966
- value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsWriteErrorsKey ));
967
- if (value )
968
- CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .errors .out );
969
- if (IORegistryEntryGetChildEntry (disk , kIOServicePlane , & name_plane ) || IORegistryEntryGetName (name_plane , name )) {
970
- strncpy ((char * )name ,(char * )"unknown" ,sizeof (name )- 1 );
971
- name [sizeof (name )- 1 ]= 0 ;
953
+ if (!long_darwin_disk_names ) {
954
+ name_str = (CFStringRef )CFDictionaryGetValue (props , CFSTR (kIOBSDNameKey ));
955
+ if (name_str ) {
956
+ CFStringGetCString (name_str , deviceFilePath , MAXPATHLEN - 1 , CFStringGetSystemEncoding ());
972
957
} else {
973
- if (name_plane ) {
974
- IOObjectRelease (name_plane );
975
- name_plane = 0 ;
976
- }
958
+ snprintf ((char * )deviceFilePath ,MAXPATHLEN - 1 ,"unknown%i" ,current_if_num );
959
+ deviceFilePath [MAXPATHLEN - 1 ]= 0 ;
960
+ }
961
+ } else {
962
+ if (IORegistryEntryGetName (disk , name )!= KERN_SUCCESS ) {
963
+ snprintf ((char * )name ,sizeof (name )- 1 ,"unknown%i" ,current_if_num );
964
+ name [sizeof (name )- 1 ]= 0 ;
965
+ }
966
+ }
967
+ if (IORegistryEntryGetParentEntry (disk , kIOServicePlane , & parent )!= KERN_SUCCESS ) {
968
+ CFRelease (props );
969
+ IOObjectRelease (disk );
970
+ IOIteratorReset (dlist );
971
+ deinit (1 ,"disk has no parent\n" );
972
+ }
973
+ IORegistryEntryCreateCFProperties (parent , (CFMutableDictionaryRef * )& props2 ,kCFAllocatorDefault , kNilOptions );
974
+ if (props2 ) {
975
+ dstats = CFDictionaryGetValue (props2 , CFSTR (kIOBlockStorageDriverStatisticsKey ));
976
+ if (dstats ) {
977
+ value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsBytesReadKey ));
978
+ if (value )
979
+ CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .bytes .in );
980
+ value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsBytesWrittenKey ));
981
+ if (value )
982
+ CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .bytes .out );
983
+ value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsReadsKey ));
984
+ if (value )
985
+ CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .packets .in );
986
+ value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsWritesKey ));
987
+ if (value )
988
+ CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .packets .out );
989
+ value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsReadErrorsKey ));
990
+ if (value )
991
+ CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .errors .in );
992
+ value = CFDictionaryGetValue (dstats ,CFSTR (kIOBlockStorageDriverStatisticsWriteErrorsKey ));
993
+ if (value )
994
+ CFNumberGetValue (value , kCFNumberSInt64Type , & tmp_if_stats .errors .out );
995
+ hidden_if = process_if_data (hidden_if , tmp_if_stats , & stats , long_darwin_disk_names ? (char * )name : deviceFilePath
996
+ , current_if_num , verbose ,(tmp_if_stats .bytes .in != 0 || tmp_if_stats .bytes .out != 0 ));
997
+ current_if_num ++ ;
977
998
}
978
- hidden_if = process_if_data (hidden_if , tmp_if_stats , & stats , name , current_if_num , verbose ,(tmp_if_stats .bytes .in != 0 || tmp_if_stats .bytes .out != 0 ));
979
- current_if_num ++ ;
999
+ CFRelease (props2 );
980
1000
}
1001
+ IOObjectRelease (parent );
981
1002
CFRelease (props );
982
1003
props = 0 ;
983
1004
}
984
1005
IOObjectRelease (disk );
985
1006
disk = 0 ;
986
1007
}
987
1008
finish_iface_stats (verbose , stats , hidden_if ,current_if_num );
988
- IOIteratorReset (dlist );
1009
+ IOObjectRelease (dlist );
989
1010
}
990
1011
#endif
991
1012
0 commit comments