Skip to content

Commit da15e6e

Browse files
author
vgropp
committed
default to bsd names on ioservice input, optional long disknames
git-svn-id: https://svn.code.sf.net/p/bwmng/code/trunk@115 9d038f78-4a1f-0410-99f9-a7e0acc80b06
1 parent 490f3b1 commit da15e6e

File tree

7 files changed

+89
-37
lines changed

7 files changed

+89
-37
lines changed

bwm-ng.1

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ or 1 (on), if the value is not given '1' is used.
218218
.TP
219219
.BI "-N, --ansiout "
220220
disable ANSI Codes for Plain output.
221+
.TP
222+
.BI " --longdisknames "
223+
show long realnames of disks in Darwin (ioservice input)
221224

222225
.SS OTHER
223226
These options specify the general behavior of \fBbwm-ng\fP.

bwm-ng.conf-example

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ UNIT=bits
33
PROCFILE=/proc/net/dev
44
DISKSTATSFILE=/proc/diskstats
55
PARTITIONSFILE=/proc/partitions
6+
LONGDISKNAMES=0
67
ANSIOUT=0
78
OUTPUT=plain
89
TIMEOUT=666

src/bwm-ng.c

+4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ inline void init() {
173173
strncpy(PROC_PARTITIONS_FILE,PROC_PARTITIONS,PATH_MAX);
174174
#endif
175175

176+
#if IOSERVICE_IN
177+
long_darwin_disk_names = 0;
178+
#endif
179+
176180
}
177181

178182
/* do the main thing */

src/global_vars.h

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ EXTERN int html_header;
8585
EXTERN int skfd;
8686
#endif
8787

88+
#if IOSERVICE_IN
89+
EXTERN char long_darwin_disk_names;
90+
#endif
91+
8892
EXTERN t_iface_stats *if_stats;
8993
/* total struct */
9094
EXTERN t_iface_stats if_stats_total;

src/options.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ char *token, *value;
235235
if (value) daemonize=value[0]=='0' ? 0 : 1;
236236
} else if( strcasecmp( token, "SUMHIDDEN" ) == 0 ) {
237237
if (value) sumhidden=value[0]=='0' ? 0 : 1;
238+
#if IOSERVICE_IN
239+
} else if( strcasecmp( token, "LONGDISKNAMES" ) == 0) {
240+
if (value) long_darwin_disk_names=value[0]=='0' ? 0 : 1;
241+
#endif
238242
#ifdef HTML
239243
} else if( strcasecmp( token, "HTMLREFRESH" ) == 0 ) {
240244
if (value && atol(value)>0) { html_refresh=atol(value); }
@@ -271,14 +275,17 @@ void get_cmdln_options(int argc, char *argv[]) {
271275
#endif
272276
#if NETSTAT && ALLOW_NETSTATPATH
273277
{"netstat",1,0,'n'},
278+
#endif
279+
#if IOSERVICE_IN
280+
{"longdisknames",0,0,1002},
274281
#endif
275282
{"input",1,0,'i'},
276283
{"dynamic",1,0,'d'},
277284
{"help", 0, 0, 'h'},
278285
{"version",0,0,'V'},
279286
{"allif",1,0,'a'},
280287
{"unit",1,0,'u'},
281-
{"ansiout",1,0,'N'},
288+
{"ansiout",0,0,'N'},
282289
#if EXTENDED_STATS
283290
{"type",1,0,'T'},
284291
{"avglength",1,0,'A'},
@@ -362,10 +369,17 @@ void get_cmdln_options(int argc, char *argv[]) {
362369
case 1000:
363370
if (strlen(optarg)<PATH_MAX)
364371
strcpy(PROC_DISKSTATS_FILE,optarg);
372+
break;
365373
case 1001:
366374
if (strlen(optarg)<PATH_MAX)
367375
strcpy(PROC_PARTITIONS_FILE,optarg);
368-
#endif
376+
break;
377+
#endif
378+
#if IOSERVICE_IN
379+
case 1002:
380+
long_darwin_disk_names=!long_darwin_disk_names;
381+
break;
382+
#endif
369383
case 'D':
370384
if (optarg) daemonize=atoi(optarg);
371385
break;

src/retrieve.c

+56-35
Original file line numberDiff line numberDiff line change
@@ -927,65 +927,86 @@ void get_disk_stats_ioservice (char verbose) {
927927
io_iterator_t dlist = 0;
928928
mach_port_t port = 0;
929929
io_registry_entry_t disk = 0;
930-
io_registry_entry_t name_plane = 0;
931930
CFDictionaryRef props = 0;
931+
CFDictionaryRef props2 = 0;
932932
CFDictionaryRef dstats = 0;
933933
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;
935939

936940
t_iface_speed_stats stats; /* local struct, used to calc total values */
937941
t_iface_speed_stats tmp_if_stats;
938942
memset(&stats,0,(size_t)sizeof(t_iface_speed_stats)); /* init it */
939943

940944
if (IOMasterPort(MACH_PORT_NULL, &port))
941945
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)
944949
deinit(1,"failure while getting disk list\n");
945-
946950
while ( (disk = IOIteratorNext(dlist)) ) {
947951
IORegistryEntryCreateCFProperties (disk,(CFMutableDictionaryRef *) &props,kCFAllocatorDefault,kNilOptions);
948952
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());
972957
} 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++;
977998
}
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);
9801000
}
1001+
IOObjectRelease(parent);
9811002
CFRelease(props);
9821003
props = 0;
9831004
}
9841005
IOObjectRelease(disk);
9851006
disk = 0;
9861007
}
9871008
finish_iface_stats (verbose, stats, hidden_if,current_if_num);
988-
IOIteratorReset(dlist);
1009+
IOObjectRelease(dlist);
9891010
}
9901011
#endif
9911012

src/retrieve.h

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989
#include <CoreFoundation/CoreFoundation.h>
9090
#include <IOKit/IOKitLib.h>
9191
#include <IOKit/storage/IOBlockStorageDriver.h>
92+
#include <IOKit/storage/IOMedia.h>
93+
#ifndef LONG_DARWIN_DEV_NAMES
94+
#include <IOKit/IOBSD.h>
95+
#include <paths.h>
96+
#endif
9297
#endif
9398

9499

0 commit comments

Comments
 (0)