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(QListView *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 QListViewItem(lBox, hw_info_mib->title, value);
101
// this is used to find out which devices are currently
103
static bool GetDmesgInfo(QListView *lBox, const char *filter,
104
void func(QListView *, 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);
125
QListViewItem *olditem = NULL;
126
while(!(s = t->readLine().toLocal8Bit()).isEmpty()) {
128
if (s.contains("cpu"))
133
if (s.contains("boot device") ||
134
s.contains("WARNING: old BSD partition ID!"))
138
|| (filter[0] == '^' && s.find(&filter[1]) == 0)
139
|| (filter[0] != '^' && s.contains(filter))) {
143
olditem = new QListViewItem(lBox, olditem, s);
161
AddIRQLine(QListView *lBox, QString s)
166
pos = s.find(" irq ");
167
irqnum = (pos < 0) ? 0 : atoi(&s.toAscii()[pos+5]);
169
snprintf(numstr, 3, "%02d", irqnum);
171
// this should never happen
172
strcpy(numstr, "??");
175
new QListViewItem(lBox, numstr, s);
178
bool GetInfo_IRQ (QListView *lBox)
180
lBox->addColumn(i18n("IRQ"));
181
lBox->addColumn(i18n("Device"));
183
lBox->setShowSortIndicator(false);
184
(void) GetDmesgInfo(lBox, " irq ", AddIRQLine);
188
bool GetInfo_DMA (QListView *)
193
bool GetInfo_PCI (QListView *lbox)
195
if (!GetDmesgInfo(lbox, "at pci", NULL))
196
new QListViewItem(lbox, i18n("No PCI devices found."));
200
bool GetInfo_IO_Ports (QListView *lbox)
202
if (!GetDmesgInfo(lbox, "port 0x", NULL))
203
new QListViewItem(lbox, i18n("No I/O port devices found."));
207
bool GetInfo_Sound (QListView *lbox)
209
lbox->setSorting(false);
211
if (!GetDmesgInfo(lbox, "audio", NULL))
212
new QListViewItem(lbox, i18n("No audio devices found."));
214
// append information for each audio devices found
215
QListViewItem *lvitem = lbox->firstChild();
216
for(; lvitem; lvitem = lvitem->nextSibling()) {
223
// The autoconf message is in form 'audio0 at auvia0: ...'
224
if (s.find("audio") == 0 && (pos = s.find(" at ")) > 0) {
225
pos += 4; // skip " at "
226
start = s.toAscii() + pos;
227
len = (int) strcspn(start, ":\n\t ");
228
dev = (char *) malloc(1 + len + 1);
229
sprintf(dev, "^%.*s", len, start); /* safe */
231
GetDmesgInfo(lbox, dev, NULL);
240
bool GetInfo_Devices (QListView *lBox)
242
(void) GetDmesgInfo(lBox, NULL, NULL);
246
bool GetInfo_SCSI (QListView *lbox)
248
if (!GetDmesgInfo(lbox, "scsibus", NULL))
249
new QListViewItem(lbox, i18n("No SCSI devices found."));
251
// remove the 'waiting %d seconds for devices to settle' message
252
QListViewItem *lvitem = lbox->firstChild();
253
for(; lvitem; lvitem = lvitem->nextSibling()) {
254
QString s = lvitem->text(0);
256
if (s.contains("seconds for devices to settle")) {
257
lbox->removeItem(lvitem);
265
bool GetInfo_Partitions (QListView *lbox)
267
int num; // number of mounts
268
// FIXME: older pkgsrc patches checked ST_RDONLY for this declaration
269
// what is ST_RDONLY and how does it affect getmntinfo?
270
struct statfs *mnt; // mount data pointer
273
if (!(num=getmntinfo(&mnt, MNT_WAIT))) {
274
kError() << "getmntinfo failed" << endl;
279
lbox->addColumn(i18n("Device"));
280
lbox->addColumn(i18n("Mount Point"));
281
lbox->addColumn(i18n("FS Type"));
282
lbox->addColumn(i18n("Total Size"));
283
lbox->addColumn(i18n("Free Size"));
284
lbox->addColumn(i18n("Total Nodes"));
285
lbox->addColumn(i18n("Free Nodes"));
286
lbox->addColumn(i18n("Flags"));
288
// mnt points into a static array (no need to free it)
289
for(; num--; ++mnt) {
290
unsigned long long big[2];
293
big[0] = big[1] = mnt->f_bsize; // coerce the product
294
big[0] *= mnt->f_blocks;
295
big[1] *= mnt->f_bavail; // FIXME: use f_bfree if root?
297
// convert to strings
298
vv[0] = KIO::convertSize(big[0]);
299
vv[1] = QLatin1String("%1 (%2%%)")
300
.arg(KIO::convertSize(big[1]))
301
.arg(mnt->f_blocks ? mnt->f_bavail*100/mnt->f_blocks : 0);
303
// FIXME: these two are large enough to punctuate
304
vv[2] = QString::number(mnt->f_files);
305
vv[3] = QLatin1String("%1 (%2%%) ")
307
.arg(mnt->f_files ? mnt->f_ffree*100/mnt->f_files : 0);
310
#define MNTF(x) if (mnt->f_flags & MNT_##x) vv[4] += QLatin1String(#x " ");
336
// put it in the table
337
// FIXME: there're more data but we have limited args (this is wrong! just add!)
338
new QListViewItem(lbox,
339
// FIXME: names need pad space
343
vv[0], vv[1], vv[2], vv[3], vv[4]);
350
bool GetInfo_XServer_and_Video (QListView *lBox)
352
return GetInfo_XServer_Generic( lBox );