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.
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 <stdio.h> /* for NULL */
36 #include <stdlib.h> /* for malloc(3) */
39 #include <QFontMetrics>
41 #include <QTextStream>
52 bool GetInfo_CPU(Q3ListView
*lBox
)
54 static hw_info_mib_list_t hw_info_mib_list
[]= {
55 { 1, HW_MODEL
, "Model" },
56 { 1, HW_MACHINE
, "Machine" },
57 { 0, HW_NCPU
, "Number of CPUs" },
58 { 0, HW_PAGESIZE
, "Pagesize" },
61 hw_info_mib_list_t
*hw_info_mib
;
68 lBox
->addColumn(i18n("Information"));
69 lBox
->addColumn(i18n("Value"));
71 for ( hw_info_mib
= hw_info_mib_list
; hw_info_mib
->title
; ++hw_info_mib
)
74 mib
[1] = hw_info_mib
->name
;
75 if ( hw_info_mib
->string
) {
76 sysctl(mib
,2,NULL
,&len
,NULL
,0);
77 if ( (buf
= (char*)malloc(len
)) ) {
78 sysctl(mib
,2,buf
,&len
,NULL
,0);
79 value
= QString::fromLocal8Bit(buf
);
83 value
= QString("Unknown");
88 sysctl(mib
,2,&num
,&len
,NULL
,0);
89 value
.sprintf("%d", num
);
91 new Q3ListViewItem(lBox
, hw_info_mib
->title
, value
);
97 // this is used to find out which devices are currently
99 static bool GetDmesgInfo(Q3ListView
*lBox
, const char *filter
,
100 void func(Q3ListView
*, QString s
, void **, bool))
102 QFile
*dmesg
= new QFile("/var/run/dmesg.boot");
111 if (dmesg
->exists() && dmesg
->open(QIODevice::ReadOnly
)) {
112 t
= new QTextStream(dmesg
);
116 pipe
= popen("/sbin/dmesg", "r");
117 if (!pipe
) return false;
119 t
= new QTextStream(pipe
, QIODevice::ReadOnly
);
122 Q3ListViewItem
*olditem
= NULL
;
123 while(!(s
= t
->readLine()).isNull()) {
125 if (s
.contains("cpu"))
130 if (s
.contains("boot device") ||
131 s
.contains("WARNING: old BSD partition ID!"))
134 if (!filter
|| s
.contains(filter
)) {
136 func(lBox
, s
, &opaque
, false);
139 olditem
= new Q3ListViewItem(lBox
, olditem
, s
);
145 func(lBox
, s
, &opaque
, true);
147 //lBox->triggerUpdate();
162 void AddIRQLine(Q3ListView
*lBox
, QString s
, void **opaque
, bool ending
)
164 Q3StrList
*strlist
= (Q3StrList
*) *opaque
;
171 strlist
= new Q3StrList();
172 *opaque
= (void *) strlist
;
175 str
= strlist
->first();
176 for(;str
; str
= strlist
->next()) {
177 new Q3ListViewItem(lBox
, str
);
183 pos
= s
.find(" irq ");
184 irqnum
= (pos
< 0) ? 0 : atoi(&p
[pos
+5]);
186 s
.sprintf("%02d%s", irqnum
, p
);
189 s
.sprintf("??%s", p
);
191 strlist
->inSort(s
.toLatin1());
194 bool GetInfo_IRQ (Q3ListView
*lBox
)
196 lBox
->addColumn(i18n("IRQ"));
197 lBox
->addColumn(i18n("Device"));
198 (void) GetDmesgInfo(lBox
, " irq ", AddIRQLine
);
202 bool GetInfo_DMA (Q3ListView
*)
207 bool GetInfo_PCI (Q3ListView
*lbox
)
209 if (!GetDmesgInfo(lbox
, "at pci", NULL
))
210 new Q3ListViewItem(lbox
, i18n("No PCI devices found."));
214 bool GetInfo_IO_Ports (Q3ListView
*lbox
)
216 if (!GetDmesgInfo(lbox
, "port 0x", NULL
))
217 new Q3ListViewItem(lbox
, i18n("No I/O port devices found."));
221 bool GetInfo_Sound (Q3ListView
*lbox
)
223 if (!GetDmesgInfo(lbox
, "audio", NULL
))
224 new Q3ListViewItem(lbox
, i18n("No audio devices found."));
226 // append information on any audio devices found
227 Q3ListViewItem
*lvitem
= lbox
->firstChild();
228 for(; lvitem
; lvitem
= lvitem
->nextSibling()) {
231 const char *start
, *end
;
235 if ((pos
= s
.find("at ")) >= 0) {
236 pos
+= 3; // skip "at "
237 start
= end
= s
.toAscii();
238 for(; *end
&& (*end
!=':') && (*end
!='\n'); end
++);
240 dev
= (char *) malloc(len
+ 1);
241 strncpy(dev
, start
, len
);
244 GetDmesgInfo(lbox
, dev
, NULL
);
253 bool GetInfo_Devices (Q3ListView
*lBox
)
255 (void) GetDmesgInfo(lBox
, NULL
, NULL
);
259 bool GetInfo_SCSI (Q3ListView
*lbox
)
261 if (!GetDmesgInfo(lbox
, "scsibus", NULL
))
262 new Q3ListViewItem(lbox
, i18n("No SCSI devices found."));
266 bool GetInfo_Partitions (Q3ListView
*lbox
)
269 char *line
, *orig_line
;
270 const char *device
, *mountpoint
, *type
, *flags
;
271 FILE *pipe
= popen("/sbin/mount", "r");
275 kError(0) << i18n("Unable to run /sbin/mount.") << endl
;
278 t
= new QTextStream(pipe
, QIODevice::ReadOnly
);
280 lbox
->addColumn(i18n("Device"));
281 lbox
->addColumn(i18n("Mount Point"));
282 lbox
->addColumn(i18n("FS Type"));
283 lbox
->addColumn(i18n("Mount Options"));
285 Q3ListViewItem
*olditem
= 0;
286 while (!(s
= t
->readLine()).isNull()) {
287 orig_line
= line
= strdup(s
.toLatin1());
289 device
= strsep(&line
, " ");
291 (void) strsep(&line
, " "); // consume word "on"
292 mountpoint
= strsep(&line
, " ");
294 (void) strsep(&line
, " "); // consume word "type"
295 type
= strsep(&line
, " ");
299 olditem
= new Q3ListViewItem(lbox
, olditem
, device
, mountpoint
,
310 bool GetInfo_XServer_and_Video (Q3ListView
*lBox
)
312 return GetInfo_XServer_Generic( lBox
);