1 /*
2 * info_fbsd.cpp is part of the KDE program kcminfo. This displays
3 * various information about the system (hopefully a FreeBSD system)
4 * it's running on.
5 *
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.
9 */
10
11 /*
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.
15 */
16
17 #include "config-infocenter.h" // HAVE_DEVINFO_H
18 #include <sys/sysctl.h>
19 #include <sys/types.h>
20
21 #ifdef HAVE_DEVINFO_H
22 extern "C" {
23 #include <devinfo.h>
24 }
25 #endif
26
27 #include <string.h>
28
29 #include <QFileInfo>
30
31 #include <QTextStream>
32
33 void ProcessChildren(QString name);
34
35 #ifdef HAVE_DEVINFO_H
36 extern "C" {
37 int print_dma(struct devinfo_rman *rman, void *arg);
38 int print_ioports(struct devinfo_rman *rman, void *arg);
39 int print_resource(struct devinfo_res *res, void *arg);
40 }
41 #endif
42
GetInfo_DMA(QTreeWidget * tree)43 bool GetInfo_DMA(QTreeWidget *tree)
44 {
45 #ifdef HAVE_DEVINFO_H
46 /* Oh neat, current now has a neat little utility called devinfo */
47 if (devinfo_init())
48 return false;
49 devinfo_foreach_rman(print_dma, tree);
50 return true;
51 #else
52 return false;
53 #endif
54 }
55
GetInfo_IO_Ports(QTreeWidget * tree)56 bool GetInfo_IO_Ports(QTreeWidget *tree)
57 {
58 #ifdef HAVE_DEVINFO_H
59 /* Oh neat, current now has a neat little utility called devinfo */
60 if (devinfo_init())
61 return false;
62 devinfo_foreach_rman(print_ioports, tree);
63 return true;
64 #else
65 return false;
66 #endif
67 }
68
GetInfo_PCI(QTreeWidget * tree)69 bool GetInfo_PCI(QTreeWidget *tree)
70 {
71 FILE *pipe;
72 QString s, cmd;
73 QTreeWidgetItem *olditem = NULL;
74
75 const QStringList headers(i18nc("@title:column Column name for PCI information", "Information"));
76 tree->setHeaderLabels(headers);
77
78 if (!QFileInfo(QLatin1String("/usr/sbin/pciconf")).exists()) {
79 QStringList list;
80 list << i18n("Could not find any programs with which to query your system's PCI information");
81 new QTreeWidgetItem(tree, list);
82 return true;
83 } else {
84 cmd = "/usr/sbin/pciconf -l -v 2>&1";
85 }
86
87 // TODO: GetInfo_ReadfromPipe should be improved so that we could pass the program name and its
88 // arguments to it and remove most of the code below.
89 if ((pipe = popen(cmd.toLatin1(), "r")) == NULL) {
90 QStringList list;
91 list << i18n("PCI subsystem could not be queried: %1 could not be executed", cmd);
92 olditem = new QTreeWidgetItem(olditem, list);
93 } else {
94 /* This prints out a list of all the pci devies, perhaps eventually we could
95 parse it as opposed to schlepping it into a listbox */
96 QTextStream outputStream(pipe, QIODevice::ReadOnly);
97
98 while (!outputStream.atEnd()) {
99 s = outputStream.readLine();
100 if (s.isEmpty())
101 break;
102 const QStringList list(s);
103 new QTreeWidgetItem(tree, list);
104 }
105
106 pclose(pipe);
107 }
108
109 if (!tree->topLevelItemCount()) {
110 QString str = i18n("The PCI subsystem could not be queried, this may need root privileges.");
111 olditem = new QTreeWidgetItem(tree, olditem);
112 olditem->setText(0, str);
113 return true;
114 }
115
116 return true;
117 }
118
GetInfo_XServer_and_Video(QTreeWidget * tree)119 bool GetInfo_XServer_and_Video(QTreeWidget *tree)
120 {
121 return GetInfo_XServer_Generic(tree);
122 }
123
124 #ifdef HAVE_DEVINFO_H
125
print_dma(struct devinfo_rman * rman,void * arg)126 int print_dma(struct devinfo_rman *rman, void *arg)
127 {
128 QTreeWidget *tree = (QTreeWidget *)arg;
129 if (strcmp(rman->dm_desc, "DMA request lines") == 0) {
130 QStringList list;
131 list << rman->dm_desc;
132 new QTreeWidgetItem(tree, list);
133 devinfo_foreach_rman_resource(rman, print_resource, arg);
134 }
135 return (0);
136 }
137
print_ioports(struct devinfo_rman * rman,void * arg)138 int print_ioports(struct devinfo_rman *rman, void *arg)
139 {
140 QTreeWidget *tree = (QTreeWidget *)arg;
141
142 if (strcmp(rman->dm_desc, "I/O ports") == 0) {
143 QStringList list;
144 list << rman->dm_desc;
145 new QTreeWidgetItem(tree, list);
146
147 devinfo_foreach_rman_resource(rman, print_resource, arg);
148 } else if (strcmp(rman->dm_desc, "I/O memory addresses") == 0) {
149 QStringList list;
150 list << rman->dm_desc;
151 new QTreeWidgetItem(tree, list);
152
153 devinfo_foreach_rman_resource(rman, print_resource, arg);
154 }
155 return 0;
156 }
157
print_resource(struct devinfo_res * res,void * arg)158 int print_resource(struct devinfo_res *res, void *arg)
159 {
160 struct devinfo_dev *dev;
161 struct devinfo_rman *rman;
162 int hexmode;
163
164 QTreeWidget *tree = (QTreeWidget *)arg;
165
166 QString s, tmp;
167
168 rman = devinfo_handle_to_rman(res->dr_rman);
169 hexmode = (rman->dm_size > 100) || (rman->dm_size == 0);
170 tmp.sprintf(hexmode ? "0x%lx" : "%lu", res->dr_start);
171 s += tmp;
172 if (res->dr_size > 1) {
173 tmp.sprintf(hexmode ? "-0x%lx" : "-%lu", res->dr_start + res->dr_size - 1);
174 s += tmp;
175 }
176
177 dev = devinfo_handle_to_device(res->dr_device);
178 if ((dev != NULL) && (dev->dd_name[0] != 0)) {
179 tmp.sprintf(" (%s)", dev->dd_name);
180 } else {
181 tmp.sprintf(" ----");
182 }
183 s += tmp;
184
185 QStringList list;
186 list << s;
187 new QTreeWidgetItem(tree, list);
188
189 return 0;
190 }
191
192 #endif
193