2 * info_fbsd.cpp is part of the KDE program kcminfo. This displays
3 * various information about the system (hopefully a FreeBSD system)
6 * All of the devinfo bits were blatantly stolen from the devinfo utility
7 * provided with FreeBSD 5.0 (and later). No gross hacks were harmed
8 * during the creation of info_fbsd.cpp. Thanks Mike.
11 #define INFO_CPU_AVAILABLE
12 #define INFO_IRQ_AVAILABLE
13 #define INFO_DMA_AVAILABLE
14 #define INFO_PCI_AVAILABLE
15 #define INFO_IOPORTS_AVAILABLE
16 #define INFO_SOUND_AVAILABLE
17 #define INFO_DEVICES_AVAILABLE
18 #define INFO_SCSI_AVAILABLE
19 #define INFO_PARTITIONS_AVAILABLE
20 #define INFO_XSERVER_AVAILABLE
24 * all following functions should return true, when the Information
25 * was filled into the lBox-Widget. Returning false indicates that
26 * information was not available.
28 #include "config-infocenter.h" // HAVE_DEVINFO_H
30 #include <sys/types.h>
31 #include <sys/sysctl.h>
43 #include <Qt3Support/Q3Dict>
46 #include <QTextStream>
50 Device (QString n
=QString(), QString d
=QString())
51 {name
=n
; description
=d
;}
52 QString name
, description
;
55 void ProcessChildren(QString name
);
56 QString
GetController(const QString
&line
);
57 Device
*GetDevice(const QString
&line
);
61 int print_irq(struct devinfo_rman
*rman
, void *arg
);
62 int print_dma(struct devinfo_rman
*rman
, void *arg
);
63 int print_ioports(struct devinfo_rman
*rman
, void *arg
);
64 int print_resource(struct devinfo_res
*res
, void *arg
);
68 bool GetInfo_CPU (Q3ListView
*lBox
)
70 // Modified 13 July 2000 for SMP by Brad Hughes - bhughes@trolltech.com
76 sysctlbyname("hw.ncpu", &ncpu
, &len
, NULL
, 0);
79 for (int i
= ncpu
; i
> 0; i
--) {
80 /* Stuff for sysctl */
84 // get the processor model
85 sysctlbyname("hw.model", NULL
, &len
, NULL
, 0);
87 sysctlbyname("hw.model", buf
, &len
, NULL
, 0);
89 // get the TSC speed if we can
91 if (sysctlbyname("machdep.tsc_freq", &i_buf
, &len
, NULL
, 0) != -1) {
92 cpustring
= i18n("CPU %1: %2, %3 MHz", i
, buf
, i_buf
/1000000);
94 cpustring
= i18n("CPU %1: %2, unknown speed", i
, buf
);
97 /* Put everything in the listbox */
98 new Q3ListViewItem(lBox
, cpustring
);
100 /* Clean up after ourselves, this time I mean it ;-) */
107 bool GetInfo_IRQ (Q3ListView
*lbox
)
109 #ifdef HAVE_DEVINFO_H
110 /* systat lists the interrupts assigned to devices as well as how many were
111 generated. Parsing its output however is about as fun as a sandpaper
112 enema. The best idea would probably be to rip out the guts of systat.
113 Too bad it's not very well commented */
114 /* Oh neat, current now has a neat little utility called devinfo */
117 devinfo_foreach_rman(print_irq
, lbox
);
124 bool GetInfo_DMA (Q3ListView
*lbox
)
126 #ifdef HAVE_DEVINFO_H
127 /* Oh neat, current now has a neat little utility called devinfo */
130 devinfo_foreach_rman(print_dma
, lbox
);
137 bool GetInfo_IO_Ports (Q3ListView
*lbox
)
139 #ifdef HAVE_DEVINFO_H
140 /* Oh neat, current now has a neat little utility called devinfo */
143 devinfo_foreach_rman(print_ioports
, lbox
);
150 bool GetInfo_Sound (Q3ListView
*lbox
)
152 QFile
*sndstat
= new QFile("/dev/sndstat");
155 Q3ListViewItem
*olditem
= 0;
157 if (!sndstat
->exists() || !sndstat
->open(QIODevice::ReadOnly
)) {
159 s
= i18n("Your sound system could not be queried. /dev/sndstat does not exist or is not readable.");
160 olditem
= new Q3ListViewItem(lbox
, olditem
, s
);
162 t
= new QTextStream(sndstat
);
163 while (!(s
=t
->readLine()).isNull()) {
164 olditem
= new Q3ListViewItem(lbox
, olditem
, s
);
175 bool GetInfo_SCSI (Q3ListView
*lbox
)
178 QFile
*camcontrol
= new QFile("/sbin/camcontrol");
181 Q3ListViewItem
*olditem
= 0;
183 if (!camcontrol
->exists()) {
184 s
= i18n ("SCSI subsystem could not be queried: /sbin/camcontrol could not be found");
185 olditem
= new Q3ListViewItem(lbox
, olditem
, s
);
186 } else if ((pipe
= popen("/sbin/camcontrol devlist 2>&1", "r")) == NULL
) {
187 s
= i18n ("SCSI subsystem could not be queried: /sbin/camcontrol could not be executed");
188 olditem
= new Q3ListViewItem(lbox
, olditem
, s
);
191 /* This prints out a list of all the scsi devies, perhaps eventually we could
192 parse it as opposed to schlepping it into a listbox */
194 t
= new QTextStream(pipe
, QIODevice::ReadOnly
);
200 olditem
= new Q3ListViewItem(lbox
, olditem
, s
);
209 if (!lbox
->childCount())
215 bool GetInfo_PCI (Q3ListView
*lbox
)
220 Q3ListViewItem
*olditem
= 0;
222 pcicontrol
= new QFile("/usr/sbin/pciconf");
224 if (!pcicontrol
->exists()) {
226 pcicontrol
= new QFile("/usr/X11R6/bin/scanpci");
227 if (!pcicontrol
->exists()) {
229 pcicontrol
= new QFile("/usr/X11R6/bin/pcitweak");
230 if (!pcicontrol
->exists()) {
232 s
= i18n("Could not find any programs with which to query your system's PCI information");
233 (void) new Q3ListViewItem(lbox
, 0, s
);
237 cmd
= "/usr/X11R6/bin/pcitweak -l 2>&1";
240 cmd
= "/usr/X11R6/bin/scanpci";
243 cmd
= "/usr/sbin/pciconf -l -v 2>&1";
247 if ((pipe
= popen(cmd
.toLatin1(), "r")) == NULL
) {
248 s
= i18n ("PCI subsystem could not be queried: %1 could not be executed", cmd
);
249 olditem
= new Q3ListViewItem(lbox
, olditem
, s
);
252 /* This prints out a list of all the pci devies, perhaps eventually we could
253 parse it as opposed to schlepping it into a listbox */
256 GetInfo_ReadfromPipe(lbox
, cmd
.toLatin1(), true);
259 if (!lbox
->childCount()) {
260 s
= i18n("The PCI subsystem could not be queried, this may need root privileges.");
261 olditem
= new Q3ListViewItem(lbox
, olditem
, s
);
268 bool GetInfo_Partitions (Q3ListView
*lbox
)
270 struct fstab
*fstab_ent
;
272 if (setfsent() != 1) /* Try to open fstab */ {
275 s
= i18n("Could not check filesystem info: ");
276 s
+= strerror(s_err
);
277 (void)new Q3ListViewItem(lbox
, 0, s
);
279 lbox
->addColumn(i18n("Device"));
280 lbox
->addColumn(i18n("Mount Point"));
281 lbox
->addColumn(i18n("FS Type"));
282 lbox
->addColumn(i18n("Mount Options"));
284 while ((fstab_ent
=getfsent())!=NULL
) {
285 new Q3ListViewItem(lbox
, fstab_ent
->fs_spec
,
286 fstab_ent
->fs_file
, fstab_ent
->fs_vfstype
,
287 fstab_ent
->fs_mntops
);
291 lbox
->header()->setClickEnabled(true);
293 endfsent(); /* Close fstab */
298 bool GetInfo_XServer_and_Video (Q3ListView
*lBox
)
300 return GetInfo_XServer_Generic( lBox
);
303 bool GetInfo_Devices (Q3ListView
*lbox
)
305 QFile
*f
= new QFile("/var/run/dmesg.boot");
306 if (f
->open(QIODevice::ReadOnly
)) {
308 Q3Dict
<Q3ListViewItem
> lv_items
;
310 QString line
, controller
;
311 lbox
->setRootIsDecorated(true);
312 lbox
->addColumn("Device");
313 lbox
->addColumn("Description");
314 while ( !(line
=qts
.readLine()).isNull() ) {
315 controller
= GetController(line
);
316 if (controller
.isNull())
321 // Ewww assuing motherboard is the only toplevel controller is rather gross
322 if (controller
== "motherboard") {
323 if (!lv_items
[dev
->name
]) {
324 lv_items
.insert(dev
->name
, new Q3ListViewItem(lbox
, dev
->name
, dev
->description
) );
327 Q3ListViewItem
*parent
=lv_items
[controller
];
328 if (parent
&& !lv_items
[dev
->name
]) {
329 lv_items
.insert(dev
->name
, new Q3ListViewItem(parent
, dev
->name
, dev
->description
) );
338 QString
GetController(const QString
&line
)
340 if ( ( (line
.startsWith("ad")) || (line
.startsWith("afd")) || (line
.startsWith("acd")) ) && (line
.find(":") < 6) ) {
341 QString controller
= line
;
342 controller
.remove(0, controller
.find(" at ")+4);
343 if (controller
.find("-slave") != -1) {
344 controller
.remove(controller
.find("-slave"), controller
.length());
345 } else if (controller
.find("-master") != -1) {
346 controller
.remove(controller
.find("-master"), controller
.length());
348 controller
=QString();
349 if (!controller
.isNull())
352 if (line
.find(" on ") != -1) {
355 controller
.remove(0, controller
.find(" on ")+4);
356 if (controller
.find(" ") != -1)
357 controller
.remove(controller
.find(" "), controller
.length());
363 Device
*GetDevice(const QString
&line
)
366 int colon
= line
.find(":");
370 dev
->name
= line
.mid(0, colon
);
371 dev
->description
= line
.mid(line
.find("<")+1, line
.length());
372 dev
->description
.remove(dev
->description
.find(">"), dev
->description
.length());
376 #ifdef HAVE_DEVINFO_H
378 int print_irq(struct devinfo_rman
*rman
, void *arg
)
380 Q3ListView
*lbox
= (Q3ListView
*)arg
;
381 if (strcmp(rman
->dm_desc
, "Interrupt request lines")==0) {
382 (void)new Q3ListViewItem(lbox
, 0, rman
->dm_desc
);
383 devinfo_foreach_rman_resource(rman
, print_resource
, arg
);
388 int print_dma(struct devinfo_rman
*rman
, void *arg
)
390 Q3ListView
*lbox
= (Q3ListView
*)arg
;
391 if (strcmp(rman
->dm_desc
, "DMA request lines")==0) {
392 (void)new Q3ListViewItem(lbox
, lbox
->lastItem(), rman
->dm_desc
);
393 devinfo_foreach_rman_resource(rman
, print_resource
, arg
);
398 int print_ioports(struct devinfo_rman
*rman
, void *arg
)
400 Q3ListView
*lbox
= (Q3ListView
*)arg
;
402 if (strcmp(rman
->dm_desc
, "I/O ports")==0) {
403 (void)new Q3ListViewItem(lbox
, lbox
->lastItem(), rman
->dm_desc
);
404 devinfo_foreach_rman_resource(rman
, print_resource
, arg
);
406 else if (strcmp(rman
->dm_desc
, "I/O memory addresses")==0) {
407 (void)new Q3ListViewItem(lbox
, lbox
->lastItem(), rman
->dm_desc
);
408 devinfo_foreach_rman_resource(rman
, print_resource
, arg
);
413 int print_resource(struct devinfo_res
*res
, void *arg
)
415 struct devinfo_dev
*dev
;
416 struct devinfo_rman
*rman
;
421 lbox
= (Q3ListView
*)arg
;
425 rman
= devinfo_handle_to_rman(res
->dr_rman
);
426 hexmode
= (rman
->dm_size
> 100) || (rman
->dm_size
== 0);
427 tmp
.sprintf(hexmode
? "0x%lx" : "%lu", res
->dr_start
);
429 if (res
->dr_size
> 1) {
430 tmp
.sprintf(hexmode
? "-0x%lx" : "-%lu",
431 res
->dr_start
+ res
->dr_size
- 1);
435 dev
= devinfo_handle_to_device(res
->dr_device
);
436 if ((dev
!= NULL
) && (dev
->dd_name
[0] != 0)) {
437 tmp
.sprintf(" (%s)", dev
->dd_name
);
439 tmp
.sprintf(" ----");
443 (void)new Q3ListViewItem(lbox
, lbox
->lastItem(), s
);