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.
14 #include <sys/cfgodm.h>
15 #include <sys/cfgdb.h>
22 #include <sys/statfs.h>
23 #include <sys/statvfs.h>
24 #include <sys/types.h>
29 #include <sys/utsname.h>
31 char * device_description(struct CuDv
*cudv
) {
33 struct PdDv
*pddv
= cudv
->PdDvLn
; /* link to Predefined Devices database */
36 cat
= catopen("/usr/lib/methods/devices.cat", NL_CAT_LOCALE
);
40 desc
= strdup(catgets(cat
, pddv
->setno
, pddv
->msgno
, "N/A") );
46 bool list_devices(QListView
*lBox
, char *criteria
) {
47 struct CuDv
*cudv
; /* Customized Devices */
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
;
64 cudv
= (struct CuDv
*) odm_get_list(CuDv_CLASS
, criteria
, &info
, 100, 2);
66 if ((int)cudv
== -1) {
68 kError(0) << "odm_get_list() failed: odmerrno = " << odmerrno
<< endl
;
70 } else if (!cudv
) /* empty list */
76 for (i
=0; i
<info
.num
; i
++) {
77 switch (cudv
[i
].status
) {
79 cudv_status
= QString("Defined");
82 cudv_status
= QString("Available");
85 cudv_status
= QString("Stopped");
88 cudv_status
= QString("Unknown");
90 cudv_desc
= device_description(&cudv
[i
]);
92 lastitem
= new QListViewItem(lBox
, lastitem
,
93 QString(cudv
[i
].name
),
95 QString(cudv
[i
].location
),
96 QString(cudv_desc
? cudv_desc
: "N/A") );
102 if (odm_free_list(cudv
, &info
) == -1) {
104 kError(0) << "odm_free_list() failed: odmerrno = " << odmerrno
<< endl
;
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
,
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" };
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
}, { "", "",
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
) {
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 */
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
;
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
;
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
);
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"));
219 bool GetInfo_IRQ(QListView
*) {
223 bool GetInfo_DMA(QListView
*) {
227 bool GetInfo_PCI(QTreeWidget
* tree
) {
228 return list_devices(tree
, (char *)"PdDvLn like '*/pci/*'");
231 bool GetInfo_IO_Ports(QListView
*) {
235 bool GetInfo_Sound(QListView
*) {
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
) {
261 if (fromsize
== tosize
) /* E.g., from 512 to 512. */
263 else if (fromsize
> tosize
) /* E.g., from 2048 to 512. */
264 return blocks
* (fromsize
/ tosize
);
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)
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;
294 // Some Ideas taken from garbazo from his source in info_fbsd.cpp
296 bool GetInfo_Partitions(QListView
*lbox
) {
298 QString Title
[NUMCOLS
];
301 struct fstab
*fstab_ent
;
305 QString
MB(i18n("MB")+ " "); // International Text for MB=Mega-Byte
307 if (setfsent() != 1) // Try to open fstab
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
);
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")));