1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
|
/*
* info_solaris.cpp
*
* Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/mnttab.h>
#include <kstat.h>
#include <sys/types.h>
#include <sys/statvfs.h>
#include <time.h>
#ifdef HAVE_LIBDEVINFO_H
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <sys/mkdev.h>
#include <sys/stat.h>
#include <devid.h>
#include <libdevinfo.h>
#endif /* HAVE_LIBDEVINFO_H */
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_PCI_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
bool GetInfo_CPU( TQListView *lBox ) {
kstat_ctl_t *kctl;
kstat_t *ksp;
kstat_named_t *kdata;
char cputype[16],
fputype[16];
char *timetxt;
char *ptr;
uint32_t i, ncpus;
unsigned long state_begin;
QString state;
QString mhz;
QString inst;
/*
* get a kstat handle first and update the user's kstat chain
*/
if( (kctl = kstat_open()) == NULL ) {
return false;
}
while( kstat_chain_update( kctl ) != 0 )
;
/*
* get the # of CPUs
*/
if( (ksp = kstat_lookup( kctl, "unix", 0, "system_misc" )) == NULL ) {
return false;
}
if( kstat_read( kctl, ksp, NULL ) == -1 ) {
return false;
}
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "ncpus" );
if( kdata != NULL ) {
ncpus = kdata->value.ui32;
} else {
ncpus = 0;
}
lBox->addColumn( i18n( "Instance" ));
lBox->addColumn( i18n( "CPU Type" ));
lBox->addColumn( i18n( "FPU Type" ));
lBox->addColumn( i18n( "MHz" ));
lBox->addColumn( i18n( "State" ));
/*
* get the per-processor info
*/
for( i = 0; i < ncpus; i++ ) {
if( (ksp = kstat_lookup( kctl, "cpu_info", i, NULL )) == NULL ){
return false;
}
if( kstat_read( kctl, ksp, NULL ) == -1 ) {
return false;
}
inst.setNum( i );
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "cpu_type" );
if( kdata != NULL ) {
strcpy( cputype, kdata->value.c );
} else {
sprintf( cputype, "???" );
}
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "fpu_type" );
if( kdata != NULL ) {
strcpy( fputype, kdata->value.c );
} else {
sprintf( fputype, "???" );
}
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "clock_MHz" );
if( kdata != NULL ) {
mhz.setNum( kdata->value.ul );
} else {
mhz.setNum( 0 );
}
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "state" );
if( kdata != NULL ) {
state = TQString( kdata->value.c );
} else {
state = "???";
}
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "state_begin" );
if( kdata != NULL ) {
state_begin = kdata->value.i32;
if( (timetxt = ctime( (time_t *) &state_begin )) != NULL ) {
ptr = strrchr( timetxt, '\n' );
*ptr = '\0';
state += " since " + TQString( timetxt );
}
}
new TQListViewItem( lBox, inst, cputype, fputype, mhz, state );
}
// sorting_allowed = true;
lBox->setSorting( 0 );
return true;
}
bool GetInfo_IRQ( TQListView * ) {
return false;
}
bool GetInfo_DMA( TQListView * ) {
return false;
}
bool GetInfo_PCI( TQListView * ) {
return false;
}
bool GetInfo_IO_Ports( TQListView * ) {
return false;
}
bool GetInfo_Sound( TQListView * ) {
return false;
}
bool GetInfo_SCSI( TQListView * ) {
return false;
}
bool GetInfo_Partitions( TQListView *lBox ) {
FILE *mnttab;
struct mnttab mnt;
struct statvfs statbuf;
fsblkcnt_t tmp;
QString total;
QString avail;
time_t mnttime;
char *timetxt;
char *ptr;
if( (mnttab = fopen( MNTTAB, "r" )) == NULL ) {
return false;
}
/*
* set up column headers
*/
lBox->addColumn( i18n( "Device" ));
lBox->addColumn( i18n( "Mount Point" ));
lBox->addColumn( i18n( "FS Type" ));
lBox->addColumn( i18n( "Total Size" ));
// XXX: FIXME: how do I set column alignment correctly?
lBox->setColumnAlignment( 3, 2 );
lBox->addColumn( i18n( "Free Size" ));
// XXX: FIXME: how do I set column alignment correctly?
lBox->setColumnAlignment( 4, 2 );
lBox->addColumn( i18n( "Mount Time" ));
lBox->addColumn( i18n( "Mount Options" ));
/*
* get info about mounted file systems
*/
rewind( mnttab );
while( getmntent( mnttab, &mnt ) == 0 ) {
/*
* skip fstype "nfs" and "autofs" for two reasons:
* o if the mountpoint is visible, the fs is not
* necessarily available (autofs option "-nobrowse")
* and we don't want to mount every remote fs just
* to get its size, do we?
* o the name "Partitions" for this statistics implies
* "local file systems only"
*/
if( (strcmp( mnt.mnt_fstype, "nfs" ) == 0)
|| (strcmp( mnt.mnt_fstype, "autofs" ) == 0) )
continue;
if( statvfs( mnt.mnt_mountp, &statbuf ) == 0 ) {
if( statbuf.f_blocks > 0 ) {
/*
* produce output in KB, MB, or GB for
* readability -- unfortunately, this
* breaks sorting for these columns...
*/
tmp = statbuf.f_blocks
* (statbuf.f_frsize / 1024);
if( tmp > 9999 ) {
tmp /= 1024;
if( tmp > 9999 ) {
tmp /= 1024;
total.setNum( tmp );
total += " G";
} else {
total.setNum( tmp );
total += " M";
}
} else {
total.setNum( tmp );
total += " K";
}
// avail.setNum( statbuf.f_bavail );
// avail += " K";
tmp = statbuf.f_bavail
* (statbuf.f_frsize / 1024);
if( tmp > 9999 ) {
tmp /= 1024;
if( tmp > 9999 ) {
tmp /= 1024;
avail.setNum( tmp );
avail += " G";
} else {
avail.setNum( tmp );
avail += " M";
}
} else {
avail.setNum( tmp );
avail += " K";
}
} else {
total = "-";
avail = "-";
}
} else {
total = "???";
avail = "???";
}
/*
* ctime() adds a '\n' which we have to remove
* so that we get a one-line output for the QListViewItem
*/
mnttime = (time_t) atol( mnt.mnt_time );
if( (timetxt = ctime( &mnttime )) != NULL ) {
ptr = strrchr( timetxt, '\n' );
*ptr = '\0';
}
new TQListViewItem(
lBox,
mnt.mnt_special,
mnt.mnt_mountp,
mnt.mnt_fstype,
total,
avail,
TQString( timetxt ),
mnt.mnt_mntopts
);
}
fclose( mnttab );
lBox->setSorting( 0 );
// sorting_allowed = true;
return true;
}
bool GetInfo_XServer_and_Video( TQListView *lBox ) {
return GetInfo_XServer_Generic( lBox );
}
#ifdef HAVE_LIBDEVINFO_H
/*
* get Solaris' device configuration data through libdevinfo(3)
* and display it in a prtconf(1M) style tree
*
* NOTE: though the devinfo library seems to be present on earlier
* Solaris releases, this interface is documented to be available
* since Solaris 7 (libdevinfo.h is missing on pre-Solaris 7 systems)
*
* documentation for libdevinfo(3) including code samples on which
* this implementation is based on is available at
* http://soldc.sun.com/developer/support/driver/wps/libdevinfo/
*/
/*
* we start with various helper routines for GetInfo_Devices()
*/
/*
* mktree() -- break up the device path and place its components
* into the tree widget
*/
TQListViewItem *mktree( TQListViewItem *top, const char *path ) {
QListViewItem *parent,
*previous,
*result;
char *str = strdup( path ),
*token;
/*
* start at "/"
*/
parent = top;
result = (*top).firstChild();
previous = (*top).firstChild();
token = strtok( str, "/" );
while( token != NULL ) {
/*
* find insert pos:
* try to match the node at the current level
*
* NOTE: this implementation assumes that there are
* no two nodes with identical names at the
* same level of the device tree
*/
while( result != NULL ) {
if( strcmp( token, (*result).text( 0 ).latin1()) == 0 )
break;
previous = result;
result = (*result).nextSibling();
}
if( result == NULL ) {
/*
* we haven't found the node, create a new one
*/
result = new TQListViewItem( parent,
previous,
token );
} else {
/*
* we've found the node
*/
parent = result;
previous = NULL;
if( (*result).firstChild() == NULL ) {
/*
* create new node during next iteration
*/
result->setExpandable( true );
result->setOpen( false );
} else {
/*
* follow the child path
*/
result = (*result).firstChild();
}
}
token = strtok( NULL, "/" );
}
free( str );
return( result );
}
/*
* prop_type_str() -- return the property type as a string
*/
char *prop_type_str( di_prop_t prop ) {
switch( di_prop_type( prop )) {
case DI_PROP_TYPE_UNDEF_IT:
return( "undefined" );
case DI_PROP_TYPE_BOOLEAN:
return( "BOOL" );
case DI_PROP_TYPE_INT:
return( "INT" );
case DI_PROP_TYPE_STRING:
return( "STRING" );
case DI_PROP_TYPE_BYTE:
return( "BYTE" );
default:
return( "unknown" );
}
}
/*
* prop_type_guess() -- guess the property type
*/
int prop_type_guess( uchar_t *data, int len ) {
int slen;
int guess;
int i, c;
if( len < 0 )
return( -1 );
else if( len == 0 )
return( DI_PROP_TYPE_BOOLEAN );
slen = 0;
guess = DI_PROP_TYPE_STRING;
for( i = 0; i < len; i++ ) {
c = (int) data[i];
switch( c ) {
case 0:
if( i == (len - 1 ))
break;
if( slen == 0 )
guess = DI_PROP_TYPE_BYTE;
else
guess = slen = 0;
break;
default:
if( ! isprint( c ))
guess = DI_PROP_TYPE_BYTE;
else
slen++;
}
if( guess != DI_PROP_TYPE_STRING )
break;
}
// if( (guess == DI_PROP_TYPE_BYTE) && (len % sizeof( int ) == 0 ))
// guess = DI_PROP_TYPE_INT;
return( guess );
}
/*
* dump_minor_node() -- examine a device minor node
* this routine gets passed to di_walk_node()
*/
int dump_minor_node( di_node_t node, di_minor_t minor, void *arg ) {
QListViewItem *item;
QString majmin;
char *type;
dev_t dev;
item = new TQListViewItem( (TQListViewItem *) arg,
di_minor_name( minor ));
item->setExpandable( true );
item->setOpen( false );
new TQListViewItem( item, i18n( "Spectype:" ),
(di_minor_spectype( minor ) == S_IFCHR)
? i18n( "character special" )
: i18n( "block special" ));
type = di_minor_nodetype( minor );
new TQListViewItem( item, i18n( "Nodetype:" ),
(type == NULL) ? "NULL" : type );
if( (dev = di_minor_devt( minor )) != DDI_DEV_T_NONE ) {
majmin.sprintf( "%ld/%ld", major( dev ), minor( dev ));
new TQListViewItem( item, i18n( "Major/Minor:" ), majmin );
}
if( di_minor_next( node, minor ) == DI_MINOR_NIL )
return( DI_WALK_TERMINATE );
else
return( DI_WALK_CONTINUE );
}
/*
* propvalue() -- return the property value
*/
TQString propvalue( di_prop_t prop ) {
int type;
int i, n;
char *strp;
int *intp;
uchar_t *bytep;
QString result;
/*
* Since a lot of printable strings seem to be tagged as 'byte',
* we're going to guess, if the property is not STRING or INT
* The actual type is shown in the info tree, though.
*/
type = di_prop_type( prop );
if( (type != DI_PROP_TYPE_STRING) && (type != DI_PROP_TYPE_INT) ) {
n = di_prop_bytes( prop, &bytep );
type = prop_type_guess( bytep, n );
}
result = "";
switch( type ) {
case DI_PROP_TYPE_STRING:
if( (n = di_prop_strings( prop, &strp )) < 0 ) {
result = "(error)";
} else {
for( i = 0; i < n; i++ ) {
result += "\"";
result += strp;
result += "\" ";
strp += strlen( strp ) + 1;
}
}
break;
case DI_PROP_TYPE_INT:
if( (n = di_prop_ints( prop, &intp )) < 0 ) {
result = "(error)";
} else {
for( i = 0; i < n; i++ ) {
TQString tmp;
tmp.setNum( intp[i] );
result += tmp;
result += " ";
}
}
break;
case DI_PROP_TYPE_BOOLEAN:
/*
* hmm, Sun's sample code handles the existence
* of a boolean property as "true", whereas
* prtconf(1M) obviously does not (Sol8, at least)
* -- we're doing the same and handle "bool" as "byte"
*/
case DI_PROP_TYPE_BYTE:
if( (n = di_prop_bytes( prop, &bytep )) < 0 ) {
result = "(error)";
} else {
if( n == 0 ) {
result = i18n( "(no value)" );
break;
}
result = "0x";
for( i = 0; i < n; i++ ) {
TQString tmp;
unsigned byte = (unsigned) bytep[i];
tmp.sprintf( "%2.2x", byte );
result += tmp;
}
}
break;
default:
result = "???";
}
return( result );
}
/*
* dump_node() -- examine a device node and its children
* this routine gets passed to di_walk_node()
*/
int dump_node( di_node_t node, void *arg ) {
QListViewItem *top = (TQListViewItem *) arg,
*parent,
*previous;
char *path;
char *drivername;
char *names;
QString compatnames;
int i, n;
di_prop_t prop;
path = di_devfs_path( node );
/*
* if this is the root node ("/"), initialize the tree
*/
if( strlen( path ) == 1 ) {
top->setText( 0, TQString( di_binding_name( node )));
top->setPixmap( 0, SmallIcon( "kcmdevices" ));
top->setOpen( true );
top->setSelectable( false );
top->setExpandable( false );
}
/*
* place the node in the tree
*/
parent = mktree( top, path );
/*
* we have to handle the root node differently...
*/
if( strlen( path ) > 1 ) {
parent->setExpandable( true );
parent->setOpen( false );
} else {
previous = parent;
parent = top;
}
/*
* node name and physical device path
*/
drivername = di_driver_name( node );
previous = new TQListViewItem( parent,
i18n( "Driver Name:" ),
(drivername == NULL)
? i18n( "(driver not attached)" )
: drivername );
previous = new TQListViewItem( parent, previous,
i18n( "Binding Name:" ), di_binding_name( node ));
n = di_compatible_names( node, &names );
if( n < 1 ) {
compatnames = i18n( "(none)" );
} else {
for( i = 0; i < n; i++ ) {
compatnames += names;
compatnames += " ";
names += strlen( names ) + 1;
}
}
previous = new TQListViewItem( parent, previous,
i18n( "Compatible Names:" ), compatnames );
previous = new TQListViewItem( parent, previous,
i18n( "Physical Path:" ), TQString( path ));
/*
* dump the node's property list (if any)
*/
if( (prop = di_prop_next( node, DI_PROP_NIL )) != DI_PROP_NIL ) {
previous = new TQListViewItem( parent, previous, i18n( "Properties" ));
previous->setExpandable( true );
previous->setOpen( false );
do {
/*
* property type & value
*/
QListViewItem *tmp,
*prev;
tmp = new TQListViewItem( previous, di_prop_name( prop ));
tmp->setExpandable( true );
tmp->setOpen( false );
prev = new TQListViewItem( tmp, i18n( "Type:" ),
prop_type_str( prop ));
new TQListViewItem( tmp, prev, i18n( "Value:" ),
propvalue( prop ));
} while( (prop = di_prop_next( node, prop )) != DI_PROP_NIL );
}
/*
* if there are minor nodes, expand the tree appropriately
*/
if( di_minor_next( node, DI_MINOR_NIL ) != DI_MINOR_NIL ) {
previous = new TQListViewItem( parent, previous, i18n( "Minor Nodes" ));
previous->setExpandable( true );
previous->setOpen( false );
di_walk_minor( node, NULL, 0, previous, dump_minor_node );
}
return( DI_WALK_CONTINUE );
}
bool GetInfo_Devices( TQListView *lBox ) {
QListViewItem *top;
di_node_t root_node;
/*
* create a snapshot of the device tree
*/
if( (root_node = di_init( "/", DINFOCPYALL )) == DI_NODE_NIL ) {
return( false );
}
// XXX: might try to di_prom_init() here as well (if we're setgid sys)
/*
* prepare the tree widget
*/
lBox->addColumn( i18n( "Device Information" ));
lBox->addColumn( i18n( "Value" ));
top = new TQListViewItem( lBox );
/*
* traverse the device tree
*/
di_walk_node( root_node, DI_WALK_CLDFIRST, top, dump_node );
di_fini( root_node );
sorting_allowed = false;
return true;
}
#else /* ! HAVE_LIBDEVINFO_H */
bool GetInfo_Devices( TQListView * ) {
return false;
}
#endif /* ! HAVE_LIBDEVINFO_H */
|