add more spacing
[personal-kdebase.git] / apps / kinfocenter / base / info_aix.cpp
blob0ba653ef1be1156b56c5243287d03e92baa108df
1 /*
2 * info_aix.cpp
4 * Reza Arbab <arbab@austin.ibm.com>
6 * GetInfo_Partitions() and its helpers (get_fs_usage, fs_adjust_blocks)
7 * taken from info_hpux.cpp.
9 */
11 #include <cf.h>
12 #define class _class
13 #include <odmi.h>
14 #include <sys/cfgodm.h>
15 #include <sys/cfgdb.h>
16 #undef class
17 #include <nl_types.h>
18 #include <string.h>
19 #include <kdebug.h>
20 #include <stdlib.h>
22 #include <sys/statfs.h>
23 #include <sys/statvfs.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <fstab.h>
28 #include <errno.h>
29 #include <sys/utsname.h>
31 char * device_description(struct CuDv *cudv) {
32 char *desc= NULL;
33 struct PdDv *pddv = cudv->PdDvLn; /* link to Predefined Devices database */
34 nl_catd cat;
36 cat = catopen("/usr/lib/methods/devices.cat", NL_CAT_LOCALE);
37 if ((int)cat == -1)
38 return NULL;
40 desc = strdup(catgets(cat, pddv->setno, pddv->msgno, "N/A") );
41 catclose(cat);
43 return desc;
46 bool list_devices(QListView *lBox, char *criteria) {
47 struct CuDv *cudv; /* Customized Devices */
48 struct listinfo info;
49 int i;
50 char *cudv_desc;
51 QString cudv_status;
52 QListViewItem *lastitem= NULL;
54 lBox->addColumn(i18n("Name"));
55 lBox->addColumn(i18n("Status"));
56 lBox->addColumn(i18n("Location"));
57 lBox->addColumn(i18n("Description"));
59 if (odm_initialize() == -1) {
60 kError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl;
61 return (false);
64 cudv = (struct CuDv *) odm_get_list(CuDv_CLASS, criteria, &info, 100, 2);
66 if ((int)cudv == -1) {
67 odm_terminate();
68 kError(0) << "odm_get_list() failed: odmerrno = " << odmerrno << endl;
69 return (false);
70 } else if (!cudv) /* empty list */
72 odm_terminate();
73 return (true);
76 for (i=0; i<info.num; i++) {
77 switch (cudv[i].status) {
78 case DEFINED:
79 cudv_status = QString("Defined");
80 break;
81 case AVAILABLE:
82 cudv_status = QString("Available");
83 break;
84 case STOPPED:
85 cudv_status = QString("Stopped");
86 break;
87 default:
88 cudv_status = QString("Unknown");
90 cudv_desc = device_description(&cudv[i]);
92 lastitem = new QListViewItem(lBox, lastitem,
93 QString(cudv[i].name),
94 cudv_status,
95 QString(cudv[i].location),
96 QString(cudv_desc ? cudv_desc : "N/A") );
98 if (cudv_desc)
99 free(cudv_desc);
102 if (odm_free_list(cudv, &info) == -1) {
103 odm_terminate();
104 kError(0) << "odm_free_list() failed: odmerrno = " << odmerrno << endl;
105 return (false);
108 odm_terminate();
109 return true;
112 enum CHIP
114 P2SC, Power, Power2, Power3, Power3_II, PowerPC,
115 PowerPC_604e, PowerPersonal, RD64_II, RS_III, RS64, RS64_II,
116 RS64_III, RS64_IV, RSC, ThinkPad, unknown,
117 NUM_CHIPS
119 static const char chip_name[NUM_CHIPS][16] = { "P2SC", "Power", "Power2", "Power3", "Power3-II", "PowerPC", "PowerPC 604e", "PowerPersonal", "RD64-II", "RS-III", "RS64", "RS64-II", "RS64-III", "RS64-IV", "RSC", "ThinkPad", "unknown" };
121 struct model {
122 char model_ID[21];
123 char machine_type[21];
124 char processor_speed[21];
125 unsigned short architecture; /* enum CHIP */
128 struct model _models[] = { { "02", "7015-930", "25", Power }, { "10", "7013-530", "25", Power }, { "10", "7016-730", "25", Power }, { "11", "7013-540", "30", Power }, { "14", "7013-540", "30", Power }, { "18", "7013-53H", "33", Power }, { "1C", "7013-550", "41.6", Power }, { "20", "7015-930", "25",
129 Power }, { "2E", "7015-950", "41", Power }, { "30", "7013-520", "20", Power }, { "31", "7012-320", "20", Power }, { "34", "7013-52H", "25", Power }, { "35", "7012-32H", "25", Power }, { "37", "7012-340", "33", Power }, { "38", "7012-350", "41", Power }, { "41", "7011-20", "33", PowerPC }, {
130 "45", "7011-220", "33", PowerPC }, { "42", "7006-41T/41W", "80", PowerPC }, { "43", "7008-M20", "33", Power }, { "43", "7008-M2A", "33", Power }, { "46", "7011-250", "66", PowerPC }, { "47", "7011-230", "45", RSC }, { "48", "7009-C10", "80", PowerPC },
131 /* 4C models use a different table -- see below */
132 { "4C", "70XX", "(unknown)", unknown }, { "57", "7012-390", "67", Power2 }, { "57", "7030-3BT", "67", Power2 }, { "57", "9076-SP2 Thin", "67", Power2 }, { "58", "7012-380", "59", Power2 }, { "58", "7030-3AT", "59", Power2 }, { "59", "7012-39H", "67", Power2 }, { "59", "9076-SP2 Thin w/L2", "67",
133 Power2 }, { "5C", "7013-560", "50", Power }, { "63", "7015-970", "50", Power }, { "63", "7015-97B", "50", Power }, { "64", "7015-980", "62.5", Power }, { "64", "7015-98B", "62.5", Power }, { "66", "7013-580", "62.5", Power }, { "67", "7013-570", "50", Power }, { "67", "7015-R10", "50",
134 Power }, { "70", "7013-590", "66", Power2 }, { "70", "9076-SP2 Wide", "66", Power2 }, { "71", "7013-58H", "55", Power2 }, { "72", "7013-59H", "66", Power2 }, { "72", "7015-R20", "66", Power2 }, { "72", "9076-SP2 Wide", "66", Power2 }, { "75", "7012-370", "62", Power }, { "75", "7012-375",
135 "62", Power }, { "75", "9076-SP1 Thin", "62", Power }, { "76", "7012-360", "50", Power }, { "76", "7012-365", "50", Power }, { "77", "7012-350", "41", Power }, { "77", "7012-355", "41", Power }, { "77", "7013-55L", "41.6", Power }, { "79", "7013-591", "77", Power2 }, { "79",
136 "9076-SP2 Wide", "77", Power2 }, { "80", "7015-990", "71.5", Power2 }, { "81", "7015-R24", "71.5", P2SC }, { "89", "7013-595", "135", P2SC }, { "89", "9076-SP2 Wide", "135", P2SC }, { "90", "7009-C20", "120", PowerPC }, { "91", "7006-42W/42T", "120", PowerPC }, { "94", "7012-397", "160",
137 P2SC }, { "94", "9076-SP2 Thin", "160", P2SC }, { "A0", "7013-J30", "75", PowerPC }, { "A1", "7013-J40", "112", PowerPC }, { "A3", "7015-R30", "(unknown)", PowerPC }, { "A4", "7015-R40", "(unknown)", PowerPC }, { "A4", "7015-R50", "(unknown)", PowerPC }, { "A4", "9076-SP2 High",
138 "(unknown)", PowerPC }, { "A6", "7012-G30", "(unknown)", PowerPC }, { "A7", "7012-G40", "(unknown)", PowerPC }, { "C0", "7024-E20", "(unknown)", PowerPC }, { "C0", "7024-E30", "(unknown)", PowerPC }, { "C4", "7025-F30", "(unknown)", PowerPC }, { "F0", "7007-N40", "50", ThinkPad }, { "", "",
139 "0", 0 } };
141 struct model _4C_models[] = { { "IBM,7017-S70", "7017-S70", "125", RS64 }, { "IBM,7017-S7A", "7017-S7A", "262", RD64_II }, { "IBM,7017-S80", "7017-S80", "450", RS_III }, { "IBM,7017-S85", "pSeries 680", "600", RS64_IV }, { "IBM,7025-F40", "7025-F40", "166/233", PowerPC_604e }, { "IBM,7025-F50",
142 "7025-F50", "(unknown)", PowerPC_604e }, { "IBM,7025-F80", "7025-F80", "(unknown)", RS64_III }, { "IBM,7026-H10", "7025-H10", "166/233", PowerPC_604e }, { "IBM,7026-H50", "7025-H50", "(unknown)", PowerPC_604e }, { "IBM,7026-H80", "7025-H80", "(unknown)", RS64_III }, { "IBM,7026-M80",
143 "7026-M80", "500", RS64_III }, { "IBM,7025-F40", "7025-F40", "166/233", PowerPC }, { "IBM,7025-F50", "7025-F50", "(unknown)", PowerPC }, { "IBM,7025-F80", "7025-F80", "450", PowerPC }, { "IBM,7026-B80", "pSeries 640", "375", Power3_II }, { "IBM,7026-H10", "7026-H10", "166/233", PowerPC }, {
144 "IBM,7026-H50", "7026-H50", "(unknown)", PowerPC }, { "IBM,7026-H70", "7026-H70", "340", RS64_II }, { "IBM,7026-H80", "7026-H80", "450", PowerPC }, { "IBM,7026-M80", "7026-M80", "500", PowerPC }, { "IBM,7042-140", "7043-140", "166/200/233/332", PowerPC }, { "IBM,7042-150", "7043-150",
145 "375", PowerPC }, { "IBM,7042-240", "7043-240", "166/233", PowerPC }, { "IBM,7043-140", "7043-140", "166/200/233/332", PowerPC }, { "IBM,7043-150", "7043-150", "375", PowerPC }, { "IBM,7043-240", "7043-240", "166/233", PowerPC }, { "IBM,7043-260", "7043-260", "200", Power3 }, { "IBM,7248",
146 "7248-100", "100", PowerPersonal }, { "IBM,7248", "7248-120", "120", PowerPersonal }, { "IBM,7248", "7248-132", "132", PowerPersonal }, { "IBM,9076-270", "9076-SP Silver Node", "(unknown)", PowerPC }, { "", "", "", 0 },
149 /* all GetInfo_ functions should return true, when the Information
150 was filled into the lBox-Widget.
151 returning false indicates, that information was not available.
154 bool GetInfo_XServer_and_Video(QListView *lBox) {
155 return GetInfo_XServer_Generic(lBox);
159 * Written using information from:
161 * http://service.software.ibm.com/cgi-bin/support/rs6000.support/techbrowse/tbgaus?gaus_mode=8&documents=B93576892313352&database=task
163 * Not fully implemented. In particular there are ways to resolve the
164 * "(unknown)" clock speeds of many of these models. See page for details.
167 bool GetInfo_CPU(QListView *lBox) {
168 struct utsname info;
169 struct model *table = _models; /* table of model information */
170 char model_ID[21] = ""; /* information for table lookup */
171 char cpu_ID[7] = ""; /* unique CPU ID */
172 int i;
173 QListViewItem *lastitem= NULL;
175 lBox->addColumn(i18n("Information"));
176 lBox->addColumn(i18n("Value"));
178 if (uname(&info) == -1) {
179 kError(0) << "uname() failed: errno = " << errno << endl;
180 return false;
183 strncat(model_ID, info.machine+8, 2); /* we want the ninth and tenth digits */
184 strncat(cpu_ID, info.machine+2, 6);
186 if (strcmp(model_ID, "4C") == 0) /* need to use a different model_ID and model table */
188 if (odm_initialize() == -1)
189 kError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl;
190 else {
191 struct CuAt cuat; /* Customized Device attribute */
193 /* equivalent to uname -M */
194 if (odm_get_first(CuAt_CLASS, (char *)"name='sys0' and attribute='modelname'", &cuat) ) {
195 strcpy(model_ID, cuat.value);
196 table = _4C_models;
199 odm_terminate();
203 lastitem = new QListViewItem(lBox, lastitem, QString("CPU ID"), QString(cpu_ID));
204 lastitem = new QListViewItem(lBox, lastitem, QString("Node"), QString(info.nodename));
205 lastitem = new QListViewItem(lBox, lastitem, QString("OS"), QString(info.sysname) +
206 QString(" ") + QString(info.version) + QString(".") + QString(info.release));
208 for (i=0; *(table[i].model_ID); i++)
209 if (strcmp(model_ID, table[i].model_ID) == 0) {
210 lastitem = new QListViewItem(lBox, lastitem, QString("Machine Type"), QString(table[i].machine_type));
211 lastitem = new QListViewItem(lBox, lastitem, QString("Architecture"), QString(chip_name[table[i].architecture]));
212 lastitem = new QListViewItem(lBox, lastitem, QString("Speed"), QString(table[i].processor_speed) + QString(" Mhz"));
213 break;
216 return (true);
219 bool GetInfo_IRQ(QListView *) {
220 return false;
223 bool GetInfo_DMA(QListView *) {
224 return false;
227 bool GetInfo_PCI(QTreeWidget* tree) {
228 return list_devices(tree, (char *)"PdDvLn like '*/pci/*'");
231 bool GetInfo_IO_Ports(QListView *) {
232 return false;
235 bool GetInfo_Sound(QListView *) {
236 return false;
239 bool GetInfo_Devices(QListView *lBox) {
240 return list_devices(lBox, (char *)"PdDvLn like '*'");
243 bool GetInfo_SCSI(QListView *lBox) {
244 return list_devices(lBox, (char *)"PdDvLn like '*/scsi/*'");
247 /* Parts taken from fsusage.c from the Midnight Commander (mc)
249 Copyright (C) 1991, 1992 Free Software Foundation, In
251 Return the number of TOSIZE-byte blocks used by
252 BLOCKS FROMSIZE-byte blocks, rounding away from zero.
253 TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
255 static long fs_adjust_blocks(long blocks, int fromsize, int tosize) {
256 if (tosize <= 0)
257 abort();
258 if (fromsize <= 0)
259 return -1;
261 if (fromsize == tosize) /* E.g., from 512 to 512. */
262 return blocks;
263 else if (fromsize > tosize) /* E.g., from 2048 to 512. */
264 return blocks * (fromsize / tosize);
265 else
266 /* E.g., from 256 to 512. */
267 return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
270 /* Fill in the fields of FSP with information about space usage for
271 the filesystem on which PATH resides.
272 Return 0 if successful, -1 if not. */
274 #define CONVERT_BLOCKS(b) fs_adjust_blocks ((b), fsd.f_bsize, 512)
276 static int get_fs_usage(char *path, long *l_total, long *l_avail) {
277 struct statfs fsd; /* 4.3BSD, SunOS 4, HP-UX, AIX. */
278 unsigned long fsu_blocks, fsu_bfree, fsu_bavail;
280 *l_total = *l_avail = 0;
281 if (statfs(path, &fsd) < 0)
282 return -1;
284 fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
285 fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
286 fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
288 *l_avail = getuid() ? fsu_bavail/2 : fsu_bfree/2;
289 *l_total = fsu_blocks/2;
291 return 0;
294 // Some Ideas taken from garbazo from his source in info_fbsd.cpp
296 bool GetInfo_Partitions(QListView *lbox) {
297 #define NUMCOLS 5
298 QString Title[NUMCOLS];
299 int n;
301 struct fstab *fstab_ent;
302 struct statvfs svfs;
303 long total, avail;
304 QString str;
305 QString MB(i18n("MB")+ " "); // International Text for MB=Mega-Byte
307 if (setfsent() != 1) // Try to open fstab
308 return false;
310 Title[0] = i18n("Device");
311 Title[1] = i18n("Mount Point");
312 Title[2] = i18n("FS Type");
313 Title[3] = i18n("Total Size");
314 Title[4] = i18n("Free Size");
316 for (n=0; n<NUMCOLS; ++n) {
317 lbox->addColumn(Title[n]);
320 while ((fstab_ent=getfsent())!=NULL) {
321 /* fstab_ent->fs_type holds only "rw","xx","ro"... */
322 memset(&svfs, 0, sizeof(svfs));
323 statvfs(fstab_ent->fs_file, &svfs);
324 get_fs_usage(fstab_ent->fs_file, &total, &avail);
326 if (!strcmp(fstab_ent->fs_type, FSTAB_XX)) // valid drive ?
327 svfs.f_basetype[0] = 0;
329 if (svfs.f_basetype[0]) {
330 new QListViewItem(lbox, QString(fstab_ent->fs_spec),
331 QString(fstab_ent->fs_file) + QString(" "),
332 (svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")),
333 Value((total+512)/1024,6) + MB,
334 Value((avail+512)/1024,6) + MB);
335 } else {
336 new QListViewItem(lbox, QString(fstab_ent->fs_spec),
337 QString(fstab_ent->fs_file) + QString(" "),
338 (svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")));
342 endfsent();
344 return true;