From 4aed2c8219774f5d797760606b8489a92ddc5163 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kcontrol/info/info_aix.cpp | 486 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 486 insertions(+) create mode 100644 kcontrol/info/info_aix.cpp (limited to 'kcontrol/info/info_aix.cpp') diff --git a/kcontrol/info/info_aix.cpp b/kcontrol/info/info_aix.cpp new file mode 100644 index 000000000..8aaee4f6d --- /dev/null +++ b/kcontrol/info/info_aix.cpp @@ -0,0 +1,486 @@ +/* + * info_aix.cpp + * + * Reza Arbab + * + * GetInfo_Partitions() and its helpers (get_fs_usage, fs_adjust_blocks) + * taken from info_hpux.cpp. + * + */ + +#include +#define class _class +#include +#include +#include +#undef class +#include +#include +#include +#include + +#define INFO_DEVICES_AVAILABLE +#define INFO_SCSI_AVAILABLE +#define INFO_PCI_AVAILABLE + +#include +#include +#include +#include +#include + +#define INFO_PARTITIONS_AVAILABLE + +#include +#include + +#define INFO_CPU_AVAILABLE + +#define INFO_IRQ_AVAILABLE +#define INFO_DMA_AVAILABLE +#define INFO_IOPORTS_AVAILABLE +#define INFO_SOUND_AVAILABLE +#define INFO_XSERVER_AVAILABLE + +char * +device_description(struct CuDv *cudv) +{ + char *desc = NULL; + struct PdDv *pddv = cudv->PdDvLn; /* link to Predefined Devices database */ + nl_catd cat; + + cat = catopen("/usr/lib/methods/devices.cat", NL_CAT_LOCALE); + if ((int)cat == -1) + return NULL; + + desc = strdup( catgets(cat, pddv->setno, pddv->msgno, "N/A") ); + catclose(cat); + + return desc; +} + +bool +list_devices(QListView *lBox, char *criteria) +{ + struct CuDv *cudv; /* Customized Devices */ + struct listinfo info; + int i; + char *cudv_desc; + QString cudv_status; + QListViewItem *lastitem = NULL; + + lBox->addColumn(i18n("Name")); + lBox->addColumn(i18n("Status")); + lBox->addColumn(i18n("Location")); + lBox->addColumn(i18n("Description")); + + if (odm_initialize() == -1) + { + kdError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl; + return(false); + } + + cudv = (struct CuDv *) odm_get_list(CuDv_CLASS, criteria, &info, 100, 2); + + if ((int)cudv == -1) + { + odm_terminate(); + kdError(0) << "odm_get_list() failed: odmerrno = " << odmerrno << endl; + return(false); + } + else if (!cudv) /* empty list */ + { + odm_terminate(); + return(true); + } + + for (i=0; iaddColumn(i18n("Information")); + lBox->addColumn(i18n("Value")); + + if (uname(&info) == -1) + { + kdError(0) << "uname() failed: errno = " << errno << endl; + return false; + } + + strncat(model_ID, info.machine+8, 2); /* we want the ninth and tenth digits */ + strncat(cpu_ID, info.machine+2, 6); + + if (strcmp(model_ID, "4C") == 0) /* need to use a different model_ID and model table */ + { + if (odm_initialize() == -1) + kdError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl; + else + { + struct CuAt cuat; /* Customized Device attribute */ + + /* equivalent to uname -M */ + if ( odm_get_first(CuAt_CLASS, (char *)"name='sys0' and attribute='modelname'", &cuat) ) + { + strcpy(model_ID, cuat.value); + table = _4C_models; + } + + odm_terminate(); + } + } + + lastitem = new QListViewItem(lBox, lastitem, QString("CPU ID"), QString(cpu_ID)); + lastitem = new QListViewItem(lBox, lastitem, QString("Node"), QString(info.nodename)); + lastitem = new QListViewItem(lBox, lastitem, QString("OS"), QString(info.sysname) + + QString(" ") + QString(info.version) + QString(".") + QString(info.release)); + + for (i=0; *(table[i].model_ID); i++) + if (strcmp(model_ID, table[i].model_ID) == 0) + { + lastitem = new QListViewItem(lBox, lastitem, QString("Machine Type"), QString(table[i].machine_type)); + lastitem = new QListViewItem(lBox, lastitem, QString("Architecture"), QString(chip_name[table[i].architecture])); + lastitem = new QListViewItem(lBox, lastitem, QString("Speed"), QString(table[i].processor_speed) + QString(" Mhz")); + break; + } + + return(true); +} + +bool GetInfo_IRQ( QListView * ) +{ + return false; +} + +bool GetInfo_DMA( QListView * ) +{ + return false; +} + +bool +GetInfo_PCI( QListView *lBox ) +{ + return list_devices(lBox, (char *)"PdDvLn like '*/pci/*'"); +} + +bool GetInfo_IO_Ports( QListView * ) +{ + return false; +} + +bool GetInfo_Sound( QListView * ) +{ + return false; +} + +bool +GetInfo_Devices( QListView *lBox ) +{ + return list_devices(lBox, (char *)"PdDvLn like '*'"); +} + +bool +GetInfo_SCSI( QListView *lBox ) +{ + return list_devices(lBox, (char *)"PdDvLn like '*/scsi/*'"); +} + +/* Parts taken from fsusage.c from the Midnight Commander (mc) + + Copyright (C) 1991, 1992 Free Software Foundation, In + + Return the number of TOSIZE-byte blocks used by + BLOCKS FROMSIZE-byte blocks, rounding away from zero. + TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */ + +static long fs_adjust_blocks(long blocks, int fromsize, int tosize) +{ + if (tosize <= 0) + abort (); + if (fromsize <= 0) + return -1; + + if (fromsize == tosize) /* E.g., from 512 to 512. */ + return blocks; + else if (fromsize > tosize) /* E.g., from 2048 to 512. */ + return blocks * (fromsize / tosize); + else /* E.g., from 256 to 512. */ + return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize); +} + +/* Fill in the fields of FSP with information about space usage for + the filesystem on which PATH resides. + Return 0 if successful, -1 if not. */ + +#define CONVERT_BLOCKS(b) fs_adjust_blocks ((b), fsd.f_bsize, 512) + +static int get_fs_usage (char *path, long *l_total, long *l_avail) +{ struct statfs fsd; /* 4.3BSD, SunOS 4, HP-UX, AIX. */ + unsigned long fsu_blocks,fsu_bfree,fsu_bavail; + + *l_total = *l_avail = 0; + if (statfs (path, &fsd) < 0) + return -1; + + fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks); + fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree); + fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail); + + *l_avail = getuid () ? fsu_bavail/2 : fsu_bfree/2; + *l_total = fsu_blocks/2; + + return 0; +} + + +// Some Ideas taken from garbazo from his source in info_fbsd.cpp + +bool +GetInfo_Partitions ( QListView *lbox ) +{ + #define NUMCOLS 5 + QString Title[NUMCOLS]; + int n; + + struct fstab *fstab_ent; + struct statvfs svfs; + long total,avail; + QString str; + QString MB(i18n("MB")+ " "); // International Text for MB=Mega-Byte + + if (setfsent() != 1) // Try to open fstab + return false; + + Title[0] = i18n("Device"); + Title[1] = i18n("Mount Point"); + Title[2] = i18n("FS Type"); + Title[3] = i18n("Total Size"); + Title[4] = i18n("Free Size"); + + for (n=0; naddColumn(Title[n] ); + } + + while ((fstab_ent=getfsent())!=NULL) { + /* fstab_ent->fs_type holds only "rw","xx","ro"... */ + memset(&svfs,0,sizeof(svfs)); + statvfs(fstab_ent->fs_file,&svfs); + get_fs_usage(fstab_ent->fs_file, &total, &avail); + + if (!strcmp(fstab_ent->fs_type,FSTAB_XX)) // valid drive ? + svfs.f_basetype[0] = 0; + + if(svfs.f_basetype[0]) { + new QListViewItem(lbox, QString(fstab_ent->fs_spec), + QString(fstab_ent->fs_file) + QString(" "), + (svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")), + Value((total+512)/1024,6) + MB, + Value((avail+512)/1024,6) + MB); + } + else { + new QListViewItem(lbox, QString(fstab_ent->fs_spec), + QString(fstab_ent->fs_file) + QString(" "), + (svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a"))); + } + + } + endfsent(); + + return true; +} -- cgit v1.2.1