2
* info_netbsd.cpp is part of the KDE program kcminfo. This displays
3
* various information about the NetBSD system it's running on.
5
* Originally written by Jaromir Dolecek <dolecek@ics.muni.cz>. CPU info
6
* code has been imported from implementation of processor.cpp for KDE 1.0
7
* by David Brownlee <abs@NetBSD.org> as found in NetBSD packages collection.
8
* Hubert Feyer <hubertf@NetBSD.org> enhanced the sound information printing
11
* The code is placed into public domain. Do whatever you want with it.
14
#define INFO_CPU_AVAILABLE
15
#define INFO_IRQ_AVAILABLE
16
#define INFO_DMA_AVAILABLE
17
#define INFO_PCI_AVAILABLE
18
#define INFO_IOPORTS_AVAILABLE
19
#define INFO_SOUND_AVAILABLE
20
#define INFO_DEVICES_AVAILABLE
21
#define INFO_SCSI_AVAILABLE
22
#define INFO_PARTITIONS_AVAILABLE
23
#define INFO_XSERVER_AVAILABLE
27
* all following functions should return true, when the Information
28
* was filled into the lBox-Widget. Returning false indicates that
29
* information was not available.
32
#include <sys/types.h>
33
#include <sys/param.h>
34
#include <sys/sysctl.h>
35
#include <sys/mount.h>
36
#include <stdio.h> /* for NULL */
37
#include <stdlib.h> /* for malloc(3) */
41
#include <QFontMetrics>
43
#include <QTextStream>
46
#include <kio/global.h> /* for KIO::convertSize() */
55
bool GetInfo_CPU(Q3ListView *lBox)
57
static hw_info_mib_list_t hw_info_mib_list[]= {
58
{ 1, HW_MODEL, "Model" },
59
{ 1, HW_MACHINE, "Machine" },
60
{ 1, HW_MACHINE_ARCH, "Architecture" },
61
{ 0, HW_NCPU, "Number of CPUs" },
62
{ 0, HW_PAGESIZE, "Pagesize" },
65
hw_info_mib_list_t *hw_info_mib;
72
lBox->addColumn(i18n("Information"));
73
lBox->addColumn(i18n("Value"));
75
for ( hw_info_mib = hw_info_mib_list ; hw_info_mib->title ; ++hw_info_mib )
78
mib[1] = hw_info_mib->name;
79
if ( hw_info_mib->string ) {
80
sysctl(mib,2,NULL,&len,NULL,0);
81
if ( (buf = (char*)malloc(len)) ) {
82
sysctl(mib,2,buf,&len,NULL,0);
83
value = QString::fromLocal8Bit(buf);
87
value = QString("Unknown");
92
sysctl(mib,2,&num,&len,NULL,0);
93
value = QString::number(num);
95
new Q3ListViewItem(lBox, hw_info_mib->title, value);
101
// this is used to find out which devices are currently
103
static bool GetDmesgInfo(Q3ListView *lBox, const char *filter,
104
void func(Q3ListView *, QString s))
106
QFile *dmesg = new QFile("/var/run/dmesg.boot");
107
bool usepipe = false;
110
bool seencpu = false;
114
if (dmesg->exists() && dmesg->open(QIODevice::ReadOnly)) {
115
t = new QTextStream(dmesg);
119
pipe = popen("/sbin/dmesg", "r");
120
if (!pipe) return false;
122
t = new QTextStream(pipe, QIODevice::ReadOnly);
124
Q3ListViewItem *olditem = NULL;
125
while(!(s = t->readLine().toLocal8Bit()).isNull()) {
127
if (s.contains("cpu"))
132
if (s.contains("boot device") ||
133
s.contains("WARNING: old BSD partition ID!"))
136
if (!filter || s.contains(QRegExp(filter))) {
140
olditem = new Q3ListViewItem(lBox, olditem, s);
158
AddIRQLine(Q3ListView *lBox, QString s)
165
s2 = s.mid(s.indexOf(QRegExp("[ (]irq "))+5);
166
irqnum = s2.remove(QRegExp("[^0-9].*")).toInt(&ok);
168
snprintf(numstr, 3, "%02d", irqnum);
170
// this should never happen
171
strcpy(numstr, "??");
174
new Q3ListViewItem(lBox, numstr, s);
177
bool GetInfo_IRQ (Q3ListView *lBox)
179
lBox->addColumn(i18n("IRQ"));
180
lBox->addColumn(i18n("Device"));
182
lBox->setShowSortIndicator(false);
183
(void) GetDmesgInfo(lBox, "[ (]irq ", AddIRQLine);
187
bool GetInfo_DMA (Q3ListView *)
192
bool GetInfo_PCI (Q3ListView *lbox)
194
if (!GetDmesgInfo(lbox, "at pci", NULL))
195
new Q3ListViewItem(lbox, i18n("No PCI devices found."));
199
bool GetInfo_IO_Ports (Q3ListView *lbox)
201
if (!GetDmesgInfo(lbox, "port 0x", NULL))
202
new Q3ListViewItem(lbox, i18n("No I/O port devices found."));
206
bool GetInfo_Sound (Q3ListView *lbox)
208
lbox->setSorting(false);
210
if (!GetDmesgInfo(lbox, "audio", NULL))
211
new Q3ListViewItem(lbox, i18n("No audio devices found."));
213
// append information for each audio devices found
214
Q3ListViewItem *lvitem = lbox->firstChild();
215
for(; lvitem; lvitem = lvitem->nextSibling()) {
221
// The autoconf message is in form 'audio0 at auvia0: ...'
222
if (s.find("audio") == 0 && (pos = s.find(" at ")) > 0) {
223
s2 = s.mid(pos+4); // skip " at "
224
s2.remove(QRegExp("[:\n\t ].*"));
225
dev = strdup(s2.toAscii().data());
227
GetDmesgInfo(lbox, dev, NULL);
236
bool GetInfo_Devices (Q3ListView *lBox)
238
(void) GetDmesgInfo(lBox, NULL, NULL);
242
bool GetInfo_SCSI (Q3ListView *lbox)
244
if (!GetDmesgInfo(lbox, "scsibus", NULL))
245
new Q3ListViewItem(lbox, i18n("No SCSI devices found."));
247
// remove the 'waiting %d seconds for devices to settle' message
248
Q3ListViewItem *lvitem = lbox->firstChild();
249
for(; lvitem; lvitem = lvitem->nextSibling()) {
250
QString s = lvitem->text(0);
252
if (s.contains("seconds for devices to settle")) {
253
lbox->removeItem(lvitem);
261
bool GetInfo_Partitions (Q3ListView *lbox)
263
int num; // number of mounts
265
struct statvfs *mnt; // mount data pointer
267
struct statfs *mnt; // mount data pointer
271
if (!(num=getmntinfo(&mnt, MNT_WAIT))) {
272
kError() << "getmntinfo failed" << endl;
277
lbox->addColumn(i18n("Device"));
278
lbox->addColumn(i18n("Mount Point"));
279
lbox->addColumn(i18n("FS Type"));
280
lbox->addColumn(i18n("Total Size"));
281
lbox->addColumn(i18n("Free Size"));
282
lbox->addColumn(i18n("Total Nodes"));
283
lbox->addColumn(i18n("Free Nodes"));
284
lbox->addColumn(i18n("Flags"));
286
// mnt points into a static array (no need to free it)
287
for(; num--; ++mnt) {
288
unsigned long long big[2];
292
big[0] = big[1] = mnt->f_frsize; // coerce the product
294
big[0] = big[1] = mnt->f_bsize; // coerce the product
296
big[0] *= mnt->f_blocks;
297
big[1] *= mnt->f_bavail; // FIXME: use f_bfree if root?
299
// convert to strings
300
vv[0] = KIO::convertSize(big[0]);
301
vv[1] = QString("%1 (%2%)")
302
.arg(KIO::convertSize(big[1]))
303
.arg(mnt->f_blocks ? mnt->f_bavail*100/mnt->f_blocks : 0);
305
vv[2] = QString("%L1").arg(mnt->f_files);
306
vv[3] = QString("%L1 (%2%) ")
308
.arg(mnt->f_files ? mnt->f_ffree*100/mnt->f_files : 0);
312
#define MNTF(x) if (mnt->f_flag & ST_##x) vv[4] += QLatin1String(#x " ");
314
#define MNTF(x) if (mnt->f_flags & MNT_##x) vv[4] += QLatin1String(#x " ");
343
// put it in the table
344
// FIXME: there're more data but we have limited args (this is wrong! just add!)
345
new Q3ListViewItem(lbox,
346
// FIXME: names need pad space
350
vv[0], vv[1], vv[2], vv[3], vv[4]);
357
bool GetInfo_XServer_and_Video (Q3ListView *lBox)
359
return GetInfo_XServer_Generic( lBox );