source: trunk/athena/bin/machtype/machtype_solaris.c @ 15885

Revision 15885, 3.7 KB checked in by ghudson, 23 years ago (diff)
Nuke unused variables.
RevLine 
[13614]1/*
2 *  Machtype: determine machine type & display type
3 *
4 * RCS Info
[15885]5 *    $Id: machtype_solaris.c,v 1.4 2001-03-26 20:26:51 ghudson Exp $
[13614]6 */
7
8#define volatile
9#include <stdio.h>
10#include <string.h>
11#include <kvm.h>
12#include <nlist.h>
13#include <fcntl.h>
14#include <unistd.h>
15#include <sys/types.h>
16#include <sys/file.h>
17#include <sys/cpu.h>
18#include <ctype.h>
19#include <dirent.h>
20#include <sys/vtoc.h>
21/* OpenPROM stuff */
22#include <sys/promif.h>
23#include <sys/ddi.h>
24#include <sys/sunddi.h>
25#include <sys/ddi_impldefs.h>
[15698]26#include <sys/systeminfo.h>
[13614]27/* Frame buffer stuff */
28#include <sys/fbio.h>
29#include <errno.h>
30#include "machtype.h"
31
32void do_machtype(void)
33{
34    puts("sun4");
35}
36
[15698]37void do_cpu(int verbose)
[13614]38{
39  char            buf[BUFSIZ];
40
41  char*           cpustr;
42
43  /* read device name of the top node of the OpenPROM */
44
[15698]45  if (sysinfo(SI_PLATFORM, buf, BUFSIZ) < 0) {
46    fprintf(stderr, "Can't get CPU information\n");
[13614]47    exit(2);
48  }
49  buf[BUFSIZ-1] = '\0';
50
51  /* now, return a string identifying the CPU */
52
53  if (verbose) {
54    /* "verbose" returns the kernel information directly */
55    puts(buf);
56
57  } else {
58
59    /* skip the initial "SUNW," */
60    cpustr = strchr(buf, ',');
61    if (cpustr)
62      cpustr++;
63    else
64      cpustr = buf;
65
66    /* reformat the result to look like "SPARC/Classic" or "SPARC/5" */
67    if (! strncmp(cpustr, "SPARC", sizeof("SPARC")-1)) {
68      cpustr += sizeof("SPARC")-1;
69
70      if (! strncmp(cpustr, "station-", sizeof("station-")-1))
71        cpustr += sizeof("station-")-1;
72      else
73        if (! strcmp(cpustr, "classic")) /* backwards compat - cap classic */
74          (*cpustr) = toupper(*cpustr);
75
76      printf("SPARC/%s\n", cpustr);
77
78    } else {
79      /* if it didn't start with "SPARC", just leave it be... */
80      puts(cpustr);
81    }
82  }
83
84  return;
85}
86
87void do_dpy(int verbose)
88{
89  int count;
90  char buf[1024], *p;
91
92  count = readlink("/dev/fb", buf, sizeof(buf) - 1);
93  if (count == -1) {
94    puts(verbose ? "unknown frame buffer" : "unknown");
95    return;
96  }
97  buf[count] = 0;
98  p = buf + count;
[13639]99  while (p > buf && isdigit((unsigned char)*(p - 1)))
[13614]100    *--p = 0;
101  p = strrchr(buf, ':');
102  if (!p) {
103    puts(verbose ? "unknown frame buffer" : "unknown");
104    return;
105  }
106  printf("%s%s\n", p + 1, verbose ? " frame buffer" : "");
107}
108
109void do_disk(int verbose)
110{
111  DIR *dp;
112  struct dirent *de;
113  char path[MAXPATHLEN];
114  const char *devdir = "/dev/rdsk";
115  char *cp;
116  int fd;
117  int devlen;                   /* Length of device name, w/o partition */
118  struct vtoc vtoc;
119 
120  dp = opendir(devdir);
121  if (dp == NULL)
122    {
123      fprintf(stderr, "Cannot open %s: %s\n", devdir, strerror(errno));
124      exit(1);
125    }
126
127  while ((de = readdir(dp)) != NULL)
128    {
129      if ((!strcmp(de->d_name, ".")) || (!strcmp(de->d_name, "..")))
130        continue;
131
132      /* By convention partition (slice) 2 is the whole disk. */
133      cp = strrchr(de->d_name, 's');
134      if ((cp == NULL) || (strcmp(cp, "s2") != 0))
135        continue;
136      devlen = cp - de->d_name;         /* Get name length w/o partition */
137      sprintf(path, "%s/%s", devdir, de->d_name);
138      fd = open(path, O_RDONLY);
139      if (fd == -1)
140        continue;
141
142      if ((read_vtoc(fd, &vtoc) < 0) || (vtoc.v_sanity != VTOC_SANE))
143        {
144          close(fd);
145          continue;
146        }
147      close(fd);
148
149      if (!verbose)
150        {
151          /* Strip geometry info from the label text. */
152          cp = strchr(vtoc.v_asciilabel, ' ');
153          if (cp)
154            *cp = '\0';
155        }
156
157      printf("%.*s: %.*s\n",
158             devlen, de->d_name,
159             LEN_DKL_ASCII, vtoc.v_asciilabel);
160    }
161
162  closedir(dp);
163  return;
164}
165
166#define MEG (1024*1024)
167
168void do_memory(int verbose)
169{
170   int mem, nbpp;
171
172   nbpp = getpagesize() / 1024;
[15698]173   mem = sysconf(_SC_PHYS_PAGES);
[13614]174   if(verbose)
175      printf("%d (%d M) total\n", mem * nbpp, (mem * nbpp + 916) / 1024);
176   else
177      printf("%d\n", mem * nbpp + 916);
178   return;
179}
180
Note: See TracBrowser for help on using the repository browser.