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.
15 * all following functions should return true, when the Information
16 * was filled into the Tree Widget. Returning false indicates that
17 * information was not available.
20 #include <sys/types.h>
21 #include <sys/param.h>
22 #include <sys/sysctl.h>
23 #include <sys/mount.h>
24 #include <stdio.h> /* for NULL */
25 #include <stdlib.h> /* for malloc(3) */
29 #include <QFontMetrics>
30 #include <QStringList>
31 #include <QTextStream>
32 #include <QTreeWidgetItemIterator>
35 #include <kio/global.h> /* for KIO::convertSize() */
43 bool GetInfo_CPU(QTreeWidget
* tree
) {
44 static hw_info_mib_list_t hw_info_mib_list
[]= { { 1, HW_MODEL
, "Model" }, { 1, HW_MACHINE
, "Machine" }, { 1, HW_MACHINE_ARCH
, "Architecture" }, { 0, HW_NCPU
, "Number of CPUs" }, { 0, HW_PAGESIZE
, "Pagesize" }, { 0, 0, 0 } };
45 hw_info_mib_list_t
*hw_info_mib
;
53 list
<< i18n("Information") << i18n("Value");
54 tree
->setHeaderLabels(list
);
56 for (hw_info_mib
= hw_info_mib_list
; hw_info_mib
->title
; ++hw_info_mib
) {
58 mib
[1] = hw_info_mib
->name
;
59 if (hw_info_mib
->string
) {
60 sysctl(mib
, 2, NULL
, &len
, NULL
, 0);
61 if ( (buf
= (char*)malloc(len
))) {
62 sysctl(mib
, 2, buf
, &len
, NULL
, 0);
63 value
= QString::fromLocal8Bit(buf
);
66 value
= QString("Unknown");
70 sysctl(mib
, 2, &num
, &len
, NULL
, 0);
71 value
= QString::number(num
);
75 list
<< hw_info_mib
->title
<< value
;
77 new QTreeWidgetItem(tree
, list
);
83 // this is used to find out which devices are currently
85 static bool GetDmesgInfo(QTreeWidget
* tree
, const char *filter
, void func(QTreeWidget
* tree
, QString s
)) {
86 QFile
*dmesg
= new QFile("/var/run/dmesg.boot");
94 if (dmesg
->exists() && dmesg
->open(QIODevice::ReadOnly
)) {
95 t
= new QTextStream(dmesg
);
98 pipe
= popen("/sbin/dmesg", "r");
102 t
= new QTextStream(pipe
, QIODevice::ReadOnly
);
105 while (!(s
= t
->readLine().toLocal8Bit()).isNull()) {
107 if (s
.contains("cpu"))
112 if (s
.contains("boot device") || s
.contains("WARNING: old BSD partition ID!"))
115 if (!filter
|| s
.contains(QRegExp(filter
))) {
121 new QTreeWidgetItem(tree
, list
);
138 void AddIRQLine(QTreeWidget
* tree
, QString s
) {
144 s2
= s
.mid(s
.indexOf(QRegExp("[ (]irq "))+5);
145 irqnum
= s2
.remove(QRegExp("[^0-9].*")).toInt(&ok
);
147 snprintf(numstr
, 3, "%02d", irqnum
);
149 // this should never happen
150 strcpy(numstr
, "??");
155 new QTreeWidgetItem(tree
, list
);
158 bool GetInfo_IRQ(QTreeWidget
* tree
) {
161 headers
<< i18n("IRQ") << i18n("Device");
162 tree
->setHeaderLabels(headers
);
164 tree
->sortItems(0, Qt::AscendingOrder
);
166 tree
->setSortingEnabled(false);
168 (void) GetDmesgInfo(tree
, "[ (]irq ", AddIRQLine
);
172 bool GetInfo_DMA(QTreeWidget
*) {
176 bool GetInfo_PCI(QTreeWidget
* tree
) {
177 if (!GetDmesgInfo(tree
, "at pci", NULL
)) {
179 list
<< i18n("No PCI devices found.");
180 new QTreeWidgetItem(tree
, list
);
185 bool GetInfo_IO_Ports(QTreeWidget
* tree
) {
186 if (!GetDmesgInfo(tree
, "port 0x", NULL
)) {
188 list
<< i18n("No I/O port devices found.");
189 new QTreeWidgetItem(tree
, list
);
194 bool GetInfo_Sound(QTreeWidget
* tree
) {
195 tree
->setSortingEnabled(false);
197 if (!GetDmesgInfo(tree
, "audio", NULL
)) {
199 list
<< i18n("No audio devices found.");
200 new QTreeWidgetItem(tree
, list
);
203 // append information for each audio devices found
205 QTreeWidgetItemIterator
it(tree
, QTreeWidgetItemIterator::All
);
206 while ( *it
!= NULL
) {
212 // The autoconf message is in form 'audio0 at auvia0: ...'
213 if (s
.find("audio") == 0 && (pos
= s
.find(" at ")) > 0) {
214 s2
= s
.mid(pos
+4); // skip " at "
215 s2
.remove(QRegExp("[:\n\t ].*"));
216 dev
= strdup(s2
.toAscii().data());
218 GetDmesgInfo(tree
, dev
, NULL
);
229 bool GetInfo_Devices(QTreeWidget
* tree
) {
230 (void) GetDmesgInfo(tree
, NULL
, NULL
);
234 bool GetInfo_SCSI(QTreeWidget
* tree
) {
235 if (!GetDmesgInfo(tree
, "scsibus", NULL
)) {
237 list
<< i18n("No SCSI devices found.");
238 new QTreeWidgetItem(tree
, list
);
241 // remove the 'waiting %d seconds for devices to settle' message
242 QTreeWidgetItemIterator
it(tree
, QTreeWidgetItemIterator::All
);
243 while ( *it
!= NULL
) {
244 QString s
= (*it
)->text(0);
246 if (s
.contains("seconds for devices to settle")) {
247 delete tree
->takeItem( tree
->indexOfTopLevelItem(*it
) );
257 bool GetInfo_Partitions(QTreeWidget
* tree
) {
258 int num
; // number of mounts
260 struct statvfs
*mnt
; // mount data pointer
262 struct statfs
*mnt
; // mount data pointer
266 if (!(num
=getmntinfo(&mnt
, MNT_WAIT
))) {
267 kError() << "getmntinfo failed" << endl
;
273 headers
<< i18n("Device") << i18n("Mount Point") << i18n("FS Type") << i18n("Total Size") << i18n("Free Size") << i18n("Total Nodes") << i18n("Free Nodes") << i18n("Flags");
274 tree
->setHeaderLabels(headers
);
276 // mnt points into a static array (no need to free it)
277 for (; num
--; ++mnt
) {
278 unsigned long long big
[2];
282 big
[0] = big
[1] = mnt
->f_frsize
; // coerce the product
284 big
[0] = big
[1] = mnt
->f_bsize
; // coerce the product
286 big
[0] *= mnt
->f_blocks
;
287 big
[1] *= mnt
->f_bavail
; // FIXME: use f_bfree if root?
289 // convert to strings
290 vv
[0] = KIO::convertSize(big
[0]);
291 vv
[1] = QString("%1 (%2%)")
292 .arg(KIO::convertSize(big
[1]))
293 .arg(mnt
->f_blocks
? mnt
->f_bavail
*100/mnt
->f_blocks
: 0);
295 vv
[2] = QString("%L1").arg(mnt
->f_files
);
296 vv
[3] = QString("%L1 (%2%) ")
298 .arg(mnt
->f_files
? mnt
->f_ffree
*100/mnt
->f_files
: 0);
302 #define MNTF(x) if (mnt->f_flag & ST_##x) vv[4] += QLatin1String(#x " ");
304 #define MNTF(x) if (mnt->f_flags & MNT_##x) vv[4] += QLatin1String(#x " ");
333 // put it in the table
336 // FIXME: there're more data but we have limited args (this is wrong! just add!)
337 // FIXME: names need pad space
338 list
<< mnt
->f_mntfromname
<< mnt
->f_mntonname
<< mnt
->f_fstypename
<< vv
[0] << vv
[1] << vv
[2] << vv
[3] << vv
[4];
339 new QTreeWidgetItem(tree
, list
);
346 bool GetInfo_XServer_and_Video(QTreeWidget
* tree
) {
347 return GetInfo_XServer_Generic(tree
);