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.
12 * all following functions should return true, when the Information
13 * was filled into the QTreeWidget. Returning false indicates that
14 * information was not available.
17 #include "config-infocenter.h" // HAVE_DEVINFO_H
18 #include <sys/types.h>
19 #include <sys/sysctl.h>
34 #include <QTextStream>
38 Device(QString n
=QString(), QString d
=QString()) {
42 QString name
, description
;
45 void ProcessChildren(QString name
);
46 QString
GetController(const QString
&line
);
47 Device
*GetDevice(const QString
&line
);
51 int print_irq(struct devinfo_rman
*rman
, void *arg
);
52 int print_dma(struct devinfo_rman
*rman
, void *arg
);
53 int print_ioports(struct devinfo_rman
*rman
, void *arg
);
54 int print_resource(struct devinfo_res
*res
, void *arg
);
58 bool GetInfo_CPU(QTreeWidget
* tree
) {
59 // Modified 13 July 2000 for SMP by Brad Hughes - bhughes@trolltech.com
65 sysctlbyname("hw.ncpu", &ncpu
, &len
, NULL
, 0);
68 for (int i
= ncpu
; i
> 0; i
--) {
69 /* Stuff for sysctl */
73 // get the processor model
74 sysctlbyname("hw.model", NULL
, &len
, NULL
, 0);
76 sysctlbyname("hw.model", buf
, &len
, NULL
, 0);
78 // get the TSC speed if we can
80 if (sysctlbyname("machdep.tsc_freq", &i_buf
, &len
, NULL
, 0) != -1) {
81 cpustring
= i18n("CPU %1: %2, %3 MHz", i
, buf
, i_buf
/1000000);
83 cpustring
= i18n("CPU %1: %2, unknown speed", i
, buf
);
86 /* Put everything in the listbox */
89 new QTreeWidgetItem(tree
, list
);
91 /* Clean up after ourselves, this time I mean it ;-) */
98 bool GetInfo_IRQ(QTreeWidget
* tree
) {
100 /* systat lists the interrupts assigned to devices as well as how many were
101 generated. Parsing its output however is about as fun as a sandpaper
102 enema. The best idea would probably be to rip out the guts of systat.
103 Too bad it's not very well commented */
104 /* Oh neat, current now has a neat little utility called devinfo */
107 devinfo_foreach_rman(print_irq
, tree
);
114 bool GetInfo_DMA(QTreeWidget
* tree
) {
115 #ifdef HAVE_DEVINFO_H
116 /* Oh neat, current now has a neat little utility called devinfo */
119 devinfo_foreach_rman(print_dma
, tree
);
126 bool GetInfo_IO_Ports(QTreeWidget
* tree
) {
127 #ifdef HAVE_DEVINFO_H
128 /* Oh neat, current now has a neat little utility called devinfo */
131 devinfo_foreach_rman(print_ioports
, tree
);
138 bool GetInfo_Sound(QTreeWidget
* tree
) {
139 QFile
*sndstat
= new QFile("/dev/sndstat");
143 if (!sndstat
->exists() || !sndstat
->open(QIODevice::ReadOnly
)) {
145 s
= i18n("Your sound system could not be queried. /dev/sndstat does not exist or is not readable.");
148 new QTreeWidgetItem(tree
, list
);
150 t
= new QTextStream(sndstat
);
151 while (!(s
=t
->readLine()).isNull()) {
155 new QTreeWidgetItem(tree
, list
);
166 bool GetInfo_SCSI(QTreeWidget
* tree
) {
168 QFile
*camcontrol
= new QFile("/sbin/camcontrol");
172 if (!camcontrol
->exists()) {
173 s
= i18n("SCSI subsystem could not be queried: /sbin/camcontrol could not be found");
176 new QTreeWidgetItem(tree
, list
);
177 } else if ((pipe
= popen("/sbin/camcontrol devlist 2>&1", "r")) == NULL
) {
178 s
= i18n("SCSI subsystem could not be queried: /sbin/camcontrol could not be executed");
181 new QTreeWidgetItem(tree
, list
);
184 /* This prints out a list of all the scsi devies, perhaps eventually we could
185 parse it as opposed to schlepping it into a listbox */
187 t
= new QTextStream(pipe
, QIODevice::ReadOnly
);
195 new QTreeWidgetItem(tree
, list
);
204 if (!tree
->topLevelItemCount())
210 bool GetInfo_PCI(QTreeWidget
* tree
) {
214 QTreeWidgetItem
*olditem
= NULL
;
216 pcicontrol
= new QFile("/usr/sbin/pciconf");
218 if (!pcicontrol
->exists()) {
220 pcicontrol
= new QFile("/usr/X11R6/bin/scanpci");
221 if (!pcicontrol
->exists()) {
223 pcicontrol
= new QFile("/usr/X11R6/bin/pcitweak");
224 if (!pcicontrol
->exists()) {
226 list
<< i18n("Could not find any programs with which to query your system's PCI information");
227 new QTreeWidgetItem(tree
, list
);
231 cmd
= "/usr/X11R6/bin/pcitweak -l 2>&1";
234 cmd
= "/usr/X11R6/bin/scanpci";
237 cmd
= "/usr/sbin/pciconf -l -v 2>&1";
241 if ((pipe
= popen(cmd
.toLatin1(), "r")) == NULL
) {
243 list
<< i18n("PCI subsystem could not be queried: %1 could not be executed", cmd
);
244 olditem
= new QTreeWidgetItem(olditem
, list
);
247 /* This prints out a list of all the pci devies, perhaps eventually we could
248 parse it as opposed to schlepping it into a listbox */
251 GetInfo_ReadfromPipe(tree
, cmd
.toLatin1(), true);
254 if (!tree
->topLevelItemCount()) {
255 QString str
= i18n("The PCI subsystem could not be queried, this may need root privileges.");
256 olditem
= new QTreeWidgetItem(tree
, olditem
);
257 olditem
->setText(0, str
);
264 bool GetInfo_Partitions(QTreeWidget
* tree
) {
265 struct fstab
*fstab_ent
;
267 if (setfsent() != 1) /* Try to open fstab */{
270 s
= i18n("Could not check file system info: ");
271 s
+= strerror(s_err
);
274 new QTreeWidgetItem(tree
, list
);
277 headers
<< i18n("Device") << i18n("Mount Point") << i18n("FS Type") << i18n("Mount Options");
279 while ((fstab_ent
=getfsent())!=NULL
) {
281 list
<< fstab_ent
->fs_spec
<< fstab_ent
->fs_file
<< fstab_ent
->fs_vfstype
<< fstab_ent
->fs_mntops
;
282 new QTreeWidgetItem(tree
, list
);
285 tree
->sortItems(0, Qt::AscendingOrder
);
287 endfsent(); /* Close fstab */
292 bool GetInfo_XServer_and_Video(QTreeWidget
* tree
) {
293 return GetInfo_XServer_Generic(tree
);
296 bool GetInfo_Devices(QTreeWidget
* tree
) {
297 QFile
*f
= new QFile("/var/run/dmesg.boot");
298 if (f
->open(QIODevice::ReadOnly
)) {
300 QMap
<QString
, QTreeWidgetItem
*> lv_items
;
302 QString line
, controller
;
303 tree
->setRootIsDecorated(true);
305 headers
<< i18n("Device") << i18n("Description");
306 tree
->setHeaderLabels(headers
);
307 while ( !(line
=qts
.readLine()).isNull() ) {
308 controller
= GetController(line
);
309 if (controller
.isNull())
314 // Ewww assuing motherboard is the only toplevel controller is rather gross
315 if (controller
== "motherboard") {
316 if (lv_items
.contains(QString(dev
->name
))==false) {
318 list
<< dev
->name
<< dev
->description
;
320 lv_items
.insert(QString(dev
->name
), new QTreeWidgetItem(tree
, list
));
323 QTreeWidgetItem
* parent
=lv_items
[controller
];
324 if (parent
&& lv_items
.contains(dev
->name
)==false) {
326 list
<< dev
->name
<< dev
->description
;
327 lv_items
.insert(QString(dev
->name
), new QTreeWidgetItem(parent
, list
));
338 QString
GetController(const QString
&line
) {
339 if ( ( (line
.startsWith("ad")) || (line
.startsWith("afd")) || (line
.startsWith("acd")) ) && (line
.indexOf(":") < 6)) {
340 QString controller
= line
;
341 controller
.remove(0, controller
.indexOf(" at ")+4);
342 if (controller
.indexOf("-slave") != -1) {
343 controller
.remove(controller
.indexOf("-slave"), controller
.length());
344 } else if (controller
.indexOf("-master") != -1) {
345 controller
.remove(controller
.indexOf("-master"), controller
.length());
347 controller
=QString();
348 if (!controller
.isNull())
351 if (line
.indexOf(" on ") != -1) {
354 controller
.remove(0, controller
.indexOf(" on ")+4);
355 if (controller
.indexOf(" ") != -1)
356 controller
.remove(controller
.indexOf(" "), controller
.length());
362 Device
*GetDevice(const QString
&line
) {
364 int colon
= line
.indexOf(":");
368 dev
->name
= line
.mid(0, colon
);
369 dev
->description
= line
.mid(line
.indexOf("<")+1, line
.length());
370 dev
->description
.remove(dev
->description
.indexOf(">"), dev
->description
.length());
374 #ifdef HAVE_DEVINFO_H
376 int print_irq(struct devinfo_rman
*rman
, void *arg
) {
377 QTreeWidget
* tree
= (QTreeWidget
*)arg
;
378 if (strcmp(rman
->dm_desc
, "Interrupt request lines")==0) {
381 list
<< rman
->dm_desc
;
382 new QTreeWidgetItem(tree
, list
);
383 devinfo_foreach_rman_resource(rman
, print_resource
, arg
);
388 int print_dma(struct devinfo_rman
*rman
, void *arg
)
390 QTreeWidget
* tree
= (QTreeWidget
*)arg
;
391 if (strcmp(rman
->dm_desc
, "DMA request lines")==0) {
393 list
<< rman
->dm_desc
;
394 new QTreeWidgetItem(tree
, list
);
395 devinfo_foreach_rman_resource(rman
, print_resource
, arg
);
400 int print_ioports(struct devinfo_rman
*rman
, void *arg
)
402 QTreeWidget
* tree
= (QTreeWidget
*) arg
;
404 if (strcmp(rman
->dm_desc
, "I/O ports")==0) {
406 list
<< rman
->dm_desc
;
407 new QTreeWidgetItem(tree
, list
);
409 devinfo_foreach_rman_resource(rman
, print_resource
, arg
);
411 else if (strcmp(rman
->dm_desc
, "I/O memory addresses")==0) {
413 list
<< rman
->dm_desc
;
414 new QTreeWidgetItem(tree
, list
);
416 devinfo_foreach_rman_resource(rman
, print_resource
, arg
);
421 int print_resource(struct devinfo_res
*res
, void *arg
)
423 struct devinfo_dev
*dev
;
424 struct devinfo_rman
*rman
;
427 QTreeWidget
* tree
= (QTreeWidget
*) arg
;
431 rman
= devinfo_handle_to_rman(res
->dr_rman
);
432 hexmode
= (rman
->dm_size
> 100) || (rman
->dm_size
== 0);
433 tmp
.sprintf(hexmode
? "0x%lx" : "%lu", res
->dr_start
);
435 if (res
->dr_size
> 1) {
436 tmp
.sprintf(hexmode
? "-0x%lx" : "-%lu",
437 res
->dr_start
+ res
->dr_size
- 1);
441 dev
= devinfo_handle_to_device(res
->dr_device
);
442 if ((dev
!= NULL
) && (dev
->dd_name
[0] != 0)) {
443 tmp
.sprintf(" (%s)", dev
->dd_name
);
445 tmp
.sprintf(" ----");
451 new QTreeWidgetItem(tree
, list
);