Beispiel #1
0
static int 
bpf_odmcleanup(char *errbuf)
{
	char *errstr;

	if (odm_unlock(odmlockid) == -1) {
		if (odm_err_msg(odmerrno, &errstr) == -1)
			errstr = "Unknown error";
		snprintf(errbuf, PCAP_ERRBUF_SIZE,
		    "bpf_load: odm_unlock failed: %s",
		    errstr);
		return (-1);
	}

	if (odm_terminate() == -1) {
		if (odm_err_msg(odmerrno, &errstr) == -1)
			errstr = "Unknown error";
		snprintf(errbuf, PCAP_ERRBUF_SIZE,
		    "bpf_load: odm_terminate failed: %s",
		    errstr);
		return (-1);
	}

	return (0);
}
char *OS_initialize() {

	struct CuAt* odm_object;
	int num_fetched;

	/* get the number of processors online */
	ncpus = sysconf(_SC_NPROCESSORS_ONLN);
	if( ncpus == -1 ) {		/* sysconf error */
		ncpus = 1;
	}

	/* get the page size in bytes */
	pagesize = getpagesize();

	/* get the amount of physical memory */
	if( 0 != odm_initialize() ) {
		/* fprintf(stderr, "cannot initialize ODM in Proc::ProcessTable::OS_initialize (AIX)!\n"); */
		ppt_warn("cannot initialize ODM in Proc::ProcessTable::OS_initialize (AIX)!");
	} else {
		odm_object = (struct CuAt*)getattr("sys0", "realmem", 0, &num_fetched);
		memory = strtoull(odm_object->value, 0, 10);
		odm_terminate();
	}

    memory = memory * 1024;

	return NULL;

}
Beispiel #3
0
static void
err_exit(char exitcode)
{
    odm_close_class(CuDv_CLASS);
    odm_close_class(PdDv_CLASS);
    odm_terminate();
    exit(exitcode);
}
Beispiel #4
0
/* 
 * Written using information from:
 *
 * http://service.software.ibm.com/cgi-bin/support/rs6000.support/techbrowse/tbgaus?gaus_mode=8&documents=B93576892313352&database=task
 *
 * Not fully implemented.  In particular there are ways to resolve the 
 * "(unknown)" clock speeds of many of these models.  See page for details.
 * 
 */
bool 
GetInfo_CPU( QListView *lBox )
{
  struct utsname info;
  struct model *table = _models;  /* table of model information */
  char model_ID[21] = "";  /* information for table lookup */
  char cpu_ID[7] = "";    /* unique CPU ID */
  int i;
  QListViewItem *lastitem = NULL;

  lBox->addColumn(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);
}
Beispiel #5
0
char* OS_initialize() {
  
  struct CuAt*      obj;
  int               how_many;
  

  Sysmem = 0;

  /*
   * Get the real memory size via ODM
   *
   */


  if (odm_initialize() == 0) {
    obj = (struct CuAt*)getattr ("sys0", "realmem", 0, &how_many);
    Sysmem = strtoull(obj->value, 0, 10);
    odm_terminate();
  }

  else {
    printf("BIG PROLEM !\n");
  }
  
  Sysmem = Sysmem * 1024;
  
  /*
   * Get The number of processors
   *
   */
   ProcessNumber = sysconf(_SC_NPROCESSORS_ONLN);
   if ( ProcessNumber == -1 ) {
     ProcessNumber = 1;
   }


  /*
   * Get the page size in bytes
   *
   */
  
  PageSize = getpagesize();
  
  return NULL;
}
Beispiel #6
0
int
main(int argc, char **argv)
{
    char *logical_name, *ptr;
    char sstring[256];
    struct CuDv cudvobj;
    struct PdDv pddvobj;
    int rc, how_many, errflg, c, majorno, minorno, unit, verbose;
    struct cfg_dd cfg;
    struct cfg_load load;
    int *minor_list;
    extern int optind;
    extern char *optarg;

    verbose = errflg = 0;
    logical_name = NULL;
    while ((c = getopt(argc,argv,"vl:")) != EOF) {
	switch (c) {
	case 'v':
	    verbose++;
	    break;
	case 'l':
	    if (logical_name != NULL)
		errflg++;
	    logical_name = optarg;
	    break;
	default:
	    errflg++;
	}
    }
    if (errflg)
	exit(E_ARGS);

    if (logical_name == NULL)
	exit(E_LNAME);

    if (odm_initialize() == -1)
	exit(E_ODMINIT);

    /* Get Customized Device Object for this device */
    sprintf(sstring,"name = '%s'",logical_name);
    rc = (int) odm_get_first(CuDv_CLASS, sstring, &cudvobj);
    if (rc ==  0) {
	err_exit(E_NOCuDv);
    } else if (rc == -1) {
	err_exit(E_ODMGET);
    }

    if (cudvobj.status == DEFINED)
	err_exit(E_OK);  /* already unconf'd */

    /* get device's predefined object */
    sprintf(sstring,"uniquetype = '%s'", cudvobj.PdDvLn_Lvalue);
    rc = (int) odm_get_first(PdDv_CLASS, sstring, &pddvobj);
    if (rc ==  0)
	err_exit(E_NOPdDv);
    else if (rc == -1)
	err_exit(E_ODMGET);

    /*
     * Call sysconfig() to "terminate" the device.
     * If fails with EBUSY, then device instance is "open",
     * and device cannot be "unconfigured".  Any other errno
     * returned will be ignored since we MUST unconfigure the
     * device even if it reports some other error.
     */

    /* get major number of device */
    majorno = genmajor(pddvobj.DvDr);
    if (majorno == -1) {
	return(E_MAJORNO);
    }
    /* get minor number */
    minor_list = getminor(majorno, &how_many, pddvobj.DvDr);
    if (minor_list == NULL || how_many == 0)
	err_exit (E_MINORNO);
    vprintf("how_many=%d\n", how_many);
    ptr = logical_name;
    ptr += strlen(pddvobj.prefix);
    unit = atoi(ptr);
    if (unit >= how_many) {
	err_exit (E_MINORNO);
    }
    minorno = minor_list[unit];
    vprintf("unit %d minorno %d\n", unit, minorno);

    /* create devno for this device */
    cfg.devno = makedev(majorno, minorno);
    cfg.kmid = 0;
    cfg.ddsptr = (caddr_t) NULL;
    cfg.ddslen = (int) 0;
    cfg.cmd = CFG_TERM;
    if (sysconfig(SYS_CFGDD, &cfg, sizeof(struct cfg_dd)) == -1) {
	if (errno == EBUSY)
	    err_exit(E_BUSY);
    }
    cfg.kmid = loadext(pddvobj.DvDr, FALSE, FALSE);
    if (cfg.kmid == NULL)
	err_exit(E_UNLOADEXT);

    /* Change the status field of device to "DEFINED" */
    cudvobj.status = DEFINED;
    if (odm_change_obj(CuDv_CLASS, &cudvobj) == -1) 
	err_exit(E_ODMUPDATE);

    /*
     * Terminate ODM
     */
    odm_terminate();
    return (E_OK);
}
Beispiel #7
0
/*
** PR_GetPhysicalMemorySize()
** 
** Implementation notes:
**   Every platform does it a bit different.
**     bytes is the returned value.
**   for each platform's "if defined" section
**     declare your local variable
**     do your thing, assign to bytes.
** 
*/
PR_IMPLEMENT(PRUint64) PR_GetPhysicalMemorySize(void)
{
    PRUint64 bytes = 0;

#if defined(LINUX) || defined(SOLARIS)

    long pageSize = sysconf(_SC_PAGESIZE);
    long pageCount = sysconf(_SC_PHYS_PAGES);
    bytes = (PRUint64) pageSize * pageCount;

#elif defined(HPUX)

    struct pst_static info;
    int result = pstat_getstatic(&info, sizeof(info), 1, 0);
    if (result == 1)
        bytes = (PRUint64) info.physical_memory * info.page_size;

#elif defined(DARWIN)

    struct host_basic_info hInfo;
    mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;

    int result = host_info(mach_host_self(),
                           HOST_BASIC_INFO,
                           (host_info_t) &hInfo,
                           &count);
    if (result == KERN_SUCCESS)
        bytes = hInfo.max_mem;

#elif defined(WIN32)

    /* Try to use the newer GlobalMemoryStatusEx API for Windows 2000+. */
    GlobalMemoryStatusExFn globalMemory = (GlobalMemoryStatusExFn) NULL;
    HMODULE module = GetModuleHandleW(L"kernel32.dll");

    if (module) {
        globalMemory = (GlobalMemoryStatusExFn)GetProcAddress(module, "GlobalMemoryStatusEx");

        if (globalMemory) {
            PR_MEMORYSTATUSEX memStat;
            memStat.dwLength = sizeof(memStat);

            if (globalMemory(&memStat))
                bytes = memStat.ullTotalPhys;
        }
    }

    if (!bytes) {
        /* Fall back to the older API. */
        MEMORYSTATUS memStat;
        memset(&memStat, 0, sizeof(memStat));
        GlobalMemoryStatus(&memStat);
        bytes = memStat.dwTotalPhys;
    }

#elif defined(OS2)

    ULONG ulPhysMem;
    DosQuerySysInfo(QSV_TOTPHYSMEM,
                    QSV_TOTPHYSMEM,
                    &ulPhysMem,
                    sizeof(ulPhysMem));
    bytes = ulPhysMem;

#elif defined(AIX)

    if (odm_initialize() == 0) {
        int how_many;
        struct CuAt *obj = getattr("sys0", "realmem", 0, &how_many);
        if (obj != NULL) {
            bytes = (PRUint64) atoi(obj->value) * 1024;
            free(obj);
        }
        odm_terminate();
    }

#else

    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);

#endif

    return bytes;
} /* end PR_GetPhysicalMemorySize() */
Beispiel #8
0
/*
** PR_GetPhysicalMemorySize()
** 
** Implementation notes:
**   Every platform does it a bit different.
**     bytes is the returned value.
**   for each platform's "if defined" section
**     declare your local variable
**     do your thing, assign to bytes.
** 
*/
PR_IMPLEMENT(PRUint64) PR_GetPhysicalMemorySize(void)
{
    PRUint64 bytes = 0;

#if defined(LINUX) || defined(SOLARIS)

    long pageSize = sysconf(_SC_PAGESIZE);
    long pageCount = sysconf(_SC_PHYS_PAGES);
    if (pageSize >= 0 && pageCount >= 0)
        bytes = (PRUint64) pageSize * pageCount;

#elif defined(NETBSD) || defined(OPENBSD)

    int mib[2];
    int rc;
    uint64_t memSize;
    size_t len = sizeof(memSize);

    mib[0] = CTL_HW;
    mib[1] = HW_PHYSMEM64;
    rc = sysctl(mib, 2, &memSize, &len, NULL, 0);
    if (-1 != rc)  {
        bytes = memSize;
    }

#elif defined(HPUX)

    struct pst_static info;
    int result = pstat_getstatic(&info, sizeof(info), 1, 0);
    if (result == 1)
        bytes = (PRUint64) info.physical_memory * info.page_size;

#elif defined(DARWIN)

    mach_port_t mach_host = mach_host_self();
    struct host_basic_info hInfo;
    mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;

    int result = host_info(mach_host,
                           HOST_BASIC_INFO,
                           (host_info_t) &hInfo,
                           &count);
    mach_port_deallocate(mach_task_self(), mach_host);
    if (result == KERN_SUCCESS)
        bytes = hInfo.max_mem;

#elif defined(WIN32)

    MEMORYSTATUSEX memStat;
    memStat.dwLength = sizeof(memStat);
    if (GlobalMemoryStatusEx(&memStat))
        bytes = memStat.ullTotalPhys;

#elif defined(OS2)

    ULONG ulPhysMem;
    DosQuerySysInfo(QSV_TOTPHYSMEM,
                    QSV_TOTPHYSMEM,
                    &ulPhysMem,
                    sizeof(ulPhysMem));
    bytes = ulPhysMem;

#elif defined(AIX)

    if (odm_initialize() == 0) {
        int how_many;
        struct CuAt *obj = getattr("sys0", "realmem", 0, &how_many);
        if (obj != NULL) {
            bytes = (PRUint64) atoi(obj->value) * 1024;
            free(obj);
        }
        odm_terminate();
    }

#else

    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);

#endif

    return bytes;
} /* end PR_GetPhysicalMemorySize() */
Beispiel #9
0
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) {
		kError(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();
		kError(0) << "odm_get_list() failed: odmerrno = " << odmerrno << endl;
		return (false);
	} else if (!cudv) /* empty list */
	{
		odm_terminate();
		return (true);
	}

	for (i=0; i<info.num; i++) {
		switch (cudv[i].status) {
		case DEFINED:
			cudv_status = QString("Defined");
			break;
		case AVAILABLE:
			cudv_status = QString("Available");
			break;
		case STOPPED:
			cudv_status = QString("Stopped");
			break;
		default:
			cudv_status = QString("Unknown");
		}
		cudv_desc = device_description(&cudv[i]);

		lastitem = new QListViewItem(lBox, lastitem,
				QString(cudv[i].name),
				cudv_status,
				QString(cudv[i].location),
				QString(cudv_desc ? cudv_desc : "N/A") );

		if (cudv_desc)
			free(cudv_desc);
	}

	if (odm_free_list(cudv, &info) == -1) {
		odm_terminate();
		kError(0) << "odm_free_list() failed: odmerrno = " << odmerrno << endl;
		return (false);
	}

	odm_terminate();
	return true;
}