2
* $Id: info_fbsd.cpp,v 1.27 2003/01/25 14:31:11 augustin Exp $
4
* info_fbsd.cpp is part of the KDE program kcminfo. This displays
5
* various information about the system (hopefully a FreeBSD system)
8
* All of the devinfo bits were blatantly stolen from the devinfo utility
9
* provided with FreeBSD 5.0 (and later). No gross hacks were harmed
10
* during the creation of info_fbsd.cpp. Thanks Mike.
13
#define INFO_CPU_AVAILABLE
14
#define INFO_IRQ_AVAILABLE
15
#define INFO_DMA_AVAILABLE
16
#define INFO_PCI_AVAILABLE
17
#define INFO_IOPORTS_AVAILABLE
18
#define INFO_SOUND_AVAILABLE
19
#define INFO_DEVICES_AVAILABLE
20
#define INFO_SCSI_AVAILABLE
21
#define INFO_PARTITIONS_AVAILABLE
22
#define INFO_XSERVER_AVAILABLE
26
* all following functions should return TRUE, when the Information
27
* was filled into the lBox-Widget. Returning FALSE indicates that
28
* information was not available.
35
#include <sys/types.h>
36
#include <sys/sysctl.h>
38
//#if __FreeBSD_version >= 500042
39
// #define we should have devinfo.h
41
// #define we probably don't have devinfo.h
58
#include <qtextstream.h>
62
Device (QString n=QString::null, QString d=QString::null)
63
{name=n; description=d;}
64
QString name, description;
67
void ProcessChildren(QString name);
68
QString GetController(const QString &line);
69
Device *GetDevice(const QString &line);
73
int print_irq(struct devinfo_rman *rman, void *arg);
74
int print_dma(struct devinfo_rman *rman, void *arg);
75
int print_ioports(struct devinfo_rman *rman, void *arg);
76
int print_resource(struct devinfo_res *res, void *arg);
80
bool GetInfo_CPU (QListView *lBox)
82
// Modified 13 July 2000 for SMP by Brad Hughes - bhughes@trolltech.com
88
sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);
91
for (int i = ncpu; i > 0; i--) {
92
/* Stuff for sysctl */
96
// get the processor model
97
sysctlbyname("hw.model", NULL, &len, NULL, 0);
99
sysctlbyname("hw.model", buf, &len, NULL, 0);
101
// get the TSC speed if we can
103
if (sysctlbyname("machdep.tsc_freq", &i_buf, &len, NULL, 0) != -1) {
104
cpustring = i18n("CPU %1: %2, %3 MHz").arg(i).arg(buf).arg(i_buf/1000000);
106
cpustring = i18n("CPU %1: %2, unknown speed").arg(i).arg(buf);
109
/* Put everything in the listbox */
110
new QListViewItem(lBox, cpustring);
112
/* Clean up after ourselves, this time I mean it ;-) */
119
bool GetInfo_IRQ (QListView *lbox)
121
#ifdef HAVE_DEVINFO_H
122
/* systat lists the interrupts assigned to devices as well as how many were
123
generated. Parsing its output however is about as fun as a sandpaper
124
enema. The best idea would probably be to rip out the guts of systat.
125
Too bad it's not very well commented */
126
/* Oh neat, current now has a neat little utility called devinfo */
129
devinfo_foreach_rman(print_irq, lbox);
136
bool GetInfo_DMA (QListView *lbox)
138
#ifdef HAVE_DEVINFO_H
139
/* Oh neat, current now has a neat little utility called devinfo */
142
devinfo_foreach_rman(print_dma, lbox);
149
bool GetInfo_IO_Ports (QListView *lbox)
151
#ifdef HAVE_DEVINFO_H
152
/* Oh neat, current now has a neat little utility called devinfo */
155
devinfo_foreach_rman(print_ioports, lbox);
162
bool GetInfo_Sound (QListView *lbox)
164
QFile *sndstat = new QFile("/dev/sndstat");
167
QListViewItem *olditem = 0;
169
if (!sndstat->exists() || !sndstat->open(IO_ReadOnly)) {
171
s = i18n("Your sound system could not be queried. /dev/sndstat does not exist or is not readable.");
172
olditem = new QListViewItem(lbox, olditem, s);
174
t = new QTextStream(sndstat);
175
while (!(s=t->readLine()).isNull()) {
176
olditem = new QListViewItem(lbox, olditem, s);
187
bool GetInfo_SCSI (QListView *lbox)
190
QFile *camcontrol = new QFile("/sbin/camcontrol");
193
QListViewItem *olditem = 0;
195
if (!camcontrol->exists()) {
196
s = i18n ("SCSI subsystem could not be queried: /sbin/camcontrol could not be found");
197
olditem = new QListViewItem(lbox, olditem, s);
198
} else if ((pipe = popen("/sbin/camcontrol devlist 2>&1", "r")) == NULL) {
199
s = i18n ("SCSI subsystem could not be queried: /sbin/camcontrol could not be executed");
200
olditem = new QListViewItem(lbox, olditem, s);
203
/* This prints out a list of all the scsi devies, perhaps eventually we could
204
parse it as opposed to schlepping it into a listbox */
206
t = new QTextStream(pipe, IO_ReadOnly);
212
olditem = new QListViewItem(lbox, olditem, s);
221
if (!lbox->childCount())
227
bool GetInfo_PCI (QListView *lbox)
233
QListViewItem *olditem = 0;
235
pcicontrol = new QFile("/usr/X11R6/bin/scanpci");
237
if (!pcicontrol->exists()) {
239
pcicontrol = new QFile("/usr/X11R6/bin/pcitweak");
240
if (!pcicontrol->exists()) {
242
pcicontrol = new QFile("/usr/sbin/pciconf");
243
if (!pcicontrol->exists()) {
245
s = i18n("Could not find any programs with which to query your system's PCI information");
246
(void) new QListViewItem(lbox, 0, s);
250
cmd = "/usr/sbin/pciconf -l";
253
cmd = "/usr/X11R6/bin/pcitweak -l 2>&1";
256
cmd = "/usr/X11R6/bin/scanpci";
260
if ((pipe = popen(cmd.latin1(), "r")) == NULL) {
261
s = i18n ("PCI subsystem could not be queried: %1 could not be executed").arg(cmd);
262
olditem = new QListViewItem(lbox, olditem, s);
265
/* This prints out a list of all the pci devies, perhaps eventually we could
266
parse it as opposed to schlepping it into a listbox */
268
t = new QTextStream(pipe, IO_ReadOnly);
274
olditem = new QListViewItem(lbox, olditem, s);
281
if (!lbox->childCount()) {
282
s = i18n("The PCI subsystem could not be queried, this may need root privileges.");
283
olditem = new QListViewItem(lbox, olditem, s);
290
bool GetInfo_Partitions (QListView *lbox)
292
struct fstab *fstab_ent;
294
if (setfsent() != 1) /* Try to open fstab */ {
297
s = i18n("Could not check filesystem info: ");
298
s += strerror(s_err);
299
(void)new QListViewItem(lbox, 0, s);
301
lbox->addColumn(i18n("Device"));
302
lbox->addColumn(i18n("Mount Point"));
303
lbox->addColumn(i18n("FS Type"));
304
lbox->addColumn(i18n("Mount Options"));
306
while ((fstab_ent=getfsent())!=NULL) {
307
new QListViewItem(lbox, fstab_ent->fs_spec,
308
fstab_ent->fs_file, fstab_ent->fs_vfstype,
309
fstab_ent->fs_mntops);
313
lbox->header()->setClickEnabled(true);
315
endfsent(); /* Close fstab */
320
bool GetInfo_XServer_and_Video (QListView *lBox)
322
return GetInfo_XServer_Generic( lBox );
325
bool GetInfo_Devices (QListView *lbox)
327
QFile *f = new QFile("/var/run/dmesg.boot");
328
if (f->open(IO_ReadOnly)) {
330
QDict<QListViewItem> lv_items;
332
QString line, controller;
333
lbox->setRootIsDecorated(true);
334
lbox->addColumn("Device");
335
lbox->addColumn("Description");
336
while ( !(line=qts.readLine()).isNull() ) {
337
controller = GetController(line);
338
if (controller.isNull())
343
// Ewww assuing motherboard is the only toplevel controller is rather gross
344
if (controller == "motherboard") {
345
if (!lv_items[dev->name]) {
346
lv_items.insert(dev->name, new QListViewItem(lbox, dev->name, dev->description) );
349
QListViewItem *parent=lv_items[controller];
350
if (parent && !lv_items[dev->name]) {
351
lv_items.insert(dev->name, new QListViewItem(parent, dev->name, dev->description) );
360
QString GetController(const QString &line)
362
if ( ( (line.startsWith("ad")) || (line.startsWith("afd")) || (line.startsWith("acd")) ) && (line.find(":") < 6) ) {
363
QString controller = line;
364
controller.remove(0, controller.find(" at ")+4);
365
if (controller.find("-slave") != -1) {
366
controller.remove(controller.find("-slave"), controller.length());
367
} else if (controller.find("-master") != -1) {
368
controller.remove(controller.find("-master"), controller.length());
370
controller=QString::null;
371
if (!controller.isNull())
374
if (line.find(" on ") != -1) {
377
controller.remove(0, controller.find(" on ")+4);
378
if (controller.find(" ") != -1)
379
controller.remove(controller.find(" "), controller.length());
382
return QString::null;
385
Device *GetDevice(const QString &line)
388
int colon = line.find(":");
392
dev->name = line.mid(0, colon);
393
dev->description = line.mid(line.find("<")+1, line.length());
394
dev->description.remove(dev->description.find(">"), dev->description.length());
398
#ifdef HAVE_DEVINFO_H
400
int print_irq(struct devinfo_rman *rman, void *arg)
402
QListView *lbox = (QListView *)arg;
403
if (strcmp(rman->dm_desc, "Interrupt request lines")==0) {
404
(void)new QListViewItem(lbox, 0, rman->dm_desc);
405
devinfo_foreach_rman_resource(rman, print_resource, arg);
410
int print_dma(struct devinfo_rman *rman, void *arg)
412
QListView *lbox = (QListView *)arg;
413
if (strcmp(rman->dm_desc, "DMA request lines")==0) {
414
(void)new QListViewItem(lbox, lbox->lastItem(), rman->dm_desc);
415
devinfo_foreach_rman_resource(rman, print_resource, arg);
420
int print_ioports(struct devinfo_rman *rman, void *arg)
422
QListView *lbox = (QListView *)arg;
424
if (strcmp(rman->dm_desc, "I/O ports")==0) {
425
(void)new QListViewItem(lbox, lbox->lastItem(), rman->dm_desc);
426
devinfo_foreach_rman_resource(rman, print_resource, arg);
428
else if (strcmp(rman->dm_desc, "I/O memory addresses")==0) {
429
(void)new QListViewItem(lbox, lbox->lastItem(), rman->dm_desc);
430
devinfo_foreach_rman_resource(rman, print_resource, arg);
435
int print_resource(struct devinfo_res *res, void *arg)
437
struct devinfo_dev *dev;
438
struct devinfo_rman *rman;
443
lbox = (QListView *)arg;
447
rman = devinfo_handle_to_rman(res->dr_rman);
448
hexmode = (rman->dm_size > 100) || (rman->dm_size == 0);
449
tmp.sprintf(hexmode ? "0x%lx" : "%lu", res->dr_start);
451
if (res->dr_size > 1) {
452
tmp.sprintf(hexmode ? "-0x%lx" : "-%lu",
453
res->dr_start + res->dr_size - 1);
457
dev = devinfo_handle_to_device(res->dr_device);
458
if ((dev != NULL) && (dev->dd_name[0] != 0)) {
459
tmp.sprintf(" (%s)", dev->dd_name);
461
tmp.sprintf(" ----");
465
(void)new QListViewItem(lbox, lbox->lastItem(), s);