/* * 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(TQListView *lBox, char *criteria) { struct CuDv *cudv; /* Customized Devices */ struct listinfo info; int i; char *cudv_desc; TQString cudv_status; TQListViewItem *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 TQListViewItem(lBox, lastitem, TQString("CPU ID"), TQString(cpu_ID)); lastitem = new TQListViewItem(lBox, lastitem, TQString("Node"), TQString(info.nodename)); lastitem = new TQListViewItem(lBox, lastitem, TQString("OS"), TQString(info.sysname) + TQString(" ") + TQString(info.version) + TQString(".") + TQString(info.release)); for (i=0; *(table[i].model_ID); i++) if (strcmp(model_ID, table[i].model_ID) == 0) { lastitem = new TQListViewItem(lBox, lastitem, TQString("Machine Type"), TQString(table[i].machine_type)); lastitem = new TQListViewItem(lBox, lastitem, TQString("Architecture"), TQString(chip_name[table[i].architecture])); lastitem = new TQListViewItem(lBox, lastitem, TQString("Speed"), TQString(table[i].processor_speed) + TQString(" Mhz")); break; } return(true); } bool GetInfo_IRQ( TQListView * ) { return false; } bool GetInfo_DMA( TQListView * ) { return false; } bool GetInfo_PCI( TQListView *lBox ) { return list_devices(lBox, (char *)"PdDvLn like '*/pci/*'"); } bool GetInfo_IO_Ports( TQListView * ) { return false; } bool GetInfo_Sound( TQListView * ) { return false; } bool GetInfo_Devices( TQListView *lBox ) { return list_devices(lBox, (char *)"PdDvLn like '*'"); } bool GetInfo_SCSI( TQListView *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 ( TQListView *lbox ) { #define NUMCOLS 5 TQString Title[NUMCOLS]; int n; struct fstab *fstab_ent; struct statvfs svfs; long total,avail; TQString str; TQString 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 TQListViewItem(lbox, TQString(fstab_ent->fs_spec), TQString(fstab_ent->fs_file) + TQString(" "), (svfs.f_basetype[0] ? TQString(svfs.f_basetype) : i18n("n/a")), Value((total+512)/1024,6) + MB, Value((avail+512)/1024,6) + MB); } else { new TQListViewItem(lbox, TQString(fstab_ent->fs_spec), TQString(fstab_ent->fs_file) + TQString(" "), (svfs.f_basetype[0] ? TQString(svfs.f_basetype) : i18n("n/a"))); } } endfsent(); return true; }