home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / sysinfo-1.0 / part01 / os-alliant.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-10  |  4.4 KB  |  213 lines

  1. /*
  2.  * Copyright (c) 1992 Michael A. Cooper.
  3.  * This software may be freely distributed provided it is not sold for 
  4.  * profit and the author is credited appropriately.
  5.  */
  6.  
  7. #ifndef lint
  8. static char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/os-alliant.c,v 1.9 1992/04/26 23:32:06 mcooper Exp $";
  9. #endif
  10.  
  11. /*
  12.  * $Log: os-alliant.c,v $
  13.  * Revision 1.9  1992/04/26  23:32:06  mcooper
  14.  * Add Copyright notice
  15.  *
  16.  * Revision 1.8  1992/04/17  23:27:51  mcooper
  17.  * Add support for ROM Version information (Sun only for now).
  18.  *
  19.  * Revision 1.7  1992/04/17  01:07:59  mcooper
  20.  * More de-linting
  21.  *
  22.  * Revision 1.6  1992/04/15  02:04:16  mcooper
  23.  * Change GetMemoryStr() to GetMemory().
  24.  *
  25.  * Revision 1.5  1992/03/31  19:00:15  mcooper
  26.  * A working version.
  27.  *
  28.  * Revision 1.4  1992/03/31  02:22:03  mcooper
  29.  * Fix failed return value from CheckNlist().
  30.  *
  31.  * Revision 1.3  1992/03/31  01:55:17  mcooper
  32.  * Use new CheckNlist to check nlist success.
  33.  *
  34.  * Revision 1.2  1992/03/31  00:15:09  mcooper
  35.  * Add error check for nlist.n_type.
  36.  *
  37.  * Revision 1.1  1992/03/01  23:28:16  mcooper
  38.  * Initial revision
  39.  *
  40.  */
  41.  
  42. /*
  43.  * Alliant specific functions
  44.  */
  45. #include <stdio.h>
  46. #include "system.h"
  47. #include "defs.h"
  48.  
  49. #include <fcntl.h>
  50. #include <nlist.h>
  51.  
  52. /*
  53.  * All the wonderful global extern declarations
  54.  */
  55. #if    defined(HAVE_USERETC)
  56. struct bpb                *useretc = (struct bpb *)USERETC;
  57. #endif    /* HAVE_USERETC */
  58. #if    defined(HAVE_MODELNUM)
  59. extern int            modelnum;
  60. #endif    /* HAVE_MODELNUM */
  61. #if    defined(HAVE_MEMORYSIZE)
  62. extern int            memorysize;
  63. #endif    /* HAVE_MEMORYSIZE */
  64. #if    defined(HAVE_SERIALNUM)
  65. extern int            serialnum;
  66. #endif    /* HAVE_SERIALNUM */
  67.  
  68. /*
  69.  * Lookup a model value (val) and returns it's name.
  70.  */
  71. extern char *GetModelName()
  72. {
  73.     register int         i;
  74.     register int        Num = -1;
  75.     extern NAMETAB         ModelTab[];
  76.  
  77. #if    defined(HAVE_MODELNUM)
  78.     /*
  79.      * Alliant 2800's have an external variable
  80.      * called "modelnum".
  81.      */
  82.     Num = modelnum;
  83. #endif    /* HAVE_MODELNUM */
  84. #if    defined(HAVE_USERETC)
  85.     /*
  86.      * Alliant FX/80's have an external variable
  87.      * called "useretc".
  88.      */
  89.     Num = useretc->bp_model;
  90. #endif    /* HAVE_USERETC */
  91.  
  92.     for (i = 0; ModelTab[i].name; ++i) {
  93.     if (ModelTab[i].value == Num)
  94.         return(ModelTab[i].name);
  95.     }
  96.  
  97.     return((char *) NULL);
  98. }
  99.  
  100. /*
  101.  * Get amount of memory.
  102.  */
  103. extern char *GetMemory()
  104. {
  105.     static char            Buf[BUFSIZ];
  106.     int                Amount = -1;
  107. #if    defined(HAVE_LIB_SYSCFG)
  108.     int             mem, ip, ce, det, att;
  109.  
  110.     lib_syscfg(&mem, &ip, &ce, &det, &att);
  111.     Amount = mem;
  112. #endif    /* HAVE_LIB_SYSCFG */
  113. #if    defined(HAVE_MEMORYSIZE)
  114.     Amount = memorysize;
  115. #endif    /* HAVE_MEMORYSIZE */
  116.  
  117.     if (Amount > 0) {
  118.     (void) sprintf(Buf, "%d MB", Amount);
  119.     return(Buf);
  120.     } else
  121.     return((char *) NULL);
  122. }
  123.  
  124. /*
  125.  * Get kernel version string from kernel.
  126.  */
  127. extern char *GetKernelVersionStr()
  128. {
  129.     extern struct nlist        VersionInfoNL[];
  130.     static char            Version[BUFSIZ];
  131.     static char            VerName[BUFSIZ], VerDate[BUFSIZ];
  132.     register char           *p;
  133.     kvm_t               *kd;
  134.  
  135.     Version[0] = C_NULL;
  136.  
  137.     if (!(kd = KVM_open(VersionInfoNL))) {
  138.     if (Debug) Error("GetKernelVersionStr() KVM_open failed.");
  139.     return((char *) NULL);
  140.     }
  141.  
  142.     /*
  143.      * See if we got a valid entry
  144.      */
  145.     if (CheckNlist(&VersionInfoNL[0]) || CheckNlist(&VersionInfoNL[1]))
  146.     return((char *) NULL);
  147.  
  148.     if (KVM_read(kd, VersionInfoNL[0].n_value, (char *) VerName, 
  149.          sizeof(VerName))) {
  150.     if (Debug) Error("GetKernelVersionStr() KVM_read versionname failed.");
  151.     return((char *) NULL);
  152.     }
  153.  
  154.     if (KVM_read(kd, VersionInfoNL[1].n_value, (char *) VerDate, 
  155.           sizeof(VerDate))) {
  156.     if (Debug) Error("GetKernelVersionStr() KVM_read versiondate failed.");
  157.     return((char *) NULL);
  158.     }
  159.  
  160.     if (kd)
  161.     KVM_close(kd);
  162.  
  163.     /*
  164.      * Zap trailing white space
  165.      */
  166.     p = VerName;
  167.     p = p + strlen(VerName) - 1;
  168.     while (*p == ' ') {
  169.     *p = C_NULL;
  170.     *--p;
  171.     }
  172.  
  173.     (void) sprintf(Version, "%s: %s", VerName, VerDate);
  174.  
  175.     return(Version);
  176. }
  177.  
  178. /*
  179.  * Get system serial number.
  180.  */
  181. extern char *GetSerialNoStr()
  182. {
  183. #if    defined(HAVE_SERIALNUM)
  184.     /*
  185.      * Use global variable "serialnum"
  186.      */
  187.     return(itoa(serialnum));
  188. #endif    /* HAVE_SERIALNUM */
  189. #if    defined(HAVE_USERETC)
  190.     /*
  191.      * Use global variable "useretc"
  192.      */
  193.     return(itoa(useretc->bp_serialnum));
  194. #endif     /* HAVE_USERETC */
  195. }
  196.  
  197. /*
  198.  * Get OS Version string
  199.  */
  200. extern char *GetOSVersionStr()
  201. {
  202.     return(GetOSVersionFromKernVer());
  203. }
  204.  
  205. /*
  206.  * Get ROM Version
  207.  */
  208. extern char *GetRomVer()
  209. {
  210.     /* No support */
  211.     return((char *) NULL);
  212. }
  213.