Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / kinfocenter / info / info_aix.cpp
blob84ba1390b0b9bc13ef45adf58be3d8e77c2c3e85
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 #define INFO_DEVICES_AVAILABLE
23 #define INFO_SCSI_AVAILABLE
24 #define INFO_PCI_AVAILABLE
26 #include <sys/statfs.h>
27 #include <sys/statvfs.h>
28 #include <sys/types.h>
29 #include <unistd.h>
30 #include <fstab.h>
32 #define INFO_PARTITIONS_AVAILABLE
34 #include <errno.h>
35 #include <sys/utsname.h>
37 #define INFO_CPU_AVAILABLE
39 #define INFO_IRQ_AVAILABLE
40 #define INFO_DMA_AVAILABLE
41 #define INFO_IOPORTS_AVAILABLE
42 #define INFO_SOUND_AVAILABLE
43 #define INFO_XSERVER_AVAILABLE
45 char *
46 device_description(struct CuDv *cudv)
48 char *desc = NULL;
49 struct PdDv *pddv = cudv->PdDvLn; /* link to Predefined Devices database */
50 nl_catd cat;
52 cat = catopen("/usr/lib/methods/devices.cat", NL_CAT_LOCALE);
53 if ((int)cat == -1)
54 return NULL;
56 desc = strdup( catgets(cat, pddv->setno, pddv->msgno, "N/A") );
57 catclose(cat);
59 return desc;
62 bool
63 list_devices(QListView *lBox, char *criteria)
65 struct CuDv *cudv; /* Customized Devices */
66 struct listinfo info;
67 int i;
68 char *cudv_desc;
69 QString cudv_status;
70 QListViewItem *lastitem = NULL;
72 lBox->addColumn(i18n("Name"));
73 lBox->addColumn(i18n("Status"));
74 lBox->addColumn(i18n("Location"));
75 lBox->addColumn(i18n("Description"));
77 if (odm_initialize() == -1)
79 kError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl;
80 return(false);
83 cudv = (struct CuDv *) odm_get_list(CuDv_CLASS, criteria, &info, 100, 2);
85 if ((int)cudv == -1)
87 odm_terminate();
88 kError(0) << "odm_get_list() failed: odmerrno = " << odmerrno << endl;
89 return(false);
91 else if (!cudv) /* empty list */
93 odm_terminate();
94 return(true);
97 for (i=0; i<info.num; i++)
99 switch(cudv[i].status)
101 case DEFINED: cudv_status = QString("Defined"); break;
102 case AVAILABLE: cudv_status = QString("Available"); break;
103 case STOPPED: cudv_status = QString("Stopped"); break;
104 default: cudv_status = QString("Unknown");
106 cudv_desc = device_description(&cudv[i]);
108 lastitem = new QListViewItem(lBox, lastitem,
109 QString(cudv[i].name),
110 cudv_status,
111 QString(cudv[i].location),
112 QString(cudv_desc ? cudv_desc : "N/A") );
114 if (cudv_desc) free(cudv_desc);
117 if (odm_free_list(cudv, &info) == -1)
119 odm_terminate();
120 kError(0) << "odm_free_list() failed: odmerrno = " << odmerrno << endl;
121 return(false);
124 odm_terminate();
125 return true;
128 enum CHIP
130 P2SC, Power, Power2, Power3, Power3_II, PowerPC,
131 PowerPC_604e, PowerPersonal, RD64_II, RS_III, RS64, RS64_II,
132 RS64_III, RS64_IV, RSC, ThinkPad, unknown,
133 NUM_CHIPS
135 static const char chip_name[NUM_CHIPS][16] =
137 "P2SC", "Power", "Power2", "Power3", "Power3-II", "PowerPC",
138 "PowerPC 604e", "PowerPersonal", "RD64-II", "RS-III", "RS64", "RS64-II",
139 "RS64-III", "RS64-IV", "RSC", "ThinkPad", "unknown"
142 struct model
144 char model_ID[21];
145 char machine_type[21];
146 char processor_speed[21];
147 unsigned short architecture; /* enum CHIP */
150 struct model _models[] =
152 { "02", "7015-930", "25", Power },
153 { "10", "7013-530", "25", Power },
154 { "10", "7016-730", "25", Power },
155 { "11", "7013-540", "30", Power },
156 { "14", "7013-540", "30", Power },
157 { "18", "7013-53H", "33", Power },
158 { "1C", "7013-550", "41.6", Power },
159 { "20", "7015-930", "25", Power },
160 { "2E", "7015-950", "41", Power },
161 { "30", "7013-520", "20", Power },
162 { "31", "7012-320", "20", Power },
163 { "34", "7013-52H", "25", Power },
164 { "35", "7012-32H", "25", Power },
165 { "37", "7012-340", "33", Power },
166 { "38", "7012-350", "41", Power },
167 { "41", "7011-20", "33", PowerPC },
168 { "45", "7011-220", "33", PowerPC },
169 { "42", "7006-41T/41W", "80", PowerPC },
170 { "43", "7008-M20", "33", Power },
171 { "43", "7008-M2A", "33", Power },
172 { "46", "7011-250", "66", PowerPC },
173 { "47", "7011-230", "45", RSC },
174 { "48", "7009-C10", "80", PowerPC },
175 /* 4C models use a different table -- see below */
176 { "4C", "70XX", "(unknown)", unknown },
177 { "57", "7012-390", "67", Power2 },
178 { "57", "7030-3BT", "67", Power2 },
179 { "57", "9076-SP2 Thin", "67", Power2 },
180 { "58", "7012-380", "59", Power2 },
181 { "58", "7030-3AT", "59", Power2 },
182 { "59", "7012-39H", "67", Power2 },
183 { "59", "9076-SP2 Thin w/L2", "67", Power2 },
184 { "5C", "7013-560", "50", Power },
185 { "63", "7015-970", "50", Power },
186 { "63", "7015-97B", "50", Power },
187 { "64", "7015-980", "62.5", Power },
188 { "64", "7015-98B", "62.5", Power },
189 { "66", "7013-580", "62.5", Power },
190 { "67", "7013-570", "50", Power },
191 { "67", "7015-R10", "50", Power },
192 { "70", "7013-590", "66", Power2 },
193 { "70", "9076-SP2 Wide", "66", Power2 },
194 { "71", "7013-58H", "55", Power2 },
195 { "72", "7013-59H", "66", Power2 },
196 { "72", "7015-R20", "66", Power2 },
197 { "72", "9076-SP2 Wide", "66", Power2 },
198 { "75", "7012-370", "62", Power },
199 { "75", "7012-375", "62", Power },
200 { "75", "9076-SP1 Thin", "62", Power },
201 { "76", "7012-360", "50", Power },
202 { "76", "7012-365", "50", Power },
203 { "77", "7012-350", "41", Power },
204 { "77", "7012-355", "41", Power },
205 { "77", "7013-55L", "41.6", Power },
206 { "79", "7013-591", "77", Power2 },
207 { "79", "9076-SP2 Wide", "77", Power2 },
208 { "80", "7015-990", "71.5", Power2 },
209 { "81", "7015-R24", "71.5", P2SC },
210 { "89", "7013-595", "135", P2SC },
211 { "89", "9076-SP2 Wide", "135", P2SC },
212 { "90", "7009-C20", "120", PowerPC },
213 { "91", "7006-42W/42T", "120", PowerPC },
214 { "94", "7012-397", "160", P2SC },
215 { "94", "9076-SP2 Thin", "160", P2SC },
216 { "A0", "7013-J30", "75", PowerPC },
217 { "A1", "7013-J40", "112", PowerPC },
218 { "A3", "7015-R30", "(unknown)", PowerPC },
219 { "A4", "7015-R40", "(unknown)", PowerPC },
220 { "A4", "7015-R50", "(unknown)", PowerPC },
221 { "A4", "9076-SP2 High", "(unknown)", PowerPC },
222 { "A6", "7012-G30", "(unknown)", PowerPC },
223 { "A7", "7012-G40", "(unknown)", PowerPC },
224 { "C0", "7024-E20", "(unknown)", PowerPC },
225 { "C0", "7024-E30", "(unknown)", PowerPC },
226 { "C4", "7025-F30", "(unknown)", PowerPC },
227 { "F0", "7007-N40", "50", ThinkPad },
228 { "", "", "0", 0 }
231 struct model _4C_models[] =
233 { "IBM,7017-S70", "7017-S70", "125", RS64 },
234 { "IBM,7017-S7A", "7017-S7A", "262", RD64_II },
235 { "IBM,7017-S80", "7017-S80", "450", RS_III },
236 { "IBM,7017-S85", "pSeries 680", "600", RS64_IV },
237 { "IBM,7025-F40", "7025-F40", "166/233", PowerPC_604e },
238 { "IBM,7025-F50", "7025-F50", "(unknown)", PowerPC_604e },
239 { "IBM,7025-F80", "7025-F80", "(unknown)", RS64_III },
240 { "IBM,7026-H10", "7025-H10", "166/233", PowerPC_604e },
241 { "IBM,7026-H50", "7025-H50", "(unknown)", PowerPC_604e },
242 { "IBM,7026-H80", "7025-H80", "(unknown)", RS64_III },
243 { "IBM,7026-M80", "7026-M80", "500", RS64_III },
244 { "IBM,7025-F40", "7025-F40", "166/233", PowerPC },
245 { "IBM,7025-F50", "7025-F50", "(unknown)", PowerPC },
246 { "IBM,7025-F80", "7025-F80", "450", PowerPC },
247 { "IBM,7026-B80", "pSeries 640", "375", Power3_II },
248 { "IBM,7026-H10", "7026-H10", "166/233", PowerPC },
249 { "IBM,7026-H50", "7026-H50", "(unknown)", PowerPC },
250 { "IBM,7026-H70", "7026-H70", "340", RS64_II },
251 { "IBM,7026-H80", "7026-H80", "450", PowerPC },
252 { "IBM,7026-M80", "7026-M80", "500", PowerPC },
253 { "IBM,7042-140", "7043-140", "166/200/233/332", PowerPC },
254 { "IBM,7042-150", "7043-150", "375", PowerPC },
255 { "IBM,7042-240", "7043-240", "166/233", PowerPC },
256 { "IBM,7043-140", "7043-140", "166/200/233/332", PowerPC },
257 { "IBM,7043-150", "7043-150", "375", PowerPC },
258 { "IBM,7043-240", "7043-240", "166/233", PowerPC },
259 { "IBM,7043-260", "7043-260", "200", Power3 },
260 { "IBM,7248", "7248-100", "100", PowerPersonal },
261 { "IBM,7248", "7248-120", "120", PowerPersonal },
262 { "IBM,7248", "7248-132", "132", PowerPersonal },
263 { "IBM,9076-270", "9076-SP Silver Node", "(unknown)", PowerPC },
264 { "", "", "", 0 },
268 /* all GetInfo_ functions should return true, when the Information
269 was filled into the lBox-Widget.
270 returning false indicates, that information was not available.
273 bool
274 GetInfo_XServer_and_Video( QListView *lBox )
276 return GetInfo_XServer_Generic( lBox );
280 * Written using information from:
282 * http://service.software.ibm.com/cgi-bin/support/rs6000.support/techbrowse/tbgaus?gaus_mode=8&documents=B93576892313352&database=task
284 * Not fully implemented. In particular there are ways to resolve the
285 * "(unknown)" clock speeds of many of these models. See page for details.
288 bool
289 GetInfo_CPU( QListView *lBox )
291 struct utsname info;
292 struct model *table = _models; /* table of model information */
293 char model_ID[21] = ""; /* information for table lookup */
294 char cpu_ID[7] = ""; /* unique CPU ID */
295 int i;
296 QListViewItem *lastitem = NULL;
298 lBox->addColumn(i18n("Information"));
299 lBox->addColumn(i18n("Value"));
301 if (uname(&info) == -1)
303 kError(0) << "uname() failed: errno = " << errno << endl;
304 return false;
307 strncat(model_ID, info.machine+8, 2); /* we want the ninth and tenth digits */
308 strncat(cpu_ID, info.machine+2, 6);
310 if (strcmp(model_ID, "4C") == 0) /* need to use a different model_ID and model table */
312 if (odm_initialize() == -1)
313 kError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl;
314 else
316 struct CuAt cuat; /* Customized Device attribute */
318 /* equivalent to uname -M */
319 if ( odm_get_first(CuAt_CLASS, (char *)"name='sys0' and attribute='modelname'", &cuat) )
321 strcpy(model_ID, cuat.value);
322 table = _4C_models;
325 odm_terminate();
329 lastitem = new QListViewItem(lBox, lastitem, QString("CPU ID"), QString(cpu_ID));
330 lastitem = new QListViewItem(lBox, lastitem, QString("Node"), QString(info.nodename));
331 lastitem = new QListViewItem(lBox, lastitem, QString("OS"), QString(info.sysname) +
332 QString(" ") + QString(info.version) + QString(".") + QString(info.release));
334 for (i=0; *(table[i].model_ID); i++)
335 if (strcmp(model_ID, table[i].model_ID) == 0)
337 lastitem = new QListViewItem(lBox, lastitem, QString("Machine Type"), QString(table[i].machine_type));
338 lastitem = new QListViewItem(lBox, lastitem, QString("Architecture"), QString(chip_name[table[i].architecture]));
339 lastitem = new QListViewItem(lBox, lastitem, QString("Speed"), QString(table[i].processor_speed) + QString(" Mhz"));
340 break;
343 return(true);
346 bool GetInfo_IRQ( QListView * )
348 return false;
351 bool GetInfo_DMA( QListView * )
353 return false;
356 bool
357 GetInfo_PCI( QListView *lBox )
359 return list_devices(lBox, (char *)"PdDvLn like '*/pci/*'");
362 bool GetInfo_IO_Ports( QListView * )
364 return false;
367 bool GetInfo_Sound( QListView * )
369 return false;
372 bool
373 GetInfo_Devices( QListView *lBox )
375 return list_devices(lBox, (char *)"PdDvLn like '*'");
378 bool
379 GetInfo_SCSI( QListView *lBox )
381 return list_devices(lBox, (char *)"PdDvLn like '*/scsi/*'");
384 /* Parts taken from fsusage.c from the Midnight Commander (mc)
386 Copyright (C) 1991, 1992 Free Software Foundation, In
388 Return the number of TOSIZE-byte blocks used by
389 BLOCKS FROMSIZE-byte blocks, rounding away from zero.
390 TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
392 static long fs_adjust_blocks(long blocks, int fromsize, int tosize)
394 if (tosize <= 0)
395 abort ();
396 if (fromsize <= 0)
397 return -1;
399 if (fromsize == tosize) /* E.g., from 512 to 512. */
400 return blocks;
401 else if (fromsize > tosize) /* E.g., from 2048 to 512. */
402 return blocks * (fromsize / tosize);
403 else /* E.g., from 256 to 512. */
404 return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
407 /* Fill in the fields of FSP with information about space usage for
408 the filesystem on which PATH resides.
409 Return 0 if successful, -1 if not. */
411 #define CONVERT_BLOCKS(b) fs_adjust_blocks ((b), fsd.f_bsize, 512)
413 static int get_fs_usage (char *path, long *l_total, long *l_avail)
414 { struct statfs fsd; /* 4.3BSD, SunOS 4, HP-UX, AIX. */
415 unsigned long fsu_blocks,fsu_bfree,fsu_bavail;
417 *l_total = *l_avail = 0;
418 if (statfs (path, &fsd) < 0)
419 return -1;
421 fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
422 fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
423 fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
425 *l_avail = getuid () ? fsu_bavail/2 : fsu_bfree/2;
426 *l_total = fsu_blocks/2;
428 return 0;
432 // Some Ideas taken from garbazo from his source in info_fbsd.cpp
434 bool
435 GetInfo_Partitions ( QListView *lbox )
437 #define NUMCOLS 5
438 QString Title[NUMCOLS];
439 int n;
441 struct fstab *fstab_ent;
442 struct statvfs svfs;
443 long total,avail;
444 QString str;
445 QString MB(i18n("MB")+ " "); // International Text for MB=Mega-Byte
447 if (setfsent() != 1) // Try to open fstab
448 return false;
450 Title[0] = i18n("Device");
451 Title[1] = i18n("Mount Point");
452 Title[2] = i18n("FS Type");
453 Title[3] = i18n("Total Size");
454 Title[4] = i18n("Free Size");
456 for (n=0; n<NUMCOLS; ++n) {
457 lbox->addColumn(Title[n] );
460 while ((fstab_ent=getfsent())!=NULL) {
461 /* fstab_ent->fs_type holds only "rw","xx","ro"... */
462 memset(&svfs,0,sizeof(svfs));
463 statvfs(fstab_ent->fs_file,&svfs);
464 get_fs_usage(fstab_ent->fs_file, &total, &avail);
466 if (!strcmp(fstab_ent->fs_type,FSTAB_XX)) // valid drive ?
467 svfs.f_basetype[0] = 0;
469 if(svfs.f_basetype[0]) {
470 new QListViewItem(lbox, QString(fstab_ent->fs_spec),
471 QString(fstab_ent->fs_file) + QString(" "),
472 (svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")),
473 Value((total+512)/1024,6) + MB,
474 Value((avail+512)/1024,6) + MB);
476 else {
477 new QListViewItem(lbox, QString(fstab_ent->fs_spec),
478 QString(fstab_ent->fs_file) + QString(" "),
479 (svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")));
483 endfsent();
485 return true;