2 * info_netbsd.cpp is part of the KDE program kcminfo. This displays
3 * various information about the OpenBSD 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 QTreeWidget. 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 <stdio.h> /* for NULL */
24 #include <stdlib.h> /* for malloc(3) */
27 #include <QFontMetrics>
28 #include <QTextStream>
29 #include <QTreeWidgetItemIterator>
39 bool GetInfo_CPU(QTreeWidget
* tree
) {
40 static hw_info_mib_list_t hw_info_mib_list
[]= { { 1, HW_MODEL
, "Model" }, { 1, HW_MACHINE
, "Machine" }, { 0, HW_NCPU
, "Number of CPUs" }, { 0, HW_PAGESIZE
, "Pagesize" }, { 0, 0, 0 } };
41 hw_info_mib_list_t
*hw_info_mib
;
49 headers
<< i18n("Information") << i18n("Value");
50 tree
->setHeaderLabels(headers
);
52 for (hw_info_mib
= hw_info_mib_list
; hw_info_mib
->title
; ++hw_info_mib
) {
54 mib
[1] = hw_info_mib
->name
;
55 if (hw_info_mib
->string
) {
56 sysctl(mib
, 2, NULL
, &len
, NULL
, 0);
57 if ( (buf
= (char*)malloc(len
))) {
58 sysctl(mib
, 2, buf
, &len
, NULL
, 0);
59 value
= QString::fromLocal8Bit(buf
);
62 value
= QString("Unknown");
66 sysctl(mib
, 2, &num
, &len
, NULL
, 0);
67 value
.sprintf("%d", num
);
71 list
<< hw_info_mib
->title
<< value
;
72 new QTreeWidgetItem(tree
, list
);
78 // this is used to find out which devices are currently
80 static bool GetDmesgInfo(QTreeWidget
* tree
, const char *filter
, void func(QTreeWidget
*, QString s
, void **, bool)) {
81 QFile
*dmesg
= new QFile("/var/run/dmesg.boot");
90 if (dmesg
->exists() && dmesg
->open(QIODevice::ReadOnly
)) {
91 t
= new QTextStream(dmesg
);
94 pipe
= popen("/sbin/dmesg", "r");
98 t
= new QTextStream(pipe
, QIODevice::ReadOnly
);
101 while (!(s
= t
->readLine()).isNull()) {
103 if (s
.contains("cpu"))
108 if (s
.contains("boot device") || s
.contains("WARNING: old BSD partition ID!"))
111 if (!filter
|| s
.contains(filter
)) {
113 func(tree
, s
, &opaque
, false);
117 new QTreeWidgetItem(tree
, list
);
123 func(tree
, s
, &opaque
, true);
125 //tree->triggerUpdate();
138 void AddIRQLine(QTreeWidget
* tree
, QString s
, void **opaque
, bool ending
) {
139 QStringList
*strlist
= (QStringList
*) *opaque
;
146 strlist
= new QStringList();
147 *opaque
= (void *) strlist
;
150 foreach(QString temp
, *strlist
) {
151 QStringList tempList
;
153 new QTreeWidgetItem(tree
, tempList
);
159 pos
= s
.find(" irq ");
160 irqnum
= (pos
< 0) ? 0 : atoi(&p
[pos
+5]);
162 s
.sprintf("%02d%s", irqnum
, p
);
164 s
.sprintf("??%s", p
);
170 bool GetInfo_IRQ(QTreeWidget
* tree
) {
172 headers
<< i18n("IRQ") << i18n("Device");
173 tree
->setHeaderLabels(headers
);
174 (void) GetDmesgInfo(tree
, " irq ", AddIRQLine
);
178 bool GetInfo_DMA(QTreeWidget
*) {
182 bool GetInfo_PCI(QTreeWidget
* tree
) {
183 if (!GetDmesgInfo(tree
, "at pci", NULL
)) {
185 list
<< i18n("No PCI devices found.");
186 new QTreeWidgetItem(tree
, list
);
191 bool GetInfo_IO_Ports(QTreeWidget
* tree
) {
192 if (!GetDmesgInfo(tree
, "port 0x", NULL
)) {
194 list
<< i18n("No I/O port devices found.");
195 new QTreeWidgetItem(tree
, list
);
200 bool GetInfo_Sound(QTreeWidget
* tree
) {
201 if (!GetDmesgInfo(tree
, "audio", NULL
)) {
203 list
<< i18n("No audio devices found.");
204 new QTreeWidgetItem(tree
, list
);
207 // append information on any audio devices found
208 QTreeWidgetItemIterator
it(tree
, QTreeWidgetItemIterator::All
);
209 while ( *it
!= NULL
) {
210 QTreeWidgetItem
* lvitem
= *it
;
214 const char *start
, *end
;
218 if ((pos
= s
.find("at ")) >= 0) {
219 pos
+= 3; // skip "at "
220 start
= end
= s
.toAscii();
221 for (; *end
&& (*end
!=':') && (*end
!='\n'); end
++)
224 dev
= (char *) malloc(len
+ 1);
225 strncpy(dev
, start
, len
);
228 GetDmesgInfo(tree
, dev
, NULL
);
239 bool GetInfo_Devices(QTreeWidget
* tree
) {
240 (void) GetDmesgInfo(tree
, NULL
, NULL
);
244 bool GetInfo_SCSI(QTreeWidget
* tree
) {
245 if (!GetDmesgInfo(tree
, "scsibus", NULL
)) {
247 list
<< i18n("No SCSI devices found.");
248 new QTreeWidgetItem(tree
, list
);
253 bool GetInfo_Partitions(QTreeWidget
* tree
) {
255 char *line
, *orig_line
;
256 const char *device
, *mountpoint
, *type
, *flags
;
257 FILE *pipe
= popen("/sbin/mount", "r");
261 kError(0) << i18n("Unable to run /sbin/mount.") << endl
;
264 t
= new QTextStream(pipe
, QIODevice::ReadOnly
);
267 headers
<< i18n("Device") << i18n("Mount Point") << i18n("FS Type") << i18n("Mount Options");
268 tree
->setHeaderLabels(headers
);
270 while (!(s
= t
->readLine()).isNull()) {
271 orig_line
= line
= strdup(s
.toLatin1());
273 device
= strsep(&line
, " ");
275 (void) strsep(&line
, " "); // consume word "on"
276 mountpoint
= strsep(&line
, " ");
278 (void) strsep(&line
, " "); // consume word "type"
279 type
= strsep(&line
, " ");
283 QStringList mountList
;
284 mountList
<< device
<< mountpoint
<< type
<< flags
;
285 new QTreeWidgetItem(tree
, mountList
);
295 bool GetInfo_XServer_and_Video(QTreeWidget
* tree
) {
296 return GetInfo_XServer_Generic(tree
);