home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume26 / sysinfo1 / part01 < prev    next >
Encoding:
Text File  |  1993-04-10  |  277.6 KB  |  11,459 lines

  1. Newsgroups: comp.sources.unix
  2. From: mcooper@usc.edu (Michael A. Cooper)
  3. Subject: v26i114: [REPOST] sysinfo-1.0 - Show system information, Part01/01
  4. Sender: unix-sources-moderator@vix.com
  5. Approved: paul@vix.com
  6.  
  7. Submitted-By: mcooper@usc.edu (Michael A. Cooper)
  8. Posting-Number: Volume 26, Issue 114
  9. Archive-Name: sysinfo-1.0/part01
  10.  
  11. [ the author sent me a last-minute revision to this which i neglected
  12.   to include the first time out.  this is the second and official version
  13.   of v26i114.                                --vix ]
  14.  
  15. This is version 1.0 of sysinfo.  Sysinfo is a program which shows
  16. various pieces of information about a system.  The original version
  17. was written to simply determine the model name of a system for use in
  18. /etc/motd.  It also supported a few other pieces of information that
  19. were simple to obtain, but the method used to obtain the information
  20. on various different OS's varied.  The current version shows many
  21. different "general" bits of system information as well as fairly
  22. detailed information on system devices such as disk drives, frame
  23. buffers, tape drives, and many others.  A lot of the information
  24. sysinfo displays is difficult, if not impossible, to determine by
  25. normal OS commands and/or files after boot time on many OS's.
  26.  
  27. Michael A. Cooper, University Computing Services, U of Southern California
  28.   INTERNET: mcooper@usc.edu                PHONE: (213) 740-2957
  29.   UUCP: ...!uunet!usc!mcooper              BITNET: mcooper@ramoth
  30.  
  31. #! /bin/sh
  32. # This is a shell archive.  Remove anything before this line, then unpack
  33. # it by saving it into a file and typing "sh file".  To overwrite existing
  34. # files, type "sh file -c".  You can also feed this as standard input via
  35. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  36. # will see the following message at the end:
  37. #        "End of shell archive."
  38. # Contents:  README sysinfo.man Makefile sysinfo.c devices.c memory.c
  39. #   kernel.c run.c KVM.c kvm.c kvm.h patchlevel.h strcasecmp.c
  40. #   strdup.c strerror.c options.c options.h system.h defs.h netif.c
  41. #   info-netif.c os-mach.c info-mach.c os-sunos.c info-sunos.c
  42. #   os-ultrix.c info-ultrix.c info-ultrix.h os-next.c info-next.c
  43. #   os-alliant.c info-alliant.c os-bsd43.c info-bsd43.c os-aix.c
  44. #   info-aix.c options.3 Mkfile.cpp
  45. # Wrapped by mcooper@acamar.usc.edu on Mon Jun  1 15:45:17 1992
  46. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  47. if test -f README -a "${1}" != "-c" ; then 
  48.   echo shar: Will not over-write existing file \"README\"
  49. else
  50. echo shar: Extracting \"README\" \(3243 characters\)
  51. sed "s/^X//" >README <<'END_OF_README'
  52. X
  53. X                SYSINFO 1.0
  54. X
  55. X             Michael A. Cooper
  56. X           Research, Development, and Systems Group
  57. X            University Computing Services
  58. X          University of Southern California
  59. X              mcooper@usc.edu
  60. X
  61. X
  62. XGENERAL INFORMATION
  63. X
  64. XThis is version 1.0 of sysinfo.  Sysinfo is a program which shows
  65. Xvarious pieces of information about a system.  The original version
  66. Xwas written to simply determine the model name of a system for use in
  67. X/etc/motd.  It also supported a few other pieces of information that
  68. Xwere simple to obtain, but the method used to obtain the information
  69. Xon various different OS's varied.  The current version shows many
  70. Xdifferent "general" bits of system information as well as fairly
  71. Xdetailed information on system devices such as disk drives, frame
  72. Xbuffers, tape drives, and many others.  A lot of the information
  73. Xsysinfo displays is difficult, if not impossible, to determine by
  74. Xnormal OS commands and/or files after boot time on many OS's.
  75. X
  76. XMost of the OS specific information was determined by groveling
  77. X/usr/include/{sys,machine,*dev}/*.h files, section 4 man pages, and
  78. Xreverse engineering the output from various commands like devinfo
  79. X(SunOS) and using the trace(2) facility.  Some of the network (netif)
  80. Xcode was inspired by the sources to the 4.3BSD netstat and ifconfig
  81. Xcommands.
  82. X
  83. XSUPPORTTED PLATFORMS
  84. X
  85. XSysinfo has been tested on the platforms listed below.  Porting to
  86. Xother BSD based Unix's is fairly straight-forward.
  87. X
  88. X    Sun-3            SunOS 4.0.3, 4.1.1
  89. X    Sun-386            SunOS 4.0.1
  90. X    Sun-4            SunOS 4.0.3, 4.1.1, 4.1.2
  91. X    SPARCbook-1        Solaris 1.0.1 SPARCbook Version A.3
  92. X    Solbourne Series5E    OS/MP 4.1A
  93. X    DEC MIPS        Ultrix 4.1, 4.2
  94. X    NeXT            NeXT 2.1
  95. X    IBM RS6000        *AIX 3.1
  96. X    Alliant         *Concentrix 5.X, *Concentrix-2800 2.0
  97. X    HP300            *MORE/bsd 4.3 (BSD)
  98. X
  99. X        * - No device information support
  100. X
  101. X
  102. XINSTALLATION
  103. X
  104. XInstalling on one of the platforms listed above should just be a
  105. Xmatter of editing Makefile and running "make".
  106. X
  107. XRun "make install" to install the sysinfo binary and "make
  108. Xinstall.man" to install the man page.
  109. X
  110. XBUG FIXES
  111. X
  112. XPlease send bug fixes, suggestions, and comments to mcooper@usc.edu.
  113. X
  114. XWHERE TO GET IT
  115. X
  116. XThe latest/greatest version of sysinfo is available via anonymous ftp
  117. Xon usc.edu in /pub/sysinfo.
  118. X
  119. XPLATFORM SPECIFIC NOTES
  120. X
  121. XThe following are notes regarding specific platforms:
  122. X
  123. XSunOS    Sysinfo should be compiled for each kernel architecture machine
  124. X    you wish to run it on.  It is normally installed into /usr/kvm
  125. X    and symlinked into something like /usr/local/bin.
  126. X
  127. X    Sun386i device support is shakey, at best.  No SCSI disk info
  128. X    is found.  The kernel device init table doesn't seem to have
  129. X    any of the disk info in it.  I haven't had time to track this
  130. X    down.
  131. X
  132. XNeXT    The C compiler under NeXT 2.1 is an old version of GCC (1.34).
  133. X    That version is broken and will not compile sysinfo.  We installed
  134. X    GCC 2.0 without problem under NeXT 2.1 and it seems to work
  135. X    very well with sysinfo.
  136. X
  137. X    Network address info for network interfaces is not working.  There
  138. X    is currently no debugger that works with GCC 2.0 so I haven't spent
  139. X    time on this.
  140. X
  141. XOTHER KNOWN PROBLEMS
  142. X
  143. XSPARCbook "id" DISKS
  144. X    The label on "id" disks on the SPARCbook-1 cannot be read.  This
  145. X    appears to be because the definition of IDE_READ in 
  146. X    <taddev/ide_drvr_def.h> is incorrect.
  147. END_OF_README
  148. if test 3243 -ne `wc -c <README`; then
  149.     echo shar: \"README\" unpacked with wrong size!
  150. fi
  151. # end of overwriting check
  152. fi
  153. if test -f sysinfo.man -a "${1}" != "-c" ; then 
  154.   echo shar: Will not over-write existing file \"sysinfo.man\"
  155. else
  156. echo shar: Extracting \"sysinfo.man\" \(3518 characters\)
  157. sed "s/^X//" >sysinfo.man <<'END_OF_sysinfo.man'
  158. X.\"
  159. X.\" Copyright (c) 1992 Michael A. Cooper.
  160. X.\" This software may be freely distributed provided it is not sold for 
  161. X.\" profit and the author is credited appropriately.
  162. X.\"
  163. X.\" $Header: /src/common/usc/bin/sysinfo/RCS/sysinfo.man,v 1.9 1992/04/26 23:31:36 mcooper Exp $
  164. X.\" 
  165. X.TH SYSINFO 1 "26 April 1992"
  166. X.ds ]W USC-UCS
  167. X.SH NAME
  168. Xsysinfo \- Display system information
  169. X.SH SYNOPSIS
  170. Xsysinfo
  171. X[
  172. X.B +|\-all
  173. X] 
  174. X[
  175. X.B \-level
  176. X.I level1,level2,...
  177. X]
  178. X[
  179. X.B \-show
  180. X.I item1,item2,...
  181. X] 
  182. X[
  183. X.B +|\-terse
  184. X] 
  185. X[
  186. X.B +|\-unknown
  187. X] 
  188. X.br
  189. X.sp
  190. Xsysinfo 
  191. X.B \-list
  192. X[
  193. X.B level|show
  194. X]
  195. X.br
  196. X.sp
  197. Xsysinfo 
  198. X.B \-version
  199. X.SH DESCRIPTION
  200. X.I Sysinfo
  201. Xdisplays certain pieces of system information for the current host.
  202. XBy default, 
  203. X.I sysinfo
  204. Xdisplays all system information it knows about in verbose mode.
  205. XThis includes:
  206. X.IP *
  207. XHost name
  208. X.IP *
  209. XHost name aliases
  210. X.IP *
  211. XHost network addresses
  212. X.IP *
  213. XHost ID
  214. X.IP *
  215. XSystem serial number
  216. X.IP *
  217. XManufacturer of the system's hardware
  218. X.IP *
  219. XCPU model name
  220. X.IP *
  221. XCPU type
  222. X.IP *
  223. XApplication architecture
  224. X.IP *
  225. XKernel architecture
  226. X.IP *
  227. XAmount of main memory
  228. X.IP *
  229. XOperating system name
  230. X.IP *
  231. XOperating system version
  232. X.IP *
  233. XKernel version
  234. X.IP *
  235. XA variety of information about devices.
  236. X.PP
  237. XBy default,
  238. X.B sysinfo
  239. Xwill display most info items it knows about.
  240. XSpecific items may be exclusively shown by using the
  241. X.B \-show
  242. Xoption and specifying a comma seperated list of items.
  243. X.SH OPTIONS
  244. X.IP "\fB+|-all\fP"
  245. XEnable (\fB+all\fP) or disable (\fB\-all\fP) displaying all known information.
  246. XThis option is enabled by default.
  247. X.IP "\fB\-level \fIlevels\fR"
  248. XSet the show level.
  249. X.I levels
  250. Xis a comma seperated list of values used to determine what
  251. Xlevels of information will be displayed.
  252. XUse the
  253. X.B "\-list level"
  254. Xoption to get a list of valid 
  255. X.I levels.
  256. X.IP "\fB\-list [ level|show ]\fR"
  257. XList all the possible values that may be used with an option.
  258. XSpecifying
  259. X.B "\-list show"
  260. Xwill list possible values for use with the
  261. X.B \-show
  262. Xoption.
  263. XSpecifying
  264. X.B "\-list level"
  265. Xwill list possible values for use with the
  266. X.B \-level
  267. Xoption.
  268. X.IP "\fB+|-terse\fP"
  269. XEnable (\fB+terse\fP) or disable (\fB\-terse\fP) showing items in
  270. Xterse format.
  271. XWhen enabled this 
  272. Xusually means that the field label for each item is not displayed.
  273. XThis option is disabled by default.
  274. X.IP "\fB\-show \fIitem1,item2,...\fR"
  275. XShow information only about each comma seperated item.
  276. XA current list of valid item names can be determined by using the
  277. X.B "\-list show"
  278. Xoption.
  279. X.IP "\fB+|-unknown\fP"
  280. XEnable (\fB+unknown\fP) or disable (\fB\-unknown\fP) showing devices
  281. Xthat appear to be present on the system, but are not "known" to sysinfo.
  282. XThis option is disabled by default.
  283. X.IP "\fB-version\fP"
  284. XShow version
  285. Xinformation for
  286. X.I sysinfo.
  287. X.SH AUTHOR
  288. XMichael A. Cooper, 
  289. X.br
  290. XUniversity Computing Services, 
  291. X.br
  292. XUniversity of Southern California.
  293. X.SH FILES
  294. X.sp
  295. X/etc/cpumodel.name    \- Explicitly set the CPU model name
  296. X.SH SEE ALSO
  297. Xgethostid(2), gethostname(2), gethostbyname(3)
  298. X.SH DIAGNOSTICS
  299. X.IP "\fI%x: Unknown CPU type.\fP"
  300. XThe CPU model for the current host could not be determined.
  301. X.IP "(unknown)"
  302. XInformation could not be determined for this item.
  303. X.SH BUGS
  304. XNot all operating systems support interfaces to various pieces of
  305. Xinformation that sysinfo supports.
  306. X.PP
  307. XSome devices, mostly devices that use 
  308. Xremovable media such as
  309. Xtape drives and floppy disks, are only indicated (shown) as
  310. Xpresent if media is loaded in the device and it's on-line.
  311. XThis occurs because the OS does not provide a software
  312. Xinterface to query the device when media is not loaded.
  313. END_OF_sysinfo.man
  314. if test 3518 -ne `wc -c <sysinfo.man`; then
  315.     echo shar: \"sysinfo.man\" unpacked with wrong size!
  316. fi
  317. # end of overwriting check
  318. fi
  319. if test -f Makefile -a "${1}" != "-c" ; then 
  320.   echo shar: Will not over-write existing file \"Makefile\"
  321. else
  322. echo shar: Extracting \"Makefile\" \(3784 characters\)
  323. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  324. X#
  325. X# Copyright (c) 1992 Michael A. Cooper.
  326. X# This software may be freely distributed provided it is not sold for 
  327. X# profit and the author is credited appropriately.
  328. X#
  329. X# $Header: /src/common/usc/bin/sysinfo/RCS/Makefile,v 1.8 1992/04/26 23:31:36 mcooper Exp $
  330. X#
  331. X# Makefile for sysinfo
  332. X#
  333. X
  334. X#
  335. X# Location of your Kernel specific directory.
  336. X# This is usually only for SunOS.  If you don't have
  337. X# one, set this to nothing
  338. X#
  339. XKVM        = /usr/kvm
  340. X
  341. X#
  342. X# The bin directory that user's will run the program from.
  343. X# For systems with a $(KVM) (above), a symlink will be put 
  344. X# in $(BIN) pointing to ${KVM}/sysinfo.  On systems without 
  345. X# a $(KVM), the program will be copied to $(BIN).
  346. X#
  347. X# A good place is something like /usr/local/bin.
  348. X#
  349. XBIN         = /usr/local/bin
  350. X
  351. X#
  352. X# Directory to install man page in.
  353. X#
  354. XMAN         = /usr/local/man/man1
  355. X
  356. X#
  357. X# The name of the kvm library to use.
  358. X# For SunOS this should be "-lkvm".  For others it should be "kvm.c"
  359. X#
  360. XLIBKVM        = -lkvm
  361. X
  362. X#
  363. X# SunOS 4.0 -> 4.0.3 requires using the System V cc and libc
  364. X# in order to get uname().
  365. X#
  366. X#CC        = /usr/5bin/cc
  367. X#LIBS         = /usr/5lib/libc.a
  368. X#
  369. X# The C compiler (gcc) under NeXT 2.1 and earlier is broken.
  370. X# You need GCC 2.0 or later.
  371. X#
  372. X#CC        = gcc
  373. X
  374. X#
  375. X# Defines.
  376. X#
  377. X# SunOS needs:
  378. X#    -D`/bin/arch -k`
  379. X#
  380. XDEFINES        = -D`/bin/arch -k`
  381. X
  382. X#
  383. X# Optimization or debugging flag
  384. X#
  385. XOPT        = -g
  386. X
  387. X#
  388. X# Include directories
  389. X#
  390. XINCLUDES    = -I.
  391. X
  392. XCFLAGS         = ${OPT} ${INCLUDES} ${DEFINES}
  393. X
  394. XNETIFFILES    = netif.c info-netif.c
  395. XMACHFILES    = os-mach.c info-mach.c
  396. X
  397. X#
  398. X# Select the OS specific files to compile
  399. X#
  400. X# SunOS
  401. XOSFILES        = os-sunos.c info-sunos.c ${NETIFFILES}
  402. X# Ultrix
  403. X#OSFILES    = os-ultrix.c info-ultrix.c ${NETIFFILES}
  404. X# NeXT
  405. X#OSFILES    = os-next.c info-next.c ${MACHFILES} ${NETIFFILES}
  406. X# Alliant
  407. X#OSFILES    = os-alliant.c info-alliant.c
  408. X# AIX
  409. X#OSFILES    = os-aix.c info-aix.c
  410. X# HP300's running 4.3BSD (MORE/bsd)
  411. X#OSFILES    = os-bsd43.c info-bsd43.c
  412. X
  413. X#
  414. X# Misc files
  415. X#
  416. X# List of files of things your system may not have.
  417. X# This may include strcasecmp.c, strdup.c, and strerror.c.
  418. X#
  419. XMISCFILES    = strdup.c
  420. X
  421. X#
  422. X# Installation options
  423. X#
  424. X# Sysinfo needs to be able to read your unix image (/vmunix usually),
  425. X# /dev/kmem, and device files in /dev for things like disk drives and tapes.
  426. X# Under SunOS, /dev/kmem is owned by group "kmem", but the disk files
  427. X# (e.g. /dev/rsd0a) are owned by group "operator".  Therefor, you usually
  428. X# can't make setgid to a group, but need it setuid root.
  429. X#
  430. X# You should set the INSTALLOPTS appropriately to allow sysinfo to read
  431. X# everything it needs to.  Try running "sysinfo -debug" to find out the
  432. X# special files it reads.
  433. X#
  434. XINSTALLOPTS     = -m 4555 -o root -g wheel
  435. X
  436. XBASE         = sysinfo
  437. XPROG         = ${BASE}
  438. XSRCS         = ${BASE}.c devices.c memory.c kernel.c run.c KVM.c options.c \
  439. X            ${MISCFILES} ${OSFILES}
  440. XOBJS        = $(SRCS:%.c=$(VARIANT)%.o)
  441. X
  442. Xall: ${PROG}
  443. X
  444. X${PROG}: ${OBJS}
  445. X    ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} ${LIBKVM}
  446. X
  447. X#
  448. X# CenterLine support
  449. X#
  450. Xccenter_src: ${SRCS}
  451. X    #load ${CFLAGS} ${SRCS} ${LIBS} ${LIBKVM}
  452. X
  453. Xccenter_obj: ${OBJS}
  454. X    #load ${CFLAGS} ${OBJS} ${LIBS} ${LIBKVM}
  455. X
  456. Xinstall: ${PROG}
  457. X    @if [ "${KVM}" ]; then \
  458. X        echo "install -c ${INSTALLOPTS} ${PROG} ${KVM}/${BASE}"; \
  459. X        install -c ${INSTALLOPTS} ${PROG} ${KVM}/${BASE}; \
  460. X        echo "cd ${BIN} && rm -f ${BASE} && ln -s ${KVM}/${BASE} ${BASE}"; \
  461. X        (cd ${BIN} && rm -f ${BASE} && ln -s ${KVM}/${BASE} ${BASE}); \
  462. X    else \
  463. X        echo install -c ${INSTALLOPTS} ${PROG} ${BIN}/${BASE}; \
  464. X        install -c ${INSTALLOPTS} ${PROG} ${BIN}/${BASE}; \
  465. X    fi
  466. X
  467. Xinstall.man: ${BASE}.man
  468. X    install -c -m 444 -o bin -g bin ${BASE}.man ${MAN}/${BASE}.1
  469. X
  470. Xinstall.compat:
  471. X    install -c -m 555 -o bin -g bin cpumodel.sh /usr/lsd/etc/cpumodel
  472. X    rm -f $MAN/${BASE}.8 $MAN/cpumodel.1
  473. X    (cd /usr/usc/bin; rm -f sysinfo; ln -s ${BIN}/sysinfo)
  474. X
  475. Xclean:
  476. X    rm -f *.o ${PROG} *~ *% \#* core a.out sysinfo.tar sysinfo.tar.Z
  477. X
  478. X${OBJS}: system.h defs.h
  479. END_OF_Makefile
  480. if test 3784 -ne `wc -c <Makefile`; then
  481.     echo shar: \"Makefile\" unpacked with wrong size!
  482. fi
  483. # end of overwriting check
  484. fi
  485. if test -f sysinfo.c -a "${1}" != "-c" ; then 
  486.   echo shar: Will not over-write existing file \"sysinfo.c\"
  487. else
  488. echo shar: Extracting \"sysinfo.c\" \(26266 characters\)
  489. sed "s/^X//" >sysinfo.c <<'END_OF_sysinfo.c'
  490. X/*
  491. X * Copyright (c) 1992 Michael A. Cooper.
  492. X * This software may be freely distributed provided it is not sold for 
  493. X * profit and the author is credited appropriately.
  494. X */
  495. X
  496. X#ifndef lint
  497. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/sysinfo.c,v 1.47 1992/04/26 23:32:06 mcooper Exp $";
  498. X#endif
  499. X
  500. X/*
  501. X * $Log: sysinfo.c,v $
  502. X * Revision 1.47  1992/04/26  23:32:06  mcooper
  503. X * Add Copyright notice
  504. X *
  505. X * Revision 1.46  1992/04/17  23:27:51  mcooper
  506. X * Add support for ROM Version information (Sun only for now).
  507. X *
  508. X * Revision 1.45  1992/04/17  01:07:59  mcooper
  509. X * More de-linting
  510. X *
  511. X * Revision 1.44  1992/04/16  02:25:39  mcooper
  512. X * Bug fixes, de-linting, and other changes found with CodeCenter.
  513. X *
  514. X * Revision 1.43  1992/04/15  02:07:45  mcooper
  515. X * Fixed problem with "-show man +terse".
  516. X *
  517. X * Revision 1.42  1992/04/15  02:00:36  mcooper
  518. X * Major re-write and simplification of command line options.
  519. X *
  520. X * Revision 1.41  1992/03/31  18:57:40  mcooper
  521. X * - Don't stomp on Kernel Version strings.
  522. X * - Change "verbose" to "Show".
  523. X *
  524. X * Revision 1.40  1992/03/25  02:29:51  mcooper
  525. X * Add verbose keywords.
  526. X *
  527. X * Revision 1.39  1992/03/22  00:56:12  mcooper
  528. X * Updates for NeXT.
  529. X *
  530. X * Revision 1.38  1992/03/22  00:20:10  mcooper
  531. X * Major cleanup and re-org.
  532. X *
  533. X * Revision 1.37  1992/03/03  23:57:23  mcooper
  534. X * Make HAVE_KVM and HAVE_NLIST consistant.
  535. X *
  536. X * Revision 1.36  1992/03/03  02:51:07  mcooper
  537. X * Move strdup() to strdup.c
  538. X *
  539. X * Revision 1.35  1992/03/01  23:27:30  mcooper
  540. X * Move bulk of OS specific routines to OS specific files.
  541. X *
  542. X * Revision 1.34  1992/03/01  20:30:06  mcooper
  543. X * Cleanup handling of general info.
  544. X *
  545. X * Revision 1.33  1992/03/01  19:00:55  mcooper
  546. X * Fixed memory size code to be more portable.
  547. X *
  548. X * Revision 1.32  1992/02/22  02:18:20  mcooper
  549. X * Use new KVM() calling convention.
  550. X *
  551. X * Revision 1.31  1992/02/17  01:00:51  mcooper
  552. X * Changes for devices and "general" info.
  553. X *
  554. X * Revision 1.30  1992/02/13  22:37:18  mcooper
  555. X * Add 4/25 hostid.
  556. X *
  557. X * Revision 1.29  1992/02/10  21:06:22  mcooper
  558. X * Cleanup, add support for Sun4m and devices.
  559. X *
  560. X * Revision 1.28  1991/11/10  01:13:41  mcooper
  561. X * Use math function floor() instead of rnddown().
  562. X *
  563. X * Revision 1.27  1991/10/14  21:09:39  mcooper
  564. X * Fix get_memory() bug that caused incorrect
  565. X * results when bytes%DIV_BYTES==0.
  566. X *
  567. X * Revision 1.26  1991/10/14  20:29:59  mcooper
  568. X * Fixed get_memory() for Sun's the RIGHT WAY.
  569. X *
  570. X * Revision 1.25  1991/10/12  02:13:16  mcooper
  571. X * Fix memory page counting on Suns again and
  572. X * add -debug option.
  573. X *
  574. X * Revision 1.24  1991/10/10  00:44:54  mcooper
  575. X * Fixed memory calculation.
  576. X *
  577. X * Revision 1.23  1991/10/09  03:37:17  mcooper
  578. X * Add support for getting serial number
  579. X * and model name directly from system on
  580. X * Alliant FX80 series.
  581. X *
  582. X * Revision 1.22  1991/10/01  01:49:15  mcooper
  583. X * Add new system serial number code.
  584. X *
  585. X * Revision 1.21  1991/09/30  05:21:57  mcooper
  586. X * Add support for getting memory and model
  587. X * number on Alliant 2800's.
  588. X *
  589. X * Revision 1.20  1991/09/30  04:33:45  mcooper
  590. X * - Move system dependant stuff to system.h.
  591. X * - Create error() function.
  592. X *
  593. X * Revision 1.19  1991/09/30  04:04:50  mcooper
  594. X * Cleanup Solbourne stuff.
  595. X *
  596. X * Revision 1.18  1991/09/30  01:57:46  mcooper
  597. X * Sun's now use SUN?_ARCH for determining
  598. X * kernel architecture from gethostid().
  599. X *
  600. X * Revision 1.17  1991/09/28  03:42:24  mcooper
  601. X * Fixed Sun 386i model names.
  602. X *
  603. X * Revision 1.16  1991/09/28  03:36:32  mcooper
  604. X * Fixed get_memory() when converting bytes to MB.
  605. X *
  606. X * Revision 1.15  1991/09/28  03:20:00  mcooper
  607. X * Fixed NULL cast problem.
  608. X *
  609. X * Revision 1.14  1991/09/28  03:13:38  mcooper
  610. X * - Cleanup kvm stuff.
  611. X * - Now works on FX alliants.
  612. X *
  613. X * Revision 1.13  1991/09/27  23:03:12  mcooper
  614. X * Major cleanup/re-write.
  615. X *
  616. X * Revision 1.12  1991/09/26  05:24:22  mcooper
  617. X * - Added memory lookup support for Sun's.
  618. X * - Added printing kernel version string.
  619. X *
  620. X * Revision 1.11  1991/09/22  23:50:23  mcooper
  621. X * Use new NeXT/Mach host_info() calls.
  622. X *
  623. X * Revision 1.10  1991/08/31  03:25:50  mcooper
  624. X * Add defines for SPARCstation ELC and IPX.
  625. X *
  626. X * Revision 1.9  1991/03/12  01:26:03  mcooper
  627. X * Changes for AIX on the RS6000.
  628. X *
  629. X * Revision 1.8  1991/02/27  20:14:15  mcooper
  630. X * Add back in the 4_460.  Need both that
  631. X * and 4_470 since Sun changed to 4_470 in 4.1.1.
  632. X *
  633. X * Revision 1.7  1991/02/27  19:25:04  mcooper
  634. X * Change CPU_SUN4_460 to CPU_SUN4_470.
  635. X *
  636. X * Revision 1.6  1991/02/21  02:20:25  mcooper
  637. X * Add OS name and OS version stuff.
  638. X *
  639. X * Revision 1.5  1991/02/20  20:24:16  mcooper
  640. X * Re-arrange default output order.
  641. X *
  642. X * Revision 1.4  1991/02/20  20:19:34  mcooper
  643. X * If any item is enabled from the command
  644. X * line (via a + option), then only print selected
  645. X * item(s) in non verbose mode.
  646. X *
  647. X * Revision 1.3  1991/02/12  17:27:08  root
  648. X * Ported to NeXT 2.0.
  649. X *
  650. X * Revision 1.2  91/02/11  21:58:35  mcooper
  651. X * - Add new routines to print host name, host
  652. X *   name aliases, network addresses, and hostid.
  653. X * - Make verbose format easier to read with new
  654. X *   PrintLabel() function.
  655. X * 
  656. X * Revision 1.1  1991/02/09  01:33:40  mcooper
  657. X * Initial revision
  658. X *
  659. X */
  660. X
  661. X/*
  662. X * Display System Information
  663. X */
  664. X
  665. X#include <stdio.h>
  666. X#include <sys/types.h>
  667. X#include <sys/socket.h>
  668. X#include <netinet/in.h>
  669. X#include <arpa/inet.h>
  670. X#include <netdb.h>
  671. X
  672. X#include "system.h"
  673. X#include "defs.h"
  674. X
  675. X#if    defined(HAVE_UNAME)
  676. X#include <sys/utsname.h>
  677. X#endif    /* HAVE_UNAME */
  678. X
  679. X/*
  680. X * Local declarations
  681. X */
  682. Xextern char               *AppArchCmds[];
  683. Xextern char               *KernArchCmds[];
  684. Xextern char               *ArchFiles[];
  685. Xextern char               *CPUFiles[];
  686. X
  687. Xint                 DoPrintAll = TRUE;
  688. Xint                 DoPrintUnknown = FALSE;
  689. Xint                 DoPrintVersion = FALSE;
  690. Xint                 Level = L_BRIEF;
  691. Xint                 Terse = FALSE;
  692. Xint                 Debug = 0;
  693. Xchar                    *ShowStr = NULL;
  694. Xchar                    *LevelStr = NULL;
  695. Xchar                    *ListStr = NULL;
  696. X
  697. X#if    defined(OPTION_COMPAT)
  698. X/*
  699. X * Old options here for backwards compatibility
  700. X */
  701. Xint                DoPrintCPU = FALSE;
  702. Xint                DoPrintAppArch = FALSE;
  703. Xint                DoPrintHostID = FALSE;
  704. Xint                DoPrintHostName = FALSE;
  705. Xint                DoPrintHostAlias = FALSE;
  706. Xint                DoPrintHostAddrs = FALSE;
  707. Xint                DoPrintKernArch = FALSE;
  708. Xint                DoPrintKernVer = FALSE;
  709. Xint                DoPrintMan = FALSE;
  710. Xint                DoPrintModel = FALSE;
  711. Xint                DoPrintMemory = FALSE;
  712. Xint                DoPrintOSName = FALSE;
  713. Xint                DoPrintOSVer = FALSE;
  714. Xint                DoPrintSerialNo = FALSE;
  715. X#endif    /* OPTION_COMPAT */
  716. X
  717. X/*
  718. X * Command line options table.
  719. X */
  720. XOptionDescRec Opts[] = {
  721. X    {"+all",     NoArg,        OptBool,     __ &DoPrintAll,        "1",
  722. X     NULL,    "Print all information"},
  723. X    {"-all",     NoArg,        OptBool,     __ &DoPrintAll,        "0",
  724. X     NULL,    "Don't print all information"},
  725. X    {"-level",    SepArg,        OptStr,     __ &LevelStr,        NULL,
  726. X     "<see \"-list level\">",    "Level names"},
  727. X    {"-list",    SepArg,        OptStr,     __ &ListStr,        "-",
  728. X     "level,show",    "List information about values"},
  729. X    {"-show",    SepArg,        OptStr,     __ &ShowStr,        NULL,
  730. X     "<see \"-list show\">",    "Show names"},
  731. X    {"+terse",     NoArg,        OptBool,     __ &Terse,        "1",
  732. X     NULL,    "Print info in terse format"},
  733. X    {"-terse",     NoArg,        OptBool,     __ &Terse,        "0",
  734. X     NULL,    "Don't print info in terse format"},
  735. X    {"+unknown",NoArg,        OptBool,     __ &DoPrintUnknown,    "1",
  736. X     NULL,    "Print unknown devices"},
  737. X    {"-unknown",NoArg,        OptBool,     __ &DoPrintUnknown,    "0",
  738. X     NULL,    "Don't print unknown devices"},
  739. X    {"-version",NoArg,        OptBool,     __ &DoPrintVersion,    "1",
  740. X     NULL,    "Print version of this program" },
  741. X    {"-debug",ArgHidden|SepArg,    OptInt,     __ &Debug,        "1",
  742. X     NULL,    "Enable debugging"},
  743. X#if    defined(OPTION_COMPAT)
  744. X    {"+cpu",     NoArg|ArgHidden,OptBool,__ &DoPrintCPU,        "1" },
  745. X    {"-cpu",     NoArg|ArgHidden,OptBool,__ &DoPrintCPU,        "0" },
  746. X    {"+arch",     NoArg|ArgHidden,OptBool,__ &DoPrintAppArch,    "1" },
  747. X    {"-arch",     NoArg|ArgHidden,OptBool,__ &DoPrintAppArch,    "0" },
  748. X    {"+hostid",    NoArg|ArgHidden,OptBool,__ &DoPrintHostID,    "1" },
  749. X    {"-hostid",    NoArg|ArgHidden,OptBool,__ &DoPrintHostID,    "0" },
  750. X    {"+hostname",NoArg|ArgHidden,OptBool,__ &DoPrintHostName,    "1" },
  751. X    {"-hostname",NoArg|ArgHidden,OptBool,__ &DoPrintHostName,    "0" },
  752. X    {"+hostaliases",NoArg|ArgHidden,OptBool,__ &DoPrintHostAlias,"1" },
  753. X    {"-hostaliases",NoArg|ArgHidden,OptBool,__ &DoPrintHostAlias,"0" },
  754. X    {"+hostaddrs",NoArg|ArgHidden,OptBool,__ &DoPrintHostAddrs,    "1" },
  755. X    {"-hostaddrs",NoArg|ArgHidden,OptBool,__ &DoPrintHostAddrs,    "0" },
  756. X    {"+karch",     NoArg|ArgHidden,OptBool,__ &DoPrintKernArch,    "1" },
  757. X    {"-karch",     NoArg|ArgHidden,OptBool,__ &DoPrintKernArch,    "0" },
  758. X    {"+kernver",NoArg|ArgHidden,OptBool,__ &DoPrintKernVer,    "1" },
  759. X    {"-kernver",NoArg|ArgHidden,OptBool,__ &DoPrintKernVer,    "0" },
  760. X    {"+man",     NoArg|ArgHidden,OptBool,__ &DoPrintMan,        "1" },
  761. X    {"-man",     NoArg|ArgHidden,OptBool,__ &DoPrintMan,        "0" },
  762. X    {"+model",     NoArg|ArgHidden,OptBool,__ &DoPrintModel,    "1" },
  763. X    {"-model",     NoArg|ArgHidden,OptBool,__ &DoPrintModel,    "0" },
  764. X    {"+memory",    NoArg|ArgHidden,OptBool,__ &DoPrintMemory,    "1" },
  765. X    {"-memory",    NoArg|ArgHidden,OptBool,__ &DoPrintMemory,    "0" },
  766. X    {"+osname",    NoArg|ArgHidden,OptBool,__ &DoPrintOSName,    "1" },
  767. X    {"-osname",    NoArg|ArgHidden,OptBool,__ &DoPrintOSName,    "0" },
  768. X    {"+osvers",    NoArg|ArgHidden,OptBool,__ &DoPrintOSVer,    "1" },
  769. X    {"-osvers",    NoArg|ArgHidden,OptBool,__ &DoPrintOSVer,    "0" },
  770. X    {"+serial",    NoArg|ArgHidden,OptBool,__ &DoPrintSerialNo,    "1" },
  771. X    {"-serial",    NoArg|ArgHidden,OptBool,__ &DoPrintSerialNo,    "0" },
  772. X#endif    /* OPTION_COMPAT */
  773. X};
  774. X
  775. X/*
  776. X * Option compatibility support
  777. X */
  778. X#if    defined(OPTION_COMPAT)
  779. Xstatic void            SetOptionCompat();
  780. X#define OptCom(v) v
  781. X#else
  782. X#define OptCom(v) 0
  783. X#endif
  784. X
  785. XSHOWINFO ShowInfo[] = {
  786. X    { S_GEN, "general",    "GENERAL INFORMATION",    ShowGeneral },
  787. X    { S_GEN, "hostname",    "Host Name",        NULL, GetHostName,
  788. X                        OptCom(&DoPrintHostName) },
  789. X    { S_GEN, "hostaliases",    "Host Aliases",        NULL, GetHostAliases,
  790. X                        OptCom(&DoPrintHostAlias) },
  791. X    { S_GEN, "hostaddrs",    "Host Address(es)",    NULL, GetHostAddrs,
  792. X                        OptCom(&DoPrintHostAddrs) },
  793. X    { S_GEN, "hostid",        "Host ID",        NULL, GetHostID,
  794. X                        OptCom(&DoPrintHostID) },
  795. X    { S_GEN, "serial",        "Serial Number",    NULL, GetSerialNo,
  796. X                        OptCom(&DoPrintSerialNo) },
  797. X    { S_GEN, "man",        "Manufacturer",        NULL, GetMan,
  798. X                        OptCom(&DoPrintMan) },
  799. X    { S_GEN, "model",        "System Model",        NULL, GetModel,
  800. X                        OptCom(&DoPrintModel) },
  801. X    { S_GEN, "memory",        "Main Memory",        NULL, GetMemory,
  802. X                        OptCom(&DoPrintMemory) },
  803. X    { S_GEN, "romver",        "ROM Version",        NULL, GetRomVer },
  804. X    { S_GEN, "cpu",        "CPU Type",        NULL, GetCPU,
  805. X                        OptCom(&DoPrintCPU) },
  806. X    { S_GEN, "arch",        "App Architecture",    NULL, GetAppArch,
  807. X                        OptCom(&DoPrintAppArch) },
  808. X    { S_GEN, "karch",        "Kernel Architecture",    NULL, GetKernArch,
  809. X                        OptCom(&DoPrintKernArch) },
  810. X    { S_GEN, "osname",        "OS Name",        NULL, GetOSName,
  811. X                        OptCom(&DoPrintOSName) },
  812. X    { S_GEN, "osvers",        "OS Version",        NULL, GetOSVersion,
  813. X                        OptCom(&DoPrintOSVer) },
  814. X    { S_GEN, "kernver",        "Kernel Version",    NULL, GetKernelVersion,
  815. X                        OptCom(&DoPrintKernVer) },
  816. X    { S_DEV, "devices",    "DEVICE INFORMATION",    ShowDevices },
  817. X    { 0 },
  818. X};
  819. X
  820. X/*
  821. X * Values and names of levels
  822. X */
  823. XNAMETAB LevelNames[] = {
  824. X    { L_BRIEF,        "brief" },
  825. X    { L_GENERAL,    "general" },
  826. X    { L_DESC,        "descriptions" },
  827. X    { L_CONFIG,        "config" },
  828. X    { L_ALL,        "all" },
  829. X    { L_DEBUG,        "debug" },
  830. X    { 0 },
  831. X};
  832. X
  833. X/*
  834. X * List table
  835. X */
  836. Xstruct listtab {
  837. X    char               *Name;
  838. X    char               *Desc;
  839. X    void              (*Func)();
  840. X};
  841. Xtypedef struct listtab LISTTAB;
  842. X
  843. Xstatic void            List();
  844. Xstatic void            ListLevel();
  845. Xstatic void            ListShow();
  846. X
  847. XLISTTAB ListTab[] = {
  848. X    { "level",        "Values for -level option",    ListLevel },
  849. X    { "show",        "Values for -show option",    ListShow },
  850. X    { 0 },
  851. X};
  852. X
  853. X/*
  854. X * Print a label and an argument
  855. X */
  856. Xstatic void PrintLabel(Lbl, Str)
  857. X     char                *Lbl;
  858. X     char                *Str;
  859. X{
  860. X    if (!Terse)
  861. X    printf("%-*s: ", 20, Lbl);
  862. X    printf("%s\n", (Str && *Str) ? Str : "");
  863. X}
  864. X
  865. X/*
  866. X * Print general info
  867. X */
  868. Xextern void ShowGeneral(MyInfo, SpecInfo)
  869. X    SHOWINFO               *MyInfo;
  870. X    SHOWINFO               *SpecInfo;
  871. X{
  872. X    register int        i;
  873. X    int                ShowAll = TRUE;
  874. X
  875. X    /*
  876. X     * Do a specific info item
  877. X     */
  878. X    if (SpecInfo) {
  879. X    PrintLabel(SpecInfo->Label, (*SpecInfo->GetFunc)());
  880. X    SpecInfo->Enable = FALSE;
  881. X    return;
  882. X    }
  883. X
  884. X    /*
  885. X     * See if we are going to show all items
  886. X     */
  887. X    if (!DoPrintAll)
  888. X    for (i = 0; ShowInfo[i].Name; i++)
  889. X        if (ShowInfo[i].Type == MyInfo->Type && 
  890. X        ShowInfo[i].GetFunc && !ShowInfo[i].Enable) {
  891. X        ShowAll = FALSE;
  892. X        break;
  893. X        }
  894. X
  895. X    if (MyInfo && (DoPrintAll || ShowAll || MyInfo->Enable))
  896. X    printf("\n\n\t%s\n\n", MyInfo->Label);
  897. X
  898. X    /*
  899. X     * Print each enabled item of our type
  900. X     */
  901. X    for (i = 0; ShowInfo[i].Name; i++)
  902. X    if ((ShowInfo[i].Type == MyInfo->Type) &&
  903. X        (ShowInfo[i].Enable || MyInfo->Enable) && ShowInfo[i].GetFunc) {
  904. X        PrintLabel(ShowInfo[i].Label, (*ShowInfo[i].GetFunc)());
  905. X        ShowInfo[i].Enable = FALSE;
  906. X    }
  907. X
  908. X    if (MyInfo)
  909. X    MyInfo->Enable = FALSE;
  910. X}
  911. X
  912. X/*
  913. X * List Show values
  914. X */
  915. Xstatic void ListShow()
  916. X{
  917. X    register int        i;
  918. X
  919. X    printf(
  920. X    "The following values may be specified with the \"-show\" option:\n");
  921. X    printf("\t%-20s %s\n", "VALUE", "DESCRIPTION");
  922. X
  923. X    for (i = 0; ShowInfo[i].Name; i++)
  924. X    printf("\t%-20s %s%s\n",
  925. X           ShowInfo[i].Name,
  926. X           (ShowInfo[i].ShowFunc) ? "Show all " : "",
  927. X           ShowInfo[i].Label
  928. X           );
  929. X}
  930. X
  931. X/*
  932. X * List Level values
  933. X */
  934. Xstatic void ListLevel()
  935. X{
  936. X    register int        i;
  937. X
  938. X    printf(
  939. X    "The following values may be specified with the \"-level\" option:\n");
  940. X    printf("\t%-20s\n", "VALUE");
  941. X
  942. X    for (i = 0; LevelNames[i].name; i++) {
  943. X    printf("\t%s\n", LevelNames[i].name);
  944. X    }
  945. X}
  946. X
  947. X/*
  948. X * List list values
  949. X */
  950. Xstatic void ListList()
  951. X{
  952. X    register int        i;
  953. X
  954. X    printf(
  955. X    "The following values may be specified with the \"-list\" option:\n");
  956. X    printf("\t%-20s %s\n", "VALUE", "DESCRIPTION");
  957. X
  958. X    for (i = 0; ListTab[i].Name; i++) {
  959. X    printf("\t%-20s %s\n",
  960. X           ListTab[i].Name,
  961. X           ListTab[i].Desc
  962. X           );
  963. X    }
  964. X}
  965. X
  966. X/*
  967. X * List information about each word found in Str.
  968. X */
  969. Xstatic void List(Str)
  970. X    char               *Str;
  971. X{
  972. X    register int        i;
  973. X    char               *Word;
  974. X    int                Found;
  975. X
  976. X    if (EQ(Str, "-")) {
  977. X    ListList();
  978. X    return;
  979. X    }
  980. X
  981. X    for (Word = strtok(Str, ","); Word; Word = strtok((char *)NULL, ",")) {
  982. X    for (i = 0, Found = FALSE; ListTab[i].Name && !Found; i++)
  983. X        if (EQ(Word, ListTab[i].Name)) {
  984. X        Found = TRUE;
  985. X        (*ListTab[i].Func)();
  986. X        }
  987. X
  988. X    if (!Found) {
  989. X        Error("The word \"%s\" is invalid.", Word);
  990. X        ListList();
  991. X        return;
  992. X    }
  993. X    }
  994. X}
  995. X
  996. X/*
  997. X * Get argument number "arg" from "str".
  998. X */
  999. Xstatic char *GetArg(Str, ArgNum)
  1000. X    char                *Str;
  1001. X    int             ArgNum;
  1002. X{
  1003. X    register char            *p, *start;
  1004. X    register int         c;
  1005. X
  1006. X    for (c = 1, p = Str; p && *p; ++c) {
  1007. X    /* set start of word */
  1008. X    start = p; 
  1009. X
  1010. X    /* skip over word */
  1011. X    while (p && *p && *p != ' ' && *p != '\t' && *p != '\n')
  1012. X        ++p;
  1013. X
  1014. X    /* is this what we want? */
  1015. X    if (c == ArgNum) {
  1016. X        if (p) *p = C_NULL;
  1017. X        break;
  1018. X    }
  1019. X
  1020. X    /* skip white space */
  1021. X    while (*p == ' ' || *p == '\t')
  1022. X        ++p;
  1023. X    }
  1024. X
  1025. X    return(start);
  1026. X}
  1027. X
  1028. X/*
  1029. X * Convert integer to ASCII
  1030. X */
  1031. Xchar *itoa(Num)
  1032. X    int             Num;
  1033. X{
  1034. X    static char         Buf[BUFSIZ];
  1035. X
  1036. X    (void) sprintf(Buf, "%d", Num);
  1037. X
  1038. X    return(Buf);
  1039. X}
  1040. X
  1041. X/*
  1042. X * Get kernel version string
  1043. X */
  1044. Xextern char *GetKernelVersion()
  1045. X{
  1046. X    static char               *Ptr = NULL;
  1047. X    char               *GetKernelVersionStr();
  1048. X
  1049. X    /*
  1050. X     * See if we already know the answer
  1051. X     */
  1052. X    if (Ptr)
  1053. X    return(Ptr);
  1054. X
  1055. X    return(Ptr = GetKernelVersionStr());
  1056. X}
  1057. X
  1058. X#if    defined(HAVE_UNAME)
  1059. X/*
  1060. X * Get name of OS using uname()
  1061. X */
  1062. Xextern char *GetOSNameFromUname()
  1063. X{
  1064. X    static struct utsname     un;
  1065. X
  1066. X    if (uname(&un) != 0)
  1067. X    return((char *) NULL);
  1068. X    else
  1069. X    return(un.sysname);
  1070. X}
  1071. X#endif    /* HAVE_UNAME */
  1072. X
  1073. X/*
  1074. X * Get Operating System name.
  1075. X */
  1076. Xextern char *GetOSName()
  1077. X{
  1078. X#if    defined(OS_NAME)
  1079. X    return(OS_NAME);
  1080. X#else
  1081. X    return(GetOSNameStr());
  1082. X#endif    /* OS_NAME */
  1083. X}
  1084. X
  1085. X#if    defined(HAVE_UNAME)
  1086. X/*
  1087. X * Get OS version number using uname()
  1088. X */
  1089. Xextern char *GetOSVersionFromUname()
  1090. X{
  1091. X    static char            Buf[BUFSIZ];
  1092. X    struct utsname         un;
  1093. X
  1094. X    if (uname(&un) != 0) {
  1095. X    return((char *) NULL);
  1096. X    }
  1097. X
  1098. X    /*
  1099. X     * Vendors don't all do the same thing for storing
  1100. X     * version numbers via uname().
  1101. X     */
  1102. X#if    defined(UNAME_REL_VER_COMB)
  1103. X    (void) sprintf(Buf, "%s.%s", un.version, un.release);
  1104. X#else
  1105. X    (void) sprintf(Buf, "%s", un.release);
  1106. X#endif     /* UNAME_REL_VER_COMB */
  1107. X
  1108. X    return(Buf);
  1109. X}
  1110. X#endif    /* HAVE_UNAME */
  1111. X
  1112. X#if    defined(OSVERS_FROM_KERNVER)
  1113. X/*
  1114. X * Get OS version by reading an a specific argument out of
  1115. X * the kernel version string.
  1116. X */
  1117. Xextern char *GetOSVersionFromKernVer()
  1118. X{
  1119. X    static char            Buf[BUFSIZ];
  1120. X    register char           *p;
  1121. X
  1122. X    if (!(p = GetKernelVersion()))
  1123. X    return((char *) NULL);
  1124. X
  1125. X    (void) strcpy(Buf, p);
  1126. X    p = GetArg(Buf, OSVERS_FROM_KERNVER);
  1127. X    (void) strcpy(Buf, p);
  1128. X    if ((p = index(Buf, ':')) != NULL)
  1129. X    *p = C_NULL;
  1130. X
  1131. X    return(Buf);
  1132. X}
  1133. X#endif    /* OSVERS_FROM_KERNVER */
  1134. X
  1135. X/*
  1136. X * Get Operating System version
  1137. X */
  1138. Xextern char *GetOSVersion()
  1139. X{
  1140. X#if    defined(OS_VERSION)
  1141. X    return(OS_VERSION);
  1142. X#else
  1143. X    char                *Str;
  1144. X    char                *p;
  1145. X
  1146. X    if (!(Str = GetOSVersionStr()))
  1147. X    return(Str);
  1148. X
  1149. X    /*
  1150. X     * Zap "*-PL*".
  1151. X     */
  1152. X    if (*Str && 
  1153. X    ((p = rindex(Str, '-')) != NULL) && (strncmp(p, "-PL", 3) == 0))
  1154. X    *p = C_NULL;
  1155. X
  1156. X    return(Str);
  1157. X#endif    /* !OS_VERSION */
  1158. X}
  1159. X
  1160. X/*
  1161. X * Get our hostname
  1162. X */
  1163. Xextern char *GetHostName()
  1164. X{
  1165. X    static char         Buf[MAXHOSTNAMLEN+1];
  1166. X
  1167. X    gethostname(Buf, sizeof(Buf));
  1168. X
  1169. X    return((Buf[0]) ? Buf : (char *) NULL);
  1170. X}
  1171. X
  1172. X/*
  1173. X * Get aliases for this hostname
  1174. X */
  1175. Xextern char *GetHostAliases()
  1176. X{
  1177. X    static char         Buf[BUFSIZ];
  1178. X    struct hostent            *hp;
  1179. X    register char          **pp;
  1180. X    char                *HName;
  1181. X
  1182. X    if ((HName = GetHostName()) == NULL)
  1183. X    return((char *) NULL);
  1184. X
  1185. X    if ((hp = gethostbyname(HName)) == NULL) {
  1186. X    Error("Cannot find lookup host info for \"%s\": %s", HName, SYSERR);
  1187. X    return((char *) NULL);
  1188. X    }
  1189. X
  1190. X    for (pp = hp->h_aliases, Buf[0] = C_NULL; pp && *pp; ++pp) {
  1191. X    (void) strcat(Buf, *pp);
  1192. X    (void) strcat(Buf, " ");
  1193. X    }
  1194. X
  1195. X    return((Buf[0]) ? Buf : (char *) NULL);
  1196. X}
  1197. X
  1198. X/*
  1199. X * Get addresses for this host
  1200. X */
  1201. Xextern char *GetHostAddrs()
  1202. X{
  1203. X    static char         Buf[BUFSIZ];
  1204. X    struct hostent            *hp;
  1205. X    register char          **pp;
  1206. X    char                *HName;
  1207. X
  1208. X    if ((HName = GetHostName()) == NULL)
  1209. X    return((char *) NULL);
  1210. X
  1211. X    if ((hp = gethostbyname(HName)) == NULL) {
  1212. X    Error("Cannot find lookup host info for \"%s\": %s", HName, SYSERR);
  1213. X    return((char *) NULL);
  1214. X    }
  1215. X
  1216. X    for (pp = hp->h_addr_list, Buf[0] = C_NULL; pp && *pp; ++pp) {
  1217. X    if (hp->h_addrtype == AF_INET) {
  1218. X        (void) strcat(Buf, (char *) inet_ntoa(*(struct in_addr *)*pp));
  1219. X        (void) strcat(Buf, " ");
  1220. X    }
  1221. X    }
  1222. X
  1223. X    return((Buf[0]) ? Buf : (char *) NULL);
  1224. X}
  1225. X
  1226. X/*
  1227. X * Get system model
  1228. X */
  1229. Xextern char *GetModel()
  1230. X{
  1231. X    int             Len;
  1232. X    FILE                *fd;
  1233. X    char             Buf[BUFSIZ];
  1234. X    char               *GetModelName();
  1235. X#if    defined(MODEL_COMMAND)
  1236. X    extern char            *ModelCommand[];
  1237. X#endif    /* MODEL_COMMAND */
  1238. X
  1239. X    /*
  1240. X     * Use model file if it exists.
  1241. X     */
  1242. X    if ((fd = fopen(MODELFILE, "r")) != NULL) {
  1243. X    fgets(Buf, sizeof(Buf), fd);
  1244. X    Len = strlen(Buf);
  1245. X    if (Buf[Len-1] == '\n') 
  1246. X        Buf[Len-1] = C_NULL;
  1247. X    return(Buf);
  1248. X    }
  1249. X
  1250. X    /*
  1251. X     * If a command to get model name has been defined, try it.
  1252. X     */
  1253. X#if    defined(MODEL_COMMAND)
  1254. X    if (p = RunCmds(ModelCommand))
  1255. X    return(p);
  1256. X#endif    /* MODEL_COMMAND */
  1257. X
  1258. X    /*
  1259. X     * Use a method specific to this OS
  1260. X     */
  1261. X    return(GetModelName());
  1262. X}
  1263. X
  1264. X/*
  1265. X * Get the short manufacturer name
  1266. X */
  1267. Xstatic char *GetManShort()
  1268. X{
  1269. X    return(MAN_SHORT);
  1270. X}
  1271. X
  1272. X/*
  1273. X * Get the long manufacturer name
  1274. X */
  1275. Xstatic char *GetManLong()
  1276. X{
  1277. X    return(MAN_LONG);
  1278. X}
  1279. X
  1280. X/*
  1281. X * Get the manufacturer info.
  1282. X */
  1283. Xextern char *GetMan()
  1284. X{
  1285. X    char                *ms, *ml;
  1286. X    static char         Buf[BUFSIZ];
  1287. X
  1288. X    ms = GetManShort();
  1289. X    ml = GetManLong();
  1290. X
  1291. X    if (!Terse)
  1292. X    (void) sprintf(Buf, "%s (%s)", ms, ml);
  1293. X    else
  1294. X    (void) sprintf(Buf, "%s", ms);
  1295. X
  1296. X    return(Buf);
  1297. X}
  1298. X
  1299. X/*
  1300. X * Get application architecture.
  1301. X */
  1302. Xextern char *GetAppArch()
  1303. X{
  1304. X    char                *arch = NULL;
  1305. X
  1306. X#if    defined(ARCH_TYPE)
  1307. X    /*
  1308. X     * Use predefined name if present.
  1309. X     */
  1310. X    if (!arch)
  1311. X    return(ARCH_TYPE);
  1312. X#endif    /* ARCH_TYPE */
  1313. X
  1314. X#if    defined(HAVE_AARCHNAME)
  1315. X    /*
  1316. X     * Use OS specific method
  1317. X     */
  1318. X    if (arch = (char *) GetAppArchName())
  1319. X    return(arch);
  1320. X#endif    /* HAVE_AARCHNAME */
  1321. X
  1322. X    /*
  1323. X     * Try running App Arch commands
  1324. X     */
  1325. X    if (arch = RunCmds(AppArchCmds))
  1326. X    return(arch);
  1327. X
  1328. X    /*
  1329. X     * Try testing Architecture files
  1330. X     */
  1331. X    if (arch = RunTestFiles(ArchFiles))
  1332. X    return(arch);
  1333. X
  1334. X    return(arch);
  1335. X}
  1336. X
  1337. X/*
  1338. X * Get kernel architecture
  1339. X */
  1340. Xextern char *GetKernArch()
  1341. X{
  1342. X    char                *arch = NULL;
  1343. X
  1344. X#if    defined(KARCH_TYPE)
  1345. X    /*
  1346. X     * If there's a predefined KArch name, use it.
  1347. X     */
  1348. X    if (!arch)
  1349. X    return(KARCH_TYPE);
  1350. X#endif    /* KARCH_TYPE */
  1351. X
  1352. X#if    defined(HAVE_KARCHNAME)
  1353. X    /*
  1354. X     * Try OS specific method
  1355. X     */
  1356. X    if (arch = GetKernArchName())
  1357. X    return(arch);
  1358. X#endif    /* HAVE_KARCHNAME */
  1359. X
  1360. X    /*
  1361. X     * Try running the KArch test commands
  1362. X     */
  1363. X    if (arch = RunCmds(KernArchCmds))
  1364. X    return(arch);
  1365. X
  1366. X    /*
  1367. X     * We're desperate, so try using the Application Architecture
  1368. X     */
  1369. X    if (arch = GetAppArch())
  1370. X    return(arch);
  1371. X
  1372. X    return((char *) NULL);
  1373. X}
  1374. X
  1375. X/*
  1376. X * Get host ID
  1377. X */
  1378. Xextern char *GetHostID()
  1379. X{
  1380. X    static char         Buf[100];
  1381. X
  1382. X    (void) sprintf(Buf, "%08x", gethostid());
  1383. X
  1384. X    return(Buf);
  1385. X}
  1386. X
  1387. X/*
  1388. X * Get system serial number
  1389. X */
  1390. Xextern char *GetSerialNo()
  1391. X{
  1392. X    return(GetSerialNoStr());
  1393. X}
  1394. X
  1395. X/*
  1396. X * Get CPU type
  1397. X */
  1398. Xextern char *GetCPU()
  1399. X{
  1400. X    char                *cpu = NULL;
  1401. X
  1402. X#if    defined(CPU_NAME)
  1403. X    cpu = CPU_NAME;
  1404. X#else
  1405. X#if    defined(HAVE_HOST_INFO)
  1406. X    /*
  1407. X     * Try the Mach method.
  1408. X     * This should be in os-mach.c, but this is the only
  1409. X     * OS specific case so far.
  1410. X     */
  1411. X    cpu = (char *) GetCpuTypeFromHostInfo();
  1412. X#endif     /* HAVE_HOST_INFO */
  1413. X#endif     /* CPU_NAME */
  1414. X
  1415. X    if (!cpu) {
  1416. X    cpu = RunTestFiles(CPUFiles);
  1417. X
  1418. X    /*
  1419. X     * If that didn't work, try the architecture commands.
  1420. X     */
  1421. X    if (!cpu)
  1422. X        cpu = RunCmds(AppArchCmds);
  1423. X    }
  1424. X
  1425. X    return(cpu);
  1426. X}
  1427. X
  1428. X/*
  1429. X * Print error message
  1430. X */
  1431. X#if    defined(HAVE_VARARGS)
  1432. X#include <varargs.h>
  1433. X/*
  1434. X * Varargs version of Error()
  1435. X */
  1436. Xextern void Error(va_alist)
  1437. X    va_dcl
  1438. X{
  1439. X    va_list             args;
  1440. X    char                *fmt;
  1441. X    extern char            *ProgramName;
  1442. X
  1443. X    (void) fprintf(stderr, "%s: ", ProgramName);
  1444. X    va_start(args);
  1445. X    fmt = (char *) va_arg(args, char *);
  1446. X    (void) vfprintf(stderr, fmt, args);
  1447. X    va_end(args);
  1448. X    (void) fprintf(stderr, "\n");
  1449. X}
  1450. X#else
  1451. X/*
  1452. X * Non-Varargs version of Error()
  1453. X */
  1454. Xextern void Error(fmt, a1, a2, a3, a4, a5, a6)
  1455. X    char                *fmt;
  1456. X{
  1457. X    extern char            *ProgramName;
  1458. X
  1459. X    (void) fprintf(stderr, "%s: ", ProgramName);
  1460. X    (void) fprintf(stderr, fmt, a1, a2, a3, a4, a5, a6);
  1461. X    (void) fprintf(stderr, "\n");
  1462. X}
  1463. X#endif     /* !HAVE_VARARGS */
  1464. X
  1465. X/*
  1466. X * Parse and set the level keyword list
  1467. X */
  1468. Xstatic int ParseLevel(Str)
  1469. X    char               *Str;
  1470. X{
  1471. X    register int        i;
  1472. X    char               *Word;
  1473. X    int                Found;
  1474. X
  1475. X    /*
  1476. X     * Check each word in the LevelNames table
  1477. X     */
  1478. X    for (Word = strtok(Str, ","); Word; Word = strtok((char *)NULL, ",")) {
  1479. X    for (i = 0, Found = FALSE; LevelNames[i].name && !Found; i++) {
  1480. X        if (strncasecmp(Word, LevelNames[i].name, strlen(Word)) == 0) {
  1481. X        Level |= LevelNames[i].value;
  1482. X        Found = TRUE;
  1483. X        }
  1484. X    }
  1485. X    if (!Found) {
  1486. X        Error("The word \"%s\" is not a valid verbosity level.", Word);
  1487. X        return(-1);
  1488. X    }
  1489. X    }
  1490. X
  1491. X    return(0);
  1492. X}
  1493. X
  1494. X/*
  1495. X * Parse and set the showinfo items
  1496. X */
  1497. Xstatic int ParseShow(Str)
  1498. X    char               *Str;
  1499. X{
  1500. X    register int        x;
  1501. X    char               *Word;
  1502. X    int                Found;
  1503. X
  1504. X    /*
  1505. X     * Check each word.
  1506. X     */
  1507. X    for (Word = strtok(Str, ","); Word; Word = strtok((char *)NULL, ",")) {
  1508. X    /*
  1509. X     * Search the ShowInfo entries for a match.
  1510. X     */
  1511. X    for (x = 0, Found = FALSE; !Found && ShowInfo[x].Name; x++)
  1512. X        if (EQ(Word, ShowInfo[x].Name)) {
  1513. X        ShowInfo[x].Enable = TRUE;
  1514. X        DoPrintAll = FALSE;
  1515. X        Found = TRUE;
  1516. X        }
  1517. X
  1518. X    if (!Found) {
  1519. X        Error("The word \"%s\" is not valid.", Word);
  1520. X        ListShow();
  1521. X        return(-1);
  1522. X    }
  1523. X    }
  1524. X
  1525. X    return(0);
  1526. X}
  1527. X
  1528. X/*
  1529. X * Front end to calloc()
  1530. X */
  1531. Xchar *xcalloc(nele, esize)
  1532. X    int             nele;
  1533. X    int             esize;
  1534. X{
  1535. X    char                *p, *calloc();
  1536. X
  1537. X    if ((p = calloc(nele, esize)) == NULL) {
  1538. X    Error("calloc(%d, %d) failed.", nele, esize);
  1539. X    return((char *) NULL);
  1540. X    }
  1541. X
  1542. X    return(p);
  1543. X}
  1544. X
  1545. X#if    defined(OPTION_COMPAT)
  1546. X/*
  1547. X * Set option compatibility
  1548. X */
  1549. Xstatic void SetOptionCompat()
  1550. X{
  1551. X    register int        i;
  1552. X
  1553. X    /*
  1554. X     * For every OptCompat that's TRUE, enable the real value
  1555. X     */
  1556. X    for (i = 0; ShowInfo[i].Name; i++) 
  1557. X    if (ShowInfo[i].OptCompat && *ShowInfo[i].OptCompat) {
  1558. X        ShowInfo[i].Enable = TRUE;
  1559. X        /*
  1560. X         * These is also part of the old behavior
  1561. X         */
  1562. X        DoPrintAll = FALSE;
  1563. X        Terse = TRUE;
  1564. X    }
  1565. X
  1566. X}
  1567. X#endif    /* OPTION_COMPAT */
  1568. X
  1569. X/*
  1570. X * The beginning
  1571. X */
  1572. Xmain(Argc, Argv)
  1573. X    int             Argc;
  1574. X    char               **Argv;
  1575. X{
  1576. X    register int        i;
  1577. X
  1578. X    if (ParseOptions(Opts, Num_Opts(Opts), Argc, Argv) < 0) {
  1579. X        exit(1);
  1580. X    }
  1581. X
  1582. X    /*
  1583. X     * Show version info
  1584. X     */
  1585. X    if (DoPrintVersion) {
  1586. X    printf("Sysinfo version %s.%d\n", VERSION_STR, PATCHLEVEL);
  1587. X    exit(0);
  1588. X    }
  1589. X    /*
  1590. X     * Do any list commands and exit
  1591. X     */
  1592. X    if (ListStr) {
  1593. X    List(ListStr);
  1594. X    exit(0);
  1595. X    }
  1596. X
  1597. X#if    defined(OPTION_COMPAT)
  1598. X    SetOptionCompat();
  1599. X#endif
  1600. X
  1601. X    /*
  1602. X     * Set verbosity strings
  1603. X     */
  1604. X    if (LevelStr && ParseLevel(LevelStr))
  1605. X    exit(1);
  1606. X
  1607. X    if (ShowStr && ParseShow(ShowStr))
  1608. X    exit(1);
  1609. X
  1610. X    /*
  1611. X     * Run down the main topics
  1612. X     */
  1613. X    for (i = 0; ShowInfo[i].Name; i++) {
  1614. X    if (!(DoPrintAll || ShowInfo[i].Enable))
  1615. X        continue;
  1616. X
  1617. X    if (ShowInfo[i].ShowFunc) {
  1618. X        /*
  1619. X         * The item has a show function
  1620. X         */
  1621. X        (*ShowInfo[i].ShowFunc)(&ShowInfo[i], NULL);
  1622. X    } else {
  1623. X        register int    x;
  1624. X        int            Found;
  1625. X
  1626. X        /*
  1627. X         * Search for and call a search function for this type of item
  1628. X         */
  1629. X        for (x = 0, Found = FALSE; !Found && ShowInfo[x].Name; x++)
  1630. X        if ((ShowInfo[x].Type == ShowInfo[i].Type) &&
  1631. X            ShowInfo[x].ShowFunc) {
  1632. X            Found = TRUE;
  1633. X            (*ShowInfo[x].ShowFunc)(&ShowInfo[x], &ShowInfo[i]);
  1634. X        }
  1635. X        if (!Found) {
  1636. X        Error("No show function exists for \"%s\".", 
  1637. X              ShowInfo[i].Name);
  1638. X        exit(1);
  1639. X        }
  1640. X    }
  1641. X    }
  1642. X
  1643. X    exit(0);
  1644. X}
  1645. END_OF_sysinfo.c
  1646. if test 26266 -ne `wc -c <sysinfo.c`; then
  1647.     echo shar: \"sysinfo.c\" unpacked with wrong size!
  1648. fi
  1649. # end of overwriting check
  1650. fi
  1651. if test -f devices.c -a "${1}" != "-c" ; then 
  1652.   echo shar: Will not over-write existing file \"devices.c\"
  1653. else
  1654. echo shar: Extracting \"devices.c\" \(22686 characters\)
  1655. sed "s/^X//" >devices.c <<'END_OF_devices.c'
  1656. X/*
  1657. X * Copyright (c) 1992 Michael A. Cooper.
  1658. X * This software may be freely distributed provided it is not sold for 
  1659. X * profit and the author is credited appropriately.
  1660. X */
  1661. X
  1662. X#ifndef lint
  1663. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/devices.c,v 1.18 1992/04/26 23:32:06 mcooper Exp $";
  1664. X#endif
  1665. X
  1666. X/*
  1667. X * $Log: devices.c,v $
  1668. X * Revision 1.18  1992/04/26  23:32:06  mcooper
  1669. X * Add Copyright notice
  1670. X *
  1671. X * Revision 1.17  1992/04/17  01:07:59  mcooper
  1672. X * More de-linting
  1673. X *
  1674. X * Revision 1.16  1992/04/16  02:25:39  mcooper
  1675. X * Bug fixes, de-linting, and other changes found with CodeCenter.
  1676. X *
  1677. X * Revision 1.15  1992/04/15  02:41:37  mcooper
  1678. X * Change AddDevice() to check to make sure device doesn't already exist.
  1679. X *
  1680. X * Revision 1.14  1992/04/12  22:01:11  mcooper
  1681. X * Remove kludge for "id".
  1682. X *
  1683. X * Revision 1.12  1992/03/22  02:03:31  mcooper
  1684. X * Call BuildDevicesNeXT().
  1685. X *
  1686. X * Revision 1.11  1992/03/22  00:20:10  mcooper
  1687. X * Major cleanup and re-org.
  1688. X *
  1689. X * Revision 1.10  1992/03/09  01:25:24  mcooper
  1690. X * Print device description on first line if no other info is available.
  1691. X *
  1692. X * Revision 1.9  1992/03/08  04:57:36  mcooper
  1693. X * - Add support for multiple address per netif.
  1694. X * - Move probe_generic() here for os-sunos.c.
  1695. X *
  1696. X * Revision 1.8  1992/03/06  18:36:55  mcooper
  1697. X * Move some general functions here from sunos.c.
  1698. X *
  1699. X * Revision 1.7  1992/03/05  22:36:35  mcooper
  1700. X * Cleanup format.
  1701. X *
  1702. X * Revision 1.6  1992/03/01  21:30:37  mcooper
  1703. X * Use dd_secsize from DISKDRIVE instead of SECSIZE macro.
  1704. X *
  1705. X * Revision 1.5  1992/02/25  00:16:14  mcooper
  1706. X * - Major cleanup of printing.
  1707. X * - Init new device int's to -1.
  1708. X * - Add new device type's.
  1709. X *
  1710. X * Revision 1.4  1992/02/22  02:20:19  mcooper
  1711. X * Major changes to support scanning kernel mainbus and
  1712. X * openprom data for device's.
  1713. X *
  1714. X * Revision 1.3  1992/02/16  23:50:47  mcooper
  1715. X * Cleanup newline printing and add verbosity level checking.
  1716. X *
  1717. X * Revision 1.2  1992/02/16  22:46:03  mcooper
  1718. X * Add network interface support.
  1719. X *
  1720. X * Revision 1.1  1991/11/30  23:28:53  mcooper
  1721. X * Initial revision
  1722. X *
  1723. X */
  1724. X
  1725. X
  1726. X#include <stdio.h>
  1727. X#include "system.h"
  1728. X#include "defs.h"
  1729. X
  1730. X#define OFFSET 4
  1731. X
  1732. Xstatic void PrintDiskdrive();
  1733. Xstatic void PrintFrameBuffer();
  1734. Xstatic void PrintNetIf();
  1735. Xstatic void PrintDevice();
  1736. Xstatic void PrintGeneric();
  1737. X
  1738. Xstruct devicetype {
  1739. X    int                 dt_dtype;    /* Device type */
  1740. X    char            *dt_desc;    /* Description */
  1741. X    void               (*dt_prfunc)();    /* Print function */
  1742. X};
  1743. Xtypedef struct devicetype DEVTYPE;
  1744. X
  1745. XDEVTYPE DevTypes[] = {
  1746. X    { DT_GENERIC,    NULL,            PrintGeneric },
  1747. X    { DT_DISKDRIVE,    "disk drive",        PrintDiskdrive },
  1748. X    { DT_DISKCTLR,    "disk controller",    PrintGeneric },
  1749. X    { DT_TAPEDRIVE,    "tape drive",        PrintGeneric },
  1750. X    { DT_TAPECTLR,    "tape controller",    PrintGeneric },
  1751. X    { DT_FRAMEBUFFER,    "frame buffer",        PrintFrameBuffer },
  1752. X    { DT_NETIF,        "network interface",    PrintNetIf },
  1753. X    { DT_BUS,        "system bus",        PrintGeneric },
  1754. X    { DT_PSEUDO,    "pseudo device",    PrintGeneric },
  1755. X    { 0 },
  1756. X};
  1757. X
  1758. Xstatic float             TotalDisk = 0;
  1759. X
  1760. X/*
  1761. X * Get a device type.
  1762. X */
  1763. Xstatic DEVTYPE *GetDevType(Device)
  1764. X    DEVICE                *Device;
  1765. X{
  1766. X    register int         i;
  1767. X
  1768. X    if (!Device)
  1769. X    return((DEVTYPE *) NULL);
  1770. X
  1771. X    for (i = 0; DevTypes[i].dt_prfunc; ++i)
  1772. X    if (DevTypes[i].dt_dtype == Device->dv_type)
  1773. X        return(&DevTypes[i]);
  1774. X
  1775. X    return((DEVTYPE *) NULL);
  1776. X}
  1777. X
  1778. X/*
  1779. X * Print all device info
  1780. X */
  1781. Xextern void ShowDevices(MyInfo, SpecInfo)
  1782. X    SHOWINFO               *MyInfo;
  1783. X    SHOWINFO               *SpecInfo;    /* ARGSUSED */
  1784. X{
  1785. X    static DEVICE            *RootDev;
  1786. X
  1787. X#if    defined(sun)
  1788. X    if (BuildDevicesSunOS(&RootDev) != 0)
  1789. X    return;
  1790. X#endif    /* sun */
  1791. X
  1792. X#if    defined(ultrix)
  1793. X    if (BuildDevicesUltrix(&RootDev) != 0)
  1794. X    return;
  1795. X#endif    /* ultrix */
  1796. X
  1797. X#if    defined(NeXT)
  1798. X    if (BuildDevicesNeXT(&RootDev) != 0)
  1799. X    return;
  1800. X#endif    /* NeXT */
  1801. X
  1802. X    if (!RootDev) {
  1803. X    if (Debug)
  1804. X        printf("No devices were found.\n");
  1805. X    return;
  1806. X    }
  1807. X
  1808. X    printf("\n\n\t%s\n\n", MyInfo->Label);
  1809. X
  1810. X    TotalDisk = 0;
  1811. X
  1812. X    PrintDevice(RootDev, 0);
  1813. X
  1814. X    if (VL_DESC && TotalDisk > 0)
  1815. X    printf("\nTotal Disk Capacity is %.2f MB.\n", 
  1816. X           (float) bytes_to_mbytes(TotalDisk));
  1817. X}
  1818. X
  1819. X/*
  1820. X * --RECURSE--
  1821. X * Print info about a device.  Recursively calls itself for slaves and
  1822. X * next elements
  1823. X */
  1824. Xstatic void PrintDevice(Device, OffSet)
  1825. X    DEVICE                *Device;
  1826. X    int             OffSet;
  1827. X{
  1828. X    DEVTYPE                *DevType;
  1829. X
  1830. X    /*
  1831. X     * If device->dv_name is not set, this is the root of the device tree
  1832. X     */
  1833. X
  1834. X    if (Device->dv_name) {
  1835. X    if (DevType = GetDevType(Device))
  1836. X        (*DevType->dt_prfunc)(Device, DevType, OffSet);
  1837. X    else
  1838. X        PrintGeneric(Device, DevType, OffSet);
  1839. X    }
  1840. X
  1841. X    /*
  1842. X     * Descend
  1843. X     */
  1844. X    if (Device->dv_slaves)
  1845. X    PrintDevice(Device->dv_slaves, (Device->dv_name) ? OffSet+OFFSET : 0);
  1846. X
  1847. X    /*
  1848. X     * Traverse
  1849. X     */
  1850. X    if (Device->dv_nxt)
  1851. X    PrintDevice(Device->dv_nxt, (Device->dv_name) ? OffSet : 0);
  1852. X}
  1853. X
  1854. X/*
  1855. X * Print Off Set space
  1856. X */
  1857. Xstatic void PrOffSet(cnt)
  1858. X    int             cnt;
  1859. X{
  1860. X    printf("%*s", cnt, "");
  1861. X}
  1862. X
  1863. X/*
  1864. X * Print a device label
  1865. X */
  1866. Xstatic void PrDevLabel(Name, OffSet)
  1867. X    char                *Name;
  1868. X    int             OffSet;
  1869. X{
  1870. X    PrOffSet(OffSet);
  1871. X    if (VL_CONFIG)
  1872. X    printf("%*s%-18s:", OFFSET, "", Name);
  1873. X    else
  1874. X    printf("%*s%18s:", OFFSET, "", Name);
  1875. X}
  1876. X
  1877. X/*
  1878. X * Print general device information
  1879. X */
  1880. Xstatic void PrintDeviceInfo(Device, DevType, OffSet)
  1881. X    DEVICE                *Device;
  1882. X    DEVTYPE                *DevType;
  1883. X    int             OffSet;
  1884. X{     
  1885. X    DEVTYPE                *mdt;
  1886. X
  1887. X    if (!Device->dv_name)
  1888. X    return;
  1889. X
  1890. X    if (VL_CONFIG) printf("\n");
  1891. X    PrOffSet(OffSet);
  1892. X    printf("Device %s", Device->dv_name);
  1893. X
  1894. X    if (Device->dv_model || (DevType && DevType->dt_desc)) {
  1895. X    printf(" is a");
  1896. X    if (Device->dv_model)
  1897. X        printf(" \"%s\"", Device->dv_model);
  1898. X
  1899. X    if (DevType && DevType->dt_desc)
  1900. X        printf(" %s", DevType->dt_desc);
  1901. X    } else if (Device->dv_desc) {
  1902. X    printf(" is a");
  1903. X    printf(" %s", Device->dv_desc);
  1904. X    }
  1905. X
  1906. X    if (Device->dv_name)
  1907. X    printf(".\n");
  1908. X
  1909. X    if (VL_DESC || VL_CONFIG) {
  1910. X    if (Device->dv_desc) {
  1911. X        PrDevLabel("Description", OffSet);
  1912. X        printf(" %s\n", Device->dv_desc);
  1913. X    } else if ((mdt = GetDevType(Device)) && mdt && mdt->dt_desc) {
  1914. X        PrDevLabel("Description", OffSet);
  1915. X        printf(" %s\n", mdt->dt_desc);
  1916. X    }
  1917. X
  1918. X    if (Device->dv_master && Device->dv_master->dv_name) {
  1919. X        PrDevLabel("Description", OffSet);
  1920. X        if (Device->dv_master->dv_name)
  1921. X        printf(" Connected to %s", Device->dv_master->dv_name);
  1922. X        else if (Device->dv_master->dv_model) {
  1923. X        printf(" Connected to %s", Device->dv_master->dv_model);
  1924. X        if (mdt = GetDevType(Device->dv_master))
  1925. X            printf(" %s", mdt->dt_desc);
  1926. X        }
  1927. X        printf("\n");
  1928. X    }
  1929. X    }
  1930. X}
  1931. X
  1932. X/*
  1933. X * Print info about a generic device
  1934. X */
  1935. Xstatic void PrintGeneric(Device, DevType, OffSet)
  1936. X    DEVICE                *Device;
  1937. X    DEVTYPE                *DevType;
  1938. X    int             OffSet;
  1939. X{
  1940. X    register DEVICE            *pd;
  1941. X
  1942. X    PrintDeviceInfo(Device, DevType, OffSet);
  1943. X
  1944. X    if (VL_CONFIG) {
  1945. X    if (Device->dv_unit >= 0 || Device->dv_addr >= 0 || 
  1946. X        Device->dv_prio >= 0 || Device->dv_vec >= 0) {
  1947. X        PrDevLabel("Configuration", OffSet);
  1948. X        if (Device->dv_unit >= 0)
  1949. X        printf(" Unit %d", Device->dv_unit);
  1950. X        if (Device->dv_addr >= 0)
  1951. X        printf(" Address 0x%x", Device->dv_addr);
  1952. X        if (Device->dv_prio >= 0)
  1953. X        printf(" Priority %d", Device->dv_prio);
  1954. X        if (Device->dv_vec >= 0)
  1955. X        printf(" Vector %d", Device->dv_vec);
  1956. X        printf("\n");
  1957. X    }
  1958. X    }
  1959. X
  1960. X    if (VL_CONFIG) {
  1961. X    if (Device->dv_slaves && (Device->dv_name || Device->dv_model || 
  1962. X                  (DevType && DevType->dt_desc))) {
  1963. X        PrDevLabel("Attached Device(s)", OffSet);
  1964. X        for (pd = Device->dv_slaves; pd; pd = pd->dv_nxt)
  1965. X        printf(" %s", pd->dv_name);
  1966. X        printf("\n");
  1967. X    }
  1968. X    }
  1969. X}
  1970. X
  1971. X/*
  1972. X * Print info about disk partitioning.
  1973. X */
  1974. Xstatic void PrintDiskPart(Disk, OffSet)
  1975. X    DISKDRIVE                *Disk;
  1976. X    int             OffSet;
  1977. X{
  1978. X    register DISKPART            *pp;
  1979. X
  1980. X    printf("\n");
  1981. X    PrOffSet(OffSet);
  1982. X    printf("%50s\n", "Partition Information");
  1983. X
  1984. X    PrOffSet(OffSet);
  1985. X    printf("%20s %10s %10s %9s\n",
  1986. X       "", "START", "NUMBER OF", "SIZE");
  1987. X
  1988. X    PrOffSet(OffSet);
  1989. X    printf("%20s %10s %10s %9s %s\n",
  1990. X       "PART", "SECTOR", "SECTORS", "(MB)", "USAGE");
  1991. X
  1992. X    for (pp = Disk->dd_part; pp; pp = pp->dp_nxt) {
  1993. X    PrOffSet(OffSet);
  1994. X    printf("%20s %10d %10d %9.2f %s\n",
  1995. X           pp->dp_name,
  1996. X           pp->dp_stsect,
  1997. X           pp->dp_nsect,
  1998. X           bytes_to_mbytes(nsect_to_bytes(pp->dp_nsect, Disk->dd_secsize)),
  1999. X           (pp->dp_mnt) ? pp->dp_mnt : ""
  2000. X           );
  2001. X    }
  2002. X}
  2003. X
  2004. X/*
  2005. X * Print info about a disk device.
  2006. X */
  2007. Xstatic void PrintDiskdrive(Device, DevType, OffSet)
  2008. X    DEVICE                *Device;
  2009. X    DEVTYPE                *DevType;
  2010. X    int             OffSet;
  2011. X{
  2012. X    DISKDRIVE                *Disk;
  2013. X
  2014. X    PrintDeviceInfo(Device, DevType, OffSet);
  2015. X
  2016. X    if (!Device->dv_devspec)
  2017. X    return;
  2018. X
  2019. X    Disk = (DISKDRIVE *) Device->dv_devspec;
  2020. X
  2021. X    TotalDisk += (float) Disk->dd_size;
  2022. X
  2023. X    if (VL_CONFIG) {
  2024. X    PrDevLabel("Configuration", OffSet);
  2025. X    if (FLAGS_ON(Disk->dd_flags, DF_HEXUNIT))
  2026. X        printf(" Unit %3.3x", Disk->dd_unit);
  2027. X    else
  2028. X        printf(" Unit %3d", Disk->dd_unit);
  2029. X
  2030. X    printf("  Slave %2d  RPM %d  APC %d  Interleave %d\n", 
  2031. X           Disk->dd_slave, Disk->dd_rpm, Disk->dd_apc, Disk->dd_intrlv);
  2032. X
  2033. X    PrDevLabel("Configuration", OffSet);
  2034. X    printf(" %4d Physical Cylinders  %2d Alternate Cylinders\n", 
  2035. X           Disk->dd_pcyl, Disk->dd_acyl);
  2036. X
  2037. X    PrDevLabel("Geometry", OffSet);
  2038. X    printf(" %4d Data Cylinders      %2d Heads  %3d Sectors/Track\n",
  2039. X           Disk->dd_dcyl, Disk->dd_heads, Disk->dd_sect);
  2040. X
  2041. X    if (Disk->dd_psect || Disk->dd_promrev) {
  2042. X        PrDevLabel("Hardware Info", OffSet);
  2043. X        printf(" %4d Hard Sectors  PROM Revision %d\n",
  2044. X           Disk->dd_psect, Disk->dd_promrev);
  2045. X    }
  2046. X    }
  2047. X
  2048. X    if (VL_ALL && Disk->dd_part)
  2049. X    PrintDiskPart(Disk, OffSet);
  2050. X}
  2051. X
  2052. X/*
  2053. X * Print info about a frame buffer.
  2054. X */
  2055. Xstatic void PrintFrameBuffer(Device, DevType, OffSet)
  2056. X    DEVICE                *Device;
  2057. X    DEVTYPE                *DevType;
  2058. X    int             OffSet;
  2059. X{
  2060. X    FRAMEBUFFER            *fb;
  2061. X
  2062. X    PrintDeviceInfo(Device, DevType, OffSet);
  2063. X
  2064. X    if (!Device->dv_devspec)
  2065. X    return;
  2066. X
  2067. X    fb = (FRAMEBUFFER *) Device->dv_devspec;
  2068. X
  2069. X    if (VL_CONFIG) {
  2070. X    PrDevLabel("Screen Size", OffSet);
  2071. X    printf(" %d KB  Height %d  Width %d  Depth %d-bit%s\n",
  2072. X           bytes_to_kbytes(fb->fb_size),
  2073. X           fb->fb_height, fb->fb_width, fb->fb_depth,
  2074. X           (fb->fb_depth == 1) ? "" : "s");
  2075. X
  2076. X    if (fb->fb_vmsize || fb->fb_cmsize) {
  2077. X        PrDevLabel("Configuration", OffSet);
  2078. X        if (fb->fb_vmsize)
  2079. X        printf(" Video Memory %d KB ", bytes_to_kbytes(fb->fb_vmsize));
  2080. X        if (fb->fb_cmsize)
  2081. X        printf(" Color Map Size is %d", fb->fb_cmsize);
  2082. X        printf("\n");
  2083. X    }
  2084. X    }
  2085. X}
  2086. X
  2087. X/*
  2088. X * Print info about a network interface
  2089. X */
  2090. Xstatic void PrintNetIf(Device, DevType, OffSet)
  2091. X    DEVICE                *Device;
  2092. X    DEVTYPE                *DevType;
  2093. X    int             OffSet;
  2094. X{
  2095. X    register NETIF           *ni;
  2096. X
  2097. X    PrintDeviceInfo(Device, DevType, OffSet);
  2098. X
  2099. X    if (!Device->dv_devspec)
  2100. X    return;
  2101. X
  2102. X    if (VL_CONFIG) {
  2103. X    for (ni = (NETIF *) Device->dv_devspec; ni; ni = ni->ni_nxt) {
  2104. X        if (ni->ni_typename) {
  2105. X        printf("\n");
  2106. X        PrDevLabel("Address Type", OffSet);
  2107. X        printf(" %s\n", ni->ni_typename);
  2108. X        }
  2109. X
  2110. X        if (ni->ni_hostaddr) {
  2111. X        PrDevLabel("Host Address", OffSet);
  2112. X        printf(" %-18s [%s]\n", ni->ni_hostaddr,
  2113. X               (ni->ni_hostname) ? ni->ni_hostname : "<unknown>");
  2114. X        }
  2115. X
  2116. X        if (ni->ni_netaddr) {
  2117. X        PrDevLabel("Network Address", OffSet);
  2118. X        printf(" %-18s [%s]\n", ni->ni_netaddr, 
  2119. X               (ni->ni_netname) ? ni->ni_netname : "<unknown>");
  2120. X        }
  2121. X
  2122. X        if (ni->ni_macaddr) {
  2123. X        PrDevLabel("MAC Address", OffSet);
  2124. X        printf(" %-18s [%s]\n", ni->ni_macaddr,
  2125. X               (ni->ni_macname && ni->ni_macname[0]) 
  2126. X               ? ni->ni_macname : "<unknown>");
  2127. X        }
  2128. X    }
  2129. X    }
  2130. X}
  2131. X
  2132. X/*
  2133. X * --RECURSE--
  2134. X * Create a new DEVICE and optionally copy an old DEVICE.
  2135. X */
  2136. Xextern DEVICE *NewDevice(Old)
  2137. X    DEVICE                *Old;
  2138. X{
  2139. X    register DEVICE            *SlavePtr, *Slave;
  2140. X    DEVICE                *New = NULL;
  2141. X
  2142. X    New = (DEVICE *) xcalloc(1, sizeof(DEVICE));
  2143. X
  2144. X    /* Set int's to -1 */
  2145. X    New->dv_type = New->dv_unit = New->dv_addr = New->dv_prio = 
  2146. X    New->dv_vec = -1;
  2147. X
  2148. X    if (!Old)
  2149. X    return(New);
  2150. X
  2151. X    /* Bulk copy what we can */
  2152. X    bcopy((char *) Old, (char *) New, sizeof(DEVICE));
  2153. X
  2154. X    New->dv_nxt = NULL;
  2155. X
  2156. X    /* Copy contents of pointers */
  2157. X    if (Old->dv_name)    New->dv_name = strdup(Old->dv_name);
  2158. X    if (Old->dv_model)    New->dv_model = strdup(Old->dv_model);
  2159. X    if (Old->dv_desc)    New->dv_desc = strdup(Old->dv_desc);
  2160. X
  2161. X    /* Copy Slave info */
  2162. X    for (Slave = Old->dv_slaves; Slave; Slave = Slave->dv_nxt) {
  2163. X    /* Find last slave */
  2164. X    for (SlavePtr = New->dv_slaves; SlavePtr && SlavePtr->dv_nxt; 
  2165. X         SlavePtr = SlavePtr->dv_nxt);
  2166. X    /* Copy Old slave to last new slave device */
  2167. X    SlavePtr = NewDevice(Slave);
  2168. X    }
  2169. X
  2170. X    return(New);
  2171. X}
  2172. X
  2173. X/*
  2174. X * Create a new DISKPART and optionally copy an old DISKPART.
  2175. X */
  2176. Xextern DISKPART *NewDiskPart(Old)
  2177. X    DISKPART                *Old;
  2178. X{
  2179. X    DISKPART                *New = NULL;
  2180. X
  2181. X    New = (DISKPART *) xcalloc(1, sizeof(DISKPART));
  2182. X
  2183. X    if (!Old)
  2184. X    return(New);
  2185. X
  2186. X    /* Bulk copy what we can */
  2187. X    bcopy((char *) Old, (char *) New, sizeof(DISKPART));
  2188. X
  2189. X    New->dp_nxt = NULL;
  2190. X
  2191. X    /* Copy contents of pointers */
  2192. X    if (Old->dp_name)    New->dp_name = strdup(Old->dp_name);
  2193. X    if (Old->dp_mnt)    New->dp_mnt = strdup(Old->dp_mnt);
  2194. X
  2195. X    return(New);
  2196. X}
  2197. X
  2198. X/*
  2199. X * --RECURSE--
  2200. X * Create a new DISKDRIVE and optionally copy an old DISKDRIVE.
  2201. X */
  2202. Xextern DISKDRIVE *NewDiskDrive(Old)
  2203. X    DISKDRIVE                *Old;
  2204. X{
  2205. X    register DISKPART            *dp, *pdp;
  2206. X    DISKDRIVE                *New = NULL;
  2207. X
  2208. X    New = (DISKDRIVE *) xcalloc(1, sizeof(DISKDRIVE));
  2209. X
  2210. X    if (!Old)
  2211. X    return(New);
  2212. X
  2213. X    /* Bulk copy what we can */
  2214. X    bcopy((char *) Old, (char *) New, sizeof(DISKDRIVE));
  2215. X
  2216. X    New->dd_nxt = NULL;
  2217. X
  2218. X    /* Copy contents of pointers */
  2219. X    if (Old->dd_label)    New->dd_label = strdup(Old->dd_label);
  2220. X    if (Old->dd_ctlr)     New->dd_ctlr = NewDevice(Old->dd_ctlr);
  2221. X
  2222. X    /* Copy partition info */
  2223. X    for (dp = Old->dd_part; dp; dp = dp->dp_nxt) {
  2224. X    /* Find last DISKPART */
  2225. X    for (pdp = New->dd_part; pdp && pdp->dp_nxt; pdp = pdp->dp_nxt);
  2226. X    /* Copy old DISKPART to last New DISKPART */
  2227. X    pdp = NewDiskPart(dp);
  2228. X    }
  2229. X
  2230. X    return(New);
  2231. X}
  2232. X
  2233. X/*
  2234. X * Create a new FRAMEBUFFER and optionally copy an old FRAMEBUFFER.
  2235. X */
  2236. Xextern FRAMEBUFFER *NewFrameBuffer(Old)
  2237. X    FRAMEBUFFER            *Old;
  2238. X{
  2239. X    FRAMEBUFFER            *New = NULL;
  2240. X
  2241. X    New = (FRAMEBUFFER *) xcalloc(1, sizeof(FRAMEBUFFER));
  2242. X
  2243. X    if (!Old)
  2244. X    return(New);
  2245. X
  2246. X    /* Bulk copy what we can */
  2247. X    bcopy((char *) Old, (char *) New, sizeof(FRAMEBUFFER));
  2248. X
  2249. X    return(New);
  2250. X}
  2251. X
  2252. X/*
  2253. X * Create a new NETIF and optionally copy an old NETIF.
  2254. X */
  2255. Xextern NETIF *NewNetif(Old)
  2256. X    NETIF                *Old;
  2257. X{
  2258. X    NETIF                *New = NULL;
  2259. X
  2260. X    New = (NETIF *) xcalloc(1, sizeof(NETIF));
  2261. X
  2262. X    if (!Old)
  2263. X    return(New);
  2264. X
  2265. X    /* Copy */
  2266. X    New->ni_hostaddr = strdup(Old->ni_hostaddr);
  2267. X    New->ni_hostname = strdup(Old->ni_hostname);
  2268. X    New->ni_macaddr = strdup(Old->ni_macaddr);
  2269. X    New->ni_macname = strdup(Old->ni_macname);
  2270. X    New->ni_netaddr = strdup(Old->ni_netaddr);
  2271. X    New->ni_netname = strdup(Old->ni_netname);
  2272. X
  2273. X    return(New);
  2274. X}
  2275. X
  2276. X/*
  2277. X * --RECURSE--
  2278. X * Find device named "name" in tree "treeptr".
  2279. X * This function recursively calls itself looking for 
  2280. X * the device "name".
  2281. X */
  2282. Xextern DEVICE *FindDeviceByName(Name, TreePtr)
  2283. X    char                *Name;
  2284. X    DEVICE                *TreePtr;
  2285. X{
  2286. X    DEVICE                *Ptr;
  2287. X
  2288. X    if (!Name || !TreePtr)
  2289. X    return((DEVICE *) NULL);
  2290. X
  2291. X    if (TreePtr->dv_name && Name && EQ(TreePtr->dv_name, Name))
  2292. X    return(TreePtr);
  2293. X
  2294. X    if (TreePtr->dv_slaves)
  2295. X    if (Ptr = FindDeviceByName(Name, TreePtr->dv_slaves))
  2296. X        return(Ptr);
  2297. X
  2298. X    if (TreePtr->dv_nxt)
  2299. X    if (Ptr = FindDeviceByName(Name, TreePtr->dv_nxt))
  2300. X        return(Ptr);
  2301. X
  2302. X    return((DEVICE *) NULL);
  2303. X}
  2304. X
  2305. X/*
  2306. X * Check to see if device's dev1 and dev2 are consistant.
  2307. X * If there is a discrepancy between the two due to one
  2308. X * device not having it's value set, then set it to the
  2309. X * other device's value.  Basically this "fills in the blanks".
  2310. X */
  2311. Xstatic void CheckDevice(Dev1, Dev2)
  2312. X     DEVICE                *Dev1;
  2313. X     DEVICE                *Dev2;
  2314. X{
  2315. X#define CHECK(a,b) \
  2316. X    if (a != b) { \
  2317. X    if (a) \
  2318. X        b = a; \
  2319. X    else if (b) \
  2320. X        a = b; \
  2321. X    }
  2322. X
  2323. X    CHECK(Dev1->dv_type,     Dev2->dv_type);
  2324. X    CHECK(Dev1->dv_model,     Dev2->dv_model);
  2325. X    CHECK(Dev1->dv_desc,     Dev2->dv_desc);
  2326. X    CHECK(Dev1->dv_unit,     Dev2->dv_unit);
  2327. X    CHECK(Dev1->dv_addr,     Dev2->dv_addr);
  2328. X    CHECK(Dev1->dv_prio,     Dev2->dv_prio);
  2329. X    CHECK(Dev1->dv_vec,     Dev2->dv_vec);
  2330. X    CHECK(Dev1->dv_devspec,     Dev2->dv_devspec);
  2331. X    CHECK(Dev1->dv_master,     Dev2->dv_master);
  2332. X
  2333. X#undef CHECK
  2334. X}
  2335. X
  2336. X/*
  2337. X * --RECURSE--
  2338. X * Add a device to a device list.
  2339. X */
  2340. Xextern int AddDevice(Device, TreePtr)
  2341. X    DEVICE                *Device;
  2342. X    DEVICE               **TreePtr;
  2343. X{
  2344. X    register DEVICE            *master = NULL, *mp = NULL;
  2345. X
  2346. X    if (!Device || !TreePtr) {
  2347. X    Error("Invalid parameter passed to AddDevice()");
  2348. X    return(-1);
  2349. X    }
  2350. X
  2351. X    /*
  2352. X     * Make sure device hasn't already been added
  2353. X     */
  2354. X    if (FindDeviceByName(Device->dv_name, *TreePtr)) {
  2355. X    if (Debug) 
  2356. X        printf("AddDevice: Device '%s' already exists; master = '%s'\n",
  2357. X           Device->dv_name, (master) ? master->dv_name : "?");
  2358. X    return(-1);
  2359. X    }
  2360. X
  2361. X    if (Device->dv_name)
  2362. X    Device->dv_name = strdup(Device->dv_name);
  2363. X
  2364. X    /*
  2365. X     * If the device has a master, find the master device.
  2366. X     * If one doesn't exist in the tree, then add it by recursively
  2367. X     * calling this function.
  2368. X     */
  2369. X    if (Device->dv_master) {
  2370. X    if (*TreePtr) {
  2371. X        master = FindDeviceByName(Device->dv_master->dv_name, *TreePtr);
  2372. X        if (master && EQ(master->dv_name, Device->dv_master->dv_name))
  2373. X        /* Check and fix any differences in info between master's */
  2374. X        CheckDevice(master, Device->dv_master);
  2375. X    } else
  2376. X        master = NULL;
  2377. X    if (!master) {
  2378. X        if (AddDevice(Device->dv_master, TreePtr) != 0) {
  2379. X        Error("Cannot add master '%s' to device tree.", 
  2380. X              master->dv_name);
  2381. X        return(-1);
  2382. X        }
  2383. X        master = Device->dv_master;
  2384. X    }
  2385. X    } else {
  2386. X    if (!*TreePtr)
  2387. X        *TreePtr = NewDevice((DEVICE *)NULL);
  2388. X    master = *TreePtr;
  2389. X    }
  2390. X
  2391. X    if (master->dv_name)
  2392. X    master->dv_name = strdup(master->dv_name);
  2393. X
  2394. X    if (master->dv_slaves) {
  2395. X    /* Add to existing list of slaves */
  2396. X    for (mp = master->dv_slaves; mp && mp->dv_nxt; mp = mp->dv_nxt);
  2397. X    mp->dv_nxt = Device;
  2398. X    } else
  2399. X    /* Create first slave */
  2400. X    master->dv_slaves = Device;
  2401. X
  2402. X    return(0);
  2403. X}
  2404. X
  2405. X/*
  2406. X * Get device data tab entry for "name"
  2407. X */
  2408. Xextern DEVDATATAB *GetDevDataTab(Name)
  2409. X    char                *Name;
  2410. X{
  2411. X    extern DEVDATATAB          DevDataTab[];
  2412. X    register int         i;
  2413. X
  2414. X    for (i = 0; DevDataTab[i].ddt_name; ++i) {
  2415. X    if (EQN(Name, DevDataTab[i].ddt_name, 
  2416. X        strlen(DevDataTab[i].ddt_name))) {
  2417. X        return(&DevDataTab[i]);
  2418. X    }
  2419. X    }
  2420. X
  2421. X    return((DEVDATATAB *) NULL);
  2422. X}
  2423. X
  2424. X/*
  2425. X * Create a device entry for a generic device
  2426. X */
  2427. Xextern DEVICE *ProbeGeneric(Name, DevData, DevDataTab)
  2428. X     /*ARGSUSED*/
  2429. X    char                *Name;
  2430. X    DEVDATA                *DevData;
  2431. X    DEVDATATAB                *DevDataTab;
  2432. X{
  2433. X    DEVICE               *Device;
  2434. X
  2435. X    /*
  2436. X     * DT_GENERIC devices MUST be marked alive to proceed
  2437. X     */
  2438. X    if (DevDataTab->ddt_type == DT_GENERIC && 
  2439. X    !(FLAGS_ON(DevData->dd_flags, DD_IS_ALIVE) ||
  2440. X      FLAGS_ON(DevData->dd_flags, DD_MAYBE_ALIVE)))
  2441. X    return((DEVICE *) NULL);
  2442. X
  2443. X    Device = NewDevice((DEVICE *) NULL);
  2444. X    if (Name)
  2445. X    Device->dv_name = strdup(Name);
  2446. X    else
  2447. X    Device->dv_name = strdup(MkDevName(DevData->dd_devname, 
  2448. X                       DevData->dd_devunit,
  2449. X                       DevDataTab->ddt_type));
  2450. X    Device->dv_type = DevDataTab->ddt_type;
  2451. X    Device->dv_model = DevDataTab->ddt_model;
  2452. X    Device->dv_desc = DevDataTab->ddt_desc;
  2453. X    Device->dv_unit = DevData->dd_devunit;
  2454. X    Device->dv_master = MkMasterFromDevData(DevData);
  2455. X
  2456. X    return(Device);
  2457. X}
  2458. X
  2459. X/*
  2460. X * Search for and call an appropriate probe function for this 
  2461. X * device
  2462. X */
  2463. Xextern DEVICE *ProbeDevice(DevData, TreePtr)
  2464. X    DEVDATA                *DevData;
  2465. X    DEVICE               **TreePtr;
  2466. X{
  2467. X    register DEVDATATAB        *pddt;
  2468. X    register char            *Name;
  2469. X    DEVICE                *ProbeUnknown();
  2470. X
  2471. X    if (pddt = GetDevDataTab(DevData->dd_devname)) {
  2472. X    Name = MkDevName(DevData->dd_devname, DevData->dd_devunit,
  2473. X             pddt->ddt_type);
  2474. X    if (FindDeviceByName(Name, *TreePtr)) {
  2475. X        if (Debug) printf("Device %s already exists.\n", Name);
  2476. X        return((DEVICE *) NULL);
  2477. X    }
  2478. X    return((*pddt->ddt_probe)(Name, DevData, pddt));
  2479. X    }
  2480. X
  2481. X    /*
  2482. X     * The device is unknown to us.  If it's definetly alive,
  2483. X     * return a minimal device entry for it.  If it's not alive,
  2484. X     * ignore it.
  2485. X     */
  2486. X    if (DoPrintUnknown && DevData->dd_devname && 
  2487. X    FLAGS_ON(DevData->dd_flags, DD_IS_ALIVE))
  2488. X    return(ProbeUnknown(Name, DevData));
  2489. X
  2490. X    if (Debug)
  2491. X    printf("Device `%s' is not defined.\n", DevData->dd_devname);
  2492. X
  2493. X    return((DEVICE *) NULL);
  2494. X}
  2495. X
  2496. X
  2497. X/*
  2498. X * Make a master device from a DevData controller
  2499. X */
  2500. Xextern DEVICE *MkMasterFromDevData(DevData)
  2501. X    DEVDATA                *DevData;
  2502. X{
  2503. X    register DEVICE            *Device = NULL;
  2504. X    register DEVDATATAB        *ddt;
  2505. X    int             type = 0;
  2506. X
  2507. X    if (DevData->dd_ctlrname) {
  2508. X    Device = NewDevice(NULL);
  2509. X    if (ddt = GetDevDataTab(DevData->dd_ctlrname)) {
  2510. X        type = ddt->ddt_type;
  2511. X        Device->dv_desc = ddt->ddt_desc;
  2512. X        Device->dv_model = ddt->ddt_model;
  2513. X    }
  2514. X    Device->dv_name = MkDevName(DevData->dd_ctlrname,
  2515. X                    DevData->dd_ctlrunit, 
  2516. X                    type);
  2517. X    }
  2518. X
  2519. X    return(Device);
  2520. X}
  2521. X
  2522. X/*
  2523. X * Make the file name of the raw device
  2524. X */
  2525. Xextern char *GetRawFile(Name, Part)
  2526. X    char                *Name;
  2527. X    char                *Part;
  2528. X{
  2529. X    static char         rfile[BUFSIZ];
  2530. X
  2531. X    if (!Name)
  2532. X    return((char *) NULL);
  2533. X
  2534. X    (void) sprintf(rfile, "/dev/r%s%s", Name, (Part) ? Part : "");
  2535. X
  2536. X    return(rfile);
  2537. X}
  2538. X
  2539. X/*
  2540. X * Make the file name of the character device
  2541. X */
  2542. Xextern char *GetCharFile(Name, Part)
  2543. X    char                *Name;
  2544. X    char                *Part;
  2545. X{
  2546. X    static char         file[BUFSIZ];
  2547. X
  2548. X    if (!Name)
  2549. X    return((char *) NULL);
  2550. X
  2551. X    (void) sprintf(file, "/dev/%s%s", Name, (Part) ? Part : "");
  2552. X
  2553. X    return(file);
  2554. X}
  2555. X
  2556. X/*
  2557. X * Make device name
  2558. X */
  2559. Xextern char *MkDevName(Name, Unit, Type)
  2560. X    char                *Name;
  2561. X    int             Unit;
  2562. X    int             Type;
  2563. X{
  2564. X    static char            Buf[BUFSIZ];
  2565. X
  2566. X    /*
  2567. X     * Don't attach unit number if this is a pseudo device.
  2568. X     */
  2569. X    if (Type == DT_PSEUDO)
  2570. X    sprintf(Buf, "%s", Name);
  2571. X    else
  2572. X    sprintf(Buf, "%s%d", Name, Unit);
  2573. X
  2574. X    return(strdup(Buf));
  2575. X}
  2576. X
  2577. X/*
  2578. X * Create a minimal device type for an unknown device.
  2579. X */
  2580. Xextern DEVICE *ProbeUnknown(Name, DevData)
  2581. X     /*ARGSUSED*/
  2582. X    char                *Name;
  2583. X    DEVDATA                *DevData;
  2584. X{
  2585. X    DEVICE               *Device;
  2586. X
  2587. X    Device = NewDevice((DEVICE *) NULL);
  2588. X    Device->dv_name = strdup(MkDevName(DevData->dd_devname, 
  2589. X                       DevData->dd_devunit,
  2590. X                       -1));
  2591. X    Device->dv_type = DT_GENERIC;
  2592. X    Device->dv_desc = "unknown device type";
  2593. X    Device->dv_unit = DevData->dd_devunit;
  2594. X    Device->dv_master = MkMasterFromDevData(DevData);
  2595. X
  2596. X    return(Device);
  2597. X}
  2598. END_OF_devices.c
  2599. if test 22686 -ne `wc -c <devices.c`; then
  2600.     echo shar: \"devices.c\" unpacked with wrong size!
  2601. fi
  2602. # end of overwriting check
  2603. fi
  2604. if test -f memory.c -a "${1}" != "-c" ; then 
  2605.   echo shar: Will not over-write existing file \"memory.c\"
  2606. else
  2607. echo shar: Extracting \"memory.c\" \(2645 characters\)
  2608. sed "s/^X//" >memory.c <<'END_OF_memory.c'
  2609. X/*
  2610. X * Copyright (c) 1992 Michael A. Cooper.
  2611. X * This software may be freely distributed provided it is not sold for 
  2612. X * profit and the author is credited appropriately.
  2613. X */
  2614. X
  2615. X#ifndef lint
  2616. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/memory.c,v 1.9 1992/04/26 23:32:06 mcooper Exp $";
  2617. X#endif
  2618. X
  2619. X/*
  2620. X * $Log: memory.c,v $
  2621. X * Revision 1.9  1992/04/26  23:32:06  mcooper
  2622. X * Add Copyright notice
  2623. X *
  2624. X * Revision 1.8  1992/04/17  01:07:59  mcooper
  2625. X * More de-linting
  2626. X *
  2627. X * Revision 1.7  1992/04/16  02:25:39  mcooper
  2628. X * Bug fixes, de-linting, and other changes found with CodeCenter.
  2629. X *
  2630. X * Revision 1.6  1992/03/31  02:35:53  mcooper
  2631. X * Change "nl" to "PhysmemNL".
  2632. X *
  2633. X * Revision 1.5  1992/03/31  01:55:17  mcooper
  2634. X * Use new CheckNlist to check nlist success.
  2635. X *
  2636. X * Revision 1.4  1992/03/31  00:22:54  mcooper
  2637. X * Add ctob() comment.
  2638. X *
  2639. X * Revision 1.3  1992/03/31  00:15:09  mcooper
  2640. X * Add error check for nlist.n_type.
  2641. X *
  2642. X * Revision 1.2  1992/03/28  23:13:07  mcooper
  2643. X * Don't set memory if == 0.
  2644. X *
  2645. X * Revision 1.1  1992/03/22  00:20:10  mcooper
  2646. X * Initial revision
  2647. X *
  2648. X */
  2649. X
  2650. X
  2651. X/*
  2652. X * Memory related functions.
  2653. X */
  2654. X
  2655. X#include <stdio.h>
  2656. X#include "system.h"
  2657. X#include "defs.h"
  2658. X
  2659. X/*
  2660. X * Divide and Round Up
  2661. X */
  2662. Xstatic int DivRndUp(Num, Div)
  2663. X    unsigned long         Num;
  2664. X    unsigned long         Div;
  2665. X{
  2666. X    int             i;
  2667. X
  2668. X    i = Num / Div;
  2669. X
  2670. X    return((Num % Div) ? i+1 : i);
  2671. X}
  2672. X
  2673. X#if    defined(HAVE_KVM) && defined(HAVE_NLIST)
  2674. X
  2675. X#include <fcntl.h>
  2676. X#include <nlist.h>
  2677. X
  2678. Xstatic struct nlist PhysmemNL[] = {
  2679. X#if         defined(COFF)
  2680. X    { "physmem" },
  2681. X#else
  2682. X    { "_physmem" },
  2683. X#endif        /* COFF */
  2684. X    { 0 },
  2685. X};
  2686. X
  2687. X/*
  2688. X * Common method of determining amount of physical memory in a
  2689. X * BSD Unix machine.
  2690. X *
  2691. X * Get memory by reading the variable "physmem" from the kernel
  2692. X * and the system page size.
  2693. X */ 
  2694. Xextern char *GetMemoryFromPhysmem()
  2695. X{
  2696. X    static char         Buf[BUFSIZ];
  2697. X    unsigned long         NPages, Bytes;
  2698. X    int                 Amount = -1;
  2699. X    kvm_t               *kd;
  2700. X
  2701. X    if (kd = KVM_open(PhysmemNL)) {
  2702. X    /*
  2703. X     * See if we got a valid entry
  2704. X     */
  2705. X    if (CheckNlist(&PhysmemNL[0]))
  2706. X        return((char *) NULL);
  2707. X
  2708. X    if (KVM_read(kd, PhysmemNL[0].n_value, (char *)&NPages,
  2709. X             sizeof(NPages)) >= 0) {
  2710. X        /*
  2711. X         * Could use ctob() instead of "Page Size * Num Pages",
  2712. X         * but this is more portable.
  2713. X         */
  2714. X        Bytes = (long) (getpagesize() * NPages);
  2715. X        if (Debug)
  2716. X        printf("Bytes = %d NPages = %d pagesize = %d\n", 
  2717. X               Bytes, NPages, getpagesize());
  2718. X        Amount = DivRndUp(Bytes, MBYTES);
  2719. X    }
  2720. X    }
  2721. X
  2722. X    if (kd)
  2723. X    KVM_close(kd);
  2724. X
  2725. X    if (Amount > 0) {
  2726. X    (void) sprintf(Buf, "%d MB", Amount);
  2727. X    return(Buf);
  2728. X    } else
  2729. X    return((char *) NULL);
  2730. X}
  2731. X#endif    /* HAVE_KVM && HAVE_NLIST */
  2732. END_OF_memory.c
  2733. if test 2645 -ne `wc -c <memory.c`; then
  2734.     echo shar: \"memory.c\" unpacked with wrong size!
  2735. fi
  2736. # end of overwriting check
  2737. fi
  2738. if test -f kernel.c -a "${1}" != "-c" ; then 
  2739.   echo shar: Will not over-write existing file \"kernel.c\"
  2740. else
  2741. echo shar: Extracting \"kernel.c\" \(2262 characters\)
  2742. sed "s/^X//" >kernel.c <<'END_OF_kernel.c'
  2743. X/*
  2744. X * Copyright (c) 1992 Michael A. Cooper.
  2745. X * This software may be freely distributed provided it is not sold for 
  2746. X * profit and the author is credited appropriately.
  2747. X */
  2748. X
  2749. X#ifndef lint
  2750. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/kernel.c,v 1.8 1992/04/26 23:32:06 mcooper Exp $";
  2751. X#endif
  2752. X
  2753. X/*
  2754. X * $Log: kernel.c,v $
  2755. X * Revision 1.8  1992/04/26  23:32:06  mcooper
  2756. X * Add Copyright notice
  2757. X *
  2758. X * Revision 1.7  1992/04/17  01:07:59  mcooper
  2759. X * More de-linting
  2760. X *
  2761. X * Revision 1.6  1992/04/16  02:25:39  mcooper
  2762. X * Bug fixes, de-linting, and other changes found with CodeCenter.
  2763. X *
  2764. X * Revision 1.5  1992/03/31  02:36:06  mcooper
  2765. X * Change "nl" to "VersionNL".
  2766. X *
  2767. X * Revision 1.4  1992/03/31  01:55:17  mcooper
  2768. X * Use new CheckNlist to check nlist success.
  2769. X *
  2770. X * Revision 1.3  1992/03/31  00:15:09  mcooper
  2771. X * Add error check for nlist.n_type.
  2772. X *
  2773. X * Revision 1.2  1992/03/22  00:55:41  mcooper
  2774. X * Use new GetNlName() to get n_name out of a struct nlist.
  2775. X *
  2776. X * Revision 1.1  1992/03/22  00:20:10  mcooper
  2777. X * Initial revision
  2778. X *
  2779. X */
  2780. X
  2781. X
  2782. X/*
  2783. X * Kernel related functions.
  2784. X */
  2785. X
  2786. X#include <stdio.h>
  2787. X#include "system.h"
  2788. X#include "defs.h"
  2789. X
  2790. X#if    defined(HAVE_NLIST)
  2791. X#include <fcntl.h>
  2792. X#include <nlist.h>
  2793. X
  2794. Xstruct nlist VersionNL[] = {
  2795. X#define     N_VERSION       0
  2796. X#if    defined(COFF)
  2797. X    { "version" },        /* 0 */
  2798. X#else
  2799. X    { "_version" },
  2800. X#endif    /* COFF */
  2801. X    { 0 },
  2802. X};
  2803. X
  2804. X#if    defined(HAVE_KVM)
  2805. X/*
  2806. X * Get kernel version string by reading the
  2807. X * symbol "version" from the kernel.
  2808. X */
  2809. Xextern char *GetKernelVersionFromVersion()
  2810. X{
  2811. X    static char            Buf[BUFSIZ];
  2812. X    register char           *p;
  2813. X    kvm_t               *kd;
  2814. X
  2815. X    if (kd = KVM_open(VersionNL)) {
  2816. X    /*
  2817. X     * See if we got a valid entry
  2818. X     */
  2819. X    if (CheckNlist(&VersionNL[N_VERSION]))
  2820. X        return((char *) NULL);
  2821. X
  2822. X    if (KVM_read(kd, VersionNL[N_VERSION].n_value, (char *) Buf, 
  2823. X             sizeof(Buf))) {
  2824. X        if (Debug) Error("Read of \"%s\" from kernel failed.",
  2825. X                 GetNlName(VersionNL[N_VERSION]));
  2826. X        Buf[0] = C_NULL;
  2827. X    }
  2828. X    }
  2829. X
  2830. X    if (kd)
  2831. X    KVM_close(kd);
  2832. X
  2833. X#if    defined(KERNSTR_END)
  2834. X    /*
  2835. X     * Truncate extraneous info
  2836. X     */
  2837. X    if (Buf[0])
  2838. X    if ((p = index(Buf, KERNSTR_END)) != NULL)
  2839. X        *p = C_NULL;
  2840. X#endif    /* KERNSTR_END */
  2841. X
  2842. X    return( (Buf[0]) ? Buf : (char *) NULL);
  2843. X}
  2844. X#endif    /* HAVE_KVM */
  2845. X#endif    /* HAVE_NLIST */
  2846. END_OF_kernel.c
  2847. if test 2262 -ne `wc -c <kernel.c`; then
  2848.     echo shar: \"kernel.c\" unpacked with wrong size!
  2849. fi
  2850. # end of overwriting check
  2851. fi
  2852. if test -f run.c -a "${1}" != "-c" ; then 
  2853.   echo shar: Will not over-write existing file \"run.c\"
  2854. else
  2855. echo shar: Extracting \"run.c\" \(3651 characters\)
  2856. sed "s/^X//" >run.c <<'END_OF_run.c'
  2857. X/*
  2858. X * Copyright (c) 1992 Michael A. Cooper.
  2859. X * This software may be freely distributed provided it is not sold for 
  2860. X * profit and the author is credited appropriately.
  2861. X */
  2862. X
  2863. X#ifndef lint
  2864. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/run.c,v 1.4 1992/04/26 23:32:06 mcooper Exp $";
  2865. X#endif
  2866. X
  2867. X/*
  2868. X * $Log: run.c,v $
  2869. X * Revision 1.4  1992/04/26  23:32:06  mcooper
  2870. X * Add Copyright notice
  2871. X *
  2872. X * Revision 1.3  1992/04/17  01:07:59  mcooper
  2873. X * More de-linting
  2874. X *
  2875. X * Revision 1.2  1992/04/16  02:25:39  mcooper
  2876. X * Bug fixes, de-linting, and other changes found with CodeCenter.
  2877. X *
  2878. X * Revision 1.1  1992/03/22  00:20:10  mcooper
  2879. X * Initial revision
  2880. X *
  2881. X */
  2882. X
  2883. X
  2884. X/*
  2885. X * Things related to running system commands.
  2886. X */
  2887. X#include <stdio.h>
  2888. X#include "system.h"
  2889. X#include "defs.h"
  2890. X
  2891. X/*
  2892. X * Specific command to determine our model name.
  2893. X */
  2894. X#if    defined(MODEL_COMMAND)
  2895. Xchar *ModelCommand[] = { MODEL_COMMAND, NULL };
  2896. X#endif    /* MODEL_COMMAND */
  2897. X
  2898. X/*
  2899. X * Application architecture commands.  
  2900. X * These commands should print the system's application architecture.
  2901. X */
  2902. Xchar *AppArchCmds[] = { 
  2903. X    "/bin/arch", 
  2904. X    "/bin/mach", 
  2905. X    "/bin/machine", 
  2906. X    NULL };
  2907. X
  2908. X/*
  2909. X * Kernel architecture commands.  
  2910. X * These commands should print the system's kernel architecture.
  2911. X */
  2912. Xchar *KernArchCmds[] = { 
  2913. X    "/bin/arch -k", 
  2914. X    "/bin/mach",
  2915. X    "/bin/machine", 
  2916. X    NULL };
  2917. X
  2918. X/*
  2919. X * Architecture test files.
  2920. X * Each test file is run and if the exit status is 0, 
  2921. X * the basename of the command is the name of the system architecture. 
  2922. X */
  2923. Xchar *ArchFiles[] = { 
  2924. X    "/bin/alliant", 
  2925. X    "/bin/vax", 
  2926. X    "/bin/sun", 
  2927. X    NULL };
  2928. X
  2929. X/*
  2930. X * CPU type test files.
  2931. X * Each test file is run and if the exit status is 0, 
  2932. X * the basename of the command is the name of the system CPU type. 
  2933. X */
  2934. Xchar *CPUFiles[] = { 
  2935. X    "/bin/sparc",
  2936. X    "/bin/mc68010",
  2937. X    "/bin/mc68020",
  2938. X    "/bin/mc68030",
  2939. X    "/bin/mc68040",
  2940. X    "/bin/m68k",
  2941. X    "/bin/vax",
  2942. X    "/bin/alliant",
  2943. X    "/bin/i386", 
  2944. X    "/bin/i860", 
  2945. X    "/bin/iAPX286",
  2946. X    "/bin/pdp11",
  2947. X    "/bin/u370",
  2948. X    "/bin/u3b15",
  2949. X    "/bin/u3b2",
  2950. X    "/bin/u3b5",
  2951. X    "/bin/u3b",
  2952. X    NULL };
  2953. X
  2954. X/*
  2955. X * Run a list of commands (found in cmds) and return command output.
  2956. X */
  2957. Xextern char *RunCmds(Cmds)
  2958. X    char               **Cmds;
  2959. X{
  2960. X    static char            Buf[BUFSIZ];
  2961. X    int             l;
  2962. X    FILE                *pf;
  2963. X    register char            *p;
  2964. X    char               **Cmd;
  2965. X
  2966. X    for (Cmd = Cmds; Cmd != NULL && *Cmd != NULL; ++Cmd) {
  2967. X    /*
  2968. X     * If this command has any args, nuke them for the access() test.
  2969. X     */
  2970. X    strcpy(Buf, *Cmd);
  2971. X    p = index(Buf, ' ');
  2972. X    if (p != NULL)
  2973. X        *p = C_NULL;
  2974. X
  2975. X    if (access(Buf, X_OK) != 0)
  2976. X        continue;
  2977. X
  2978. X    if ((pf = popen(*Cmd, "r")) == NULL)
  2979. X        continue;
  2980. X    if (fgets(Buf, sizeof(Buf), pf) == NULL) {
  2981. X        pclose(pf);
  2982. X        continue;
  2983. X    }
  2984. X    pclose(pf);
  2985. X
  2986. X    l = strlen(Buf);
  2987. X    if (Buf[l-1] == '\n') 
  2988. X        Buf[l-1] = C_NULL;
  2989. X
  2990. X    return(Buf);
  2991. X    }
  2992. X
  2993. X    return((char *) NULL);
  2994. X}
  2995. X
  2996. X/*
  2997. X * Run a list of test files.  Each test file is run and if the
  2998. X * exit status is 0, we return the basename of the command.
  2999. X * e.g. If "/bin/vax" exists and returns status 0, return string "vax".
  3000. X */
  3001. Xextern char *RunTestFiles(Cmds)
  3002. X    char               **Cmds;
  3003. X{
  3004. X    char               **Cmd;
  3005. X    register char           *p;
  3006. X    static char            Buf[BUFSIZ];
  3007. X
  3008. X    for (Cmd = Cmds; Cmd != NULL && *Cmd != NULL; ++Cmd) {
  3009. X    /*
  3010. X     * If this command has any args, nuke them for the access() test.
  3011. X     */
  3012. X    strcpy(Buf, *Cmd);
  3013. X    p = index(Buf, ' ');
  3014. X    if (p != NULL)
  3015. X        *p = C_NULL;
  3016. X
  3017. X    if (access(Buf, X_OK) != 0)
  3018. X        continue;
  3019. X
  3020. X    if (system(*Cmd) != 0)
  3021. X        continue;
  3022. X
  3023. X    /*
  3024. X     * The name of this architecture is the last part of the Cmd name.
  3025. X     */
  3026. X    strcpy(Buf, *Cmd);
  3027. X    p = rindex(Buf, '/');
  3028. X    if (p != NULL)
  3029. X        ++p;
  3030. X    return(p);
  3031. X    }
  3032. X
  3033. X    return(NULL);
  3034. X}
  3035. X
  3036. END_OF_run.c
  3037. if test 3651 -ne `wc -c <run.c`; then
  3038.     echo shar: \"run.c\" unpacked with wrong size!
  3039. fi
  3040. # end of overwriting check
  3041. fi
  3042. if test -f KVM.c -a "${1}" != "-c" ; then 
  3043.   echo shar: Will not over-write existing file \"KVM.c\"
  3044. else
  3045. echo shar: Extracting \"KVM.c\" \(3098 characters\)
  3046. sed "s/^X//" >KVM.c <<'END_OF_KVM.c'
  3047. X/*
  3048. X * Copyright (c) 1992 Michael A. Cooper.
  3049. X * This software may be freely distributed provided it is not sold for 
  3050. X * profit and the author is credited appropriately.
  3051. X */
  3052. X#ifndef lint
  3053. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/KVM.c,v 1.15 1992/04/26 23:32:06 mcooper Exp $";
  3054. X#endif
  3055. X
  3056. X/*
  3057. X * $Log: KVM.c,v $
  3058. X * Revision 1.15  1992/04/26  23:32:06  mcooper
  3059. X * Add Copyright notice
  3060. X *
  3061. X * Revision 1.13  1992/04/17  23:28:33  mcooper
  3062. X * Fixed NULL deref bug.
  3063. X *
  3064. X * Revision 1.12  1992/04/17  01:07:59  mcooper
  3065. X * More de-linting
  3066. X *
  3067. X * Revision 1.11  1992/04/16  02:25:39  mcooper
  3068. X * Bug fixes, de-linting, and other changes found with CodeCenter.
  3069. X *
  3070. X * Revision 1.10  1992/03/31  03:10:17  mcooper
  3071. X * Put frontend macro around CheckNlist() to avoid
  3072. X * broken things in Ultrix.
  3073. X *
  3074. X * Revision 1.9  1992/03/31  02:44:20  mcooper
  3075. X * Add BROKEN_NLIST_CHECK define.
  3076. X *
  3077. X * Revision 1.8  1992/03/31  01:54:50  mcooper
  3078. X * Add CheckNlist().
  3079. X *
  3080. X * Revision 1.7  1992/03/31  00:34:42  mcooper
  3081. X * Make GetNlName() a macro.
  3082. X *
  3083. X * Revision 1.6  1992/03/30  23:44:05  mcooper
  3084. X * *** empty log message ***
  3085. X *
  3086. X */
  3087. X
  3088. X
  3089. X/*
  3090. X * Frontend functions for kvm_*() functions
  3091. X *
  3092. X * It is assumed we HAVE_NLIST if we HAVE_KVM.
  3093. X */
  3094. X
  3095. X#include <stdio.h>
  3096. X#include "system.h"
  3097. X
  3098. X#if    defined(HAVE_KVM)
  3099. X
  3100. X#include "defs.h"
  3101. X
  3102. X#include <fcntl.h>
  3103. X#if    defined(HAVE_NLIST)
  3104. X#include <nlist.h>
  3105. X#endif    /* HAVE_NLIST */
  3106. X
  3107. X/*
  3108. X * Perform a kvm_close().  Really just hear to be compatible.
  3109. X */
  3110. Xextern void KVM_close(kd)
  3111. X    kvm_t                *kd;
  3112. X{
  3113. X    if (kd)
  3114. X    (void) kvm_close(kd);
  3115. X}
  3116. X
  3117. X/*
  3118. X * Perform a kvm_open() and then a kvm_nlist().
  3119. X */
  3120. X#if    defined(HAVE_NLIST)
  3121. X/*
  3122. X * Do a kvm_open()
  3123. X */
  3124. Xextern kvm_t *KVM_open(PtrNL)
  3125. X    struct nlist            *PtrNL;
  3126. X#else
  3127. Xetern kvm_t *KVM_open()
  3128. X#endif    /* HAVE_NLIST */
  3129. X{
  3130. X    kvm_t                *kd = NULL;
  3131. X    extern char            *ProgramName;
  3132. X
  3133. X    if ((kd = kvm_open((char *)NULL, (char *)NULL, (char *)NULL, O_RDONLY,
  3134. X               ProgramName)) == NULL) {
  3135. X    if (Debug) Error("kvm_open failed: %s.", SYSERR);
  3136. X    return((kvm_t *) NULL);
  3137. X    }
  3138. X
  3139. X#if    defined(HAVE_NLIST)
  3140. X    if (PtrNL)
  3141. X    if (kvm_nlist(kd, PtrNL) != 0) {
  3142. X        if (Debug) Error("kvm_nlist name \"%s\" failed: %s.", 
  3143. X                 GetNlNamePtr(PtrNL), SYSERR);
  3144. X        KVM_close(kd);
  3145. X        return((kvm_t *) NULL);
  3146. X    }
  3147. X#endif    /* HAVE_NLIST */
  3148. X
  3149. X    return(kd);
  3150. X}
  3151. X
  3152. X/*
  3153. X * Perform a kvm_read().
  3154. X */
  3155. Xextern int KVM_read(kd, Addr, Buf, NumBytes)
  3156. X    kvm_t                *kd;
  3157. X    u_long             Addr;
  3158. X    char                *Buf;
  3159. X    unsigned                 NumBytes;
  3160. X{
  3161. X    int                Count;
  3162. X
  3163. X    if (!kd)
  3164. X    return(-1);
  3165. X
  3166. X    if ((Count = kvm_read(kd, Addr, Buf, NumBytes)) != NumBytes) {
  3167. X    if (Debug) Error("kvm_read failed (expected %d, got %d): %s.", 
  3168. X             NumBytes, Count, SYSERR);
  3169. X    return(-1);
  3170. X    }
  3171. X
  3172. X    return(0);
  3173. X}
  3174. X
  3175. X/*
  3176. X * Check to see if PtrNL is valid.
  3177. X */
  3178. Xextern int _CheckNlist(PtrNL)
  3179. X    struct nlist           *PtrNL;
  3180. X{
  3181. X    /*
  3182. X     * Should use n_type, but that's not set
  3183. X     * correctly on some OS's.
  3184. X     */
  3185. X    if (!PtrNL || !PtrNL->n_value) {
  3186. X    if (Debug) Error("Kernel symbol \"%s\" not found.", 
  3187. X             GetNlNamePtr(PtrNL));
  3188. X    return(-1);
  3189. X    }
  3190. X
  3191. X    return(0);
  3192. X}
  3193. X
  3194. X#endif /* HAVE_KVM */
  3195. END_OF_KVM.c
  3196. if test 3098 -ne `wc -c <KVM.c`; then
  3197.     echo shar: \"KVM.c\" unpacked with wrong size!
  3198. fi
  3199. # end of overwriting check
  3200. fi
  3201. if test -f kvm.c -a "${1}" != "-c" ; then 
  3202.   echo shar: Will not over-write existing file \"kvm.c\"
  3203. else
  3204. echo shar: Extracting \"kvm.c\" \(4463 characters\)
  3205. sed "s/^X//" >kvm.c <<'END_OF_kvm.c'
  3206. X/*
  3207. X * Copyright (c) 1992 Michael A. Cooper.
  3208. X * This software may be freely distributed provided it is not sold for 
  3209. X * profit and the author is credited appropriately.
  3210. X */
  3211. X
  3212. X#ifndef lint
  3213. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/kvm.c,v 1.11 1992/04/26 23:32:06 mcooper Exp $";
  3214. X#endif
  3215. X
  3216. X/*
  3217. X * $Log: kvm.c,v $
  3218. X * Revision 1.11  1992/04/26  23:32:06  mcooper
  3219. X * Add Copyright notice
  3220. X *
  3221. X * Revision 1.10  1992/04/17  01:07:59  mcooper
  3222. X * More de-linting
  3223. X *
  3224. X * Revision 1.9  1992/03/22  00:20:10  mcooper
  3225. X * Major cleanup and re-org.
  3226. X *
  3227. X * Revision 1.8  1992/03/13  00:24:41  mcooper
  3228. X * Always copy vmfile and namelist because we free()
  3229. X * them in kvm_close().  GCC compiled stuff blows up
  3230. X * if we free() a constant.
  3231. X *
  3232. X * Revision 1.7  1992/03/12  02:03:33  mcooper
  3233. X * Change unix image to be /mach on NeXT machines.
  3234. X *
  3235. X * Revision 1.6  1992/03/04  00:01:59  mcooper
  3236. X * Make HAVE_KVM and HAVE_NLIST consistant.
  3237. X *
  3238. X * Revision 1.5  1992/03/03  03:18:59  mcooper
  3239. X * Seperate and cleanup KVM*() from kvm*().
  3240. X *
  3241. X * Revision 1.4  1992/03/01  23:28:33  mcooper
  3242. X * Add kvm_close() support and changed to work with picky
  3243. X * Alliant compiler.
  3244. X *
  3245. X * Revision 1.3  1992/02/22  02:20:19  mcooper
  3246. X * Major changes to support scanning kernel mainbus and
  3247. X * openprom data for device's.
  3248. X *
  3249. X * Revision 1.2  1992/02/10  04:13:18  mcooper
  3250. X * Move strdup() to sysinfo.c
  3251. X *
  3252. X * Revision 1.1  1991/09/28  03:14:49  mcooper
  3253. X * Initial revision
  3254. X *
  3255. X */
  3256. X
  3257. X#include "system.h"
  3258. X
  3259. X#if defined(NEED_KVM)
  3260. X
  3261. X#include <stdio.h>
  3262. X#include <sys/errno.h>
  3263. X#include "kvm.h"
  3264. X
  3265. X#ifndef SYSFAIL
  3266. X#define SYSFAIL -1
  3267. X#endif
  3268. X
  3269. X#if defined(DEBUG) && !defined(SYSERR)
  3270. Xextern int errno;
  3271. Xextern char sys_errlist[];
  3272. X#define SYSERR sys_errlist[errno]
  3273. X#endif
  3274. X
  3275. Xchar *strdup();
  3276. X
  3277. X#if defined(alliant) || defined(_AIX)
  3278. X#define NAMELIST    "/unix"
  3279. X#else
  3280. X#if defined(NeXT)
  3281. X#define NAMELIST    "/mach"
  3282. X#else
  3283. X#define NAMELIST    "/vmunix"
  3284. X#endif
  3285. X#endif
  3286. X#define MEMFILE        "/dev/mem"
  3287. X#define KMEMFILE    "/dev/kmem"
  3288. X
  3289. X/*
  3290. X * Close things down.
  3291. X */
  3292. Xextern int kvm_close(kd)
  3293. X    kvm_t                *kd;
  3294. X{
  3295. X    if (!kd)
  3296. X    return(-1);
  3297. X
  3298. X    if (kd->kmemd)
  3299. X    close(kd->kmemd);
  3300. X    if (kd->namelist)
  3301. X    free(kd->namelist);
  3302. X    if (kd->vmfile)
  3303. X    free(kd->vmfile);
  3304. X
  3305. X    free(kd);
  3306. X
  3307. X    return(0);
  3308. X}
  3309. X
  3310. X/*
  3311. X * Open things up.
  3312. X */
  3313. Xextern kvm_t *kvm_open(NameList, CoreFile, SwapFile, Flag, ErrStr)
  3314. X    char                *NameList;
  3315. X    char                *CoreFile;
  3316. X    char                *SwapFile;
  3317. X    int             Flag;
  3318. X    char                *ErrStr;
  3319. X{
  3320. X    kvm_t *kd;
  3321. X
  3322. X    if ((kd = (kvm_t *) malloc(sizeof(kvm_t))) == NULL) {
  3323. X#ifdef DEBUG
  3324. X    fprintf(stderr, "kvm_open() malloc %d bytes failed!\n", sizeof(kvm_t));
  3325. X#endif
  3326. X    return((kvm_t *) NULL);
  3327. X    }
  3328. X
  3329. X    if (NameList)
  3330. X    kd->namelist = strdup(NameList);
  3331. X    else
  3332. X    kd->namelist = strdup(NAMELIST);
  3333. X
  3334. X    if (CoreFile)
  3335. X    kd->vmfile = strdup(CoreFile);
  3336. X    else
  3337. X    kd->vmfile = strdup(KMEMFILE);
  3338. X
  3339. X    if ((kd->kmemd = open(kd->vmfile, Flag, 0)) == SYSFAIL) {
  3340. X#ifdef DEBUG
  3341. X    fprintf(stderr, "kvm_open() open '%s' failed: %s.\n", kd->vmfile, 
  3342. X        SYSERR);
  3343. X#endif
  3344. X    return((kvm_t *) NULL);
  3345. X    }
  3346. X
  3347. X    return(kd);
  3348. X}
  3349. X
  3350. X/*
  3351. X * KVM read function
  3352. X */
  3353. Xextern int kvm_read(kd, Addr, Buf, NBytes)
  3354. X     kvm_t                *kd;
  3355. X     unsigned long         Addr;
  3356. X     char                *Buf;
  3357. X     unsigned             NBytes;
  3358. X{
  3359. X    unsigned             ret;
  3360. X
  3361. X    if (!kd) {
  3362. X#ifdef DEBUG
  3363. X    fprintf(stderr, "kvm_read(): invalid kd param.\n");
  3364. X#endif
  3365. X    return(SYSFAIL);
  3366. X    }
  3367. X
  3368. X    if (lseek(kd->kmemd, Addr, 0) == SYSFAIL) {
  3369. X#ifdef DEBUG
  3370. X    fprintf(stderr, "kvm_read(): lseek failed (desc %d addr 0x%x): %s.\n",
  3371. X        kd->kmemd, Addr, SYSERR);
  3372. X#endif
  3373. X    return(SYSFAIL);
  3374. X    }
  3375. X
  3376. X    if ((ret = read(kd->kmemd, Buf, NBytes)) != NBytes) {
  3377. X#ifdef DEBUG
  3378. X    fprintf(stderr, 
  3379. X        "kvm_read(): read failed (desc %d buf 0x%x size %d): %s.\n",
  3380. X        kd->kmemd, Buf, NBytes, SYSERR);
  3381. X#endif
  3382. X    return(SYSFAIL);
  3383. X    }
  3384. X
  3385. X    return(ret);
  3386. X}
  3387. X
  3388. X/*
  3389. X * KVM write function
  3390. X */
  3391. Xextern int kvm_write(kd, Addr, Buf, NBytes)
  3392. X     kvm_t                *kd;
  3393. X     unsigned long         Addr;
  3394. X     char                *Buf;
  3395. X     unsigned             NBytes;
  3396. X{
  3397. X    unsigned             ret;
  3398. X
  3399. X    if (!kd) {
  3400. X    return(SYSFAIL);
  3401. X    }
  3402. X
  3403. X    if (lseek(kd->kmemd, Addr, 0) == SYSFAIL) {
  3404. X    return(SYSFAIL);
  3405. X    }
  3406. X
  3407. X    if ((ret = write(kd->kmemd, Buf, NBytes)) != NBytes) {
  3408. X    return(SYSFAIL);
  3409. X    }
  3410. X
  3411. X    return(ret);
  3412. X}
  3413. X
  3414. X/*
  3415. X * Perform an nlist()
  3416. X */
  3417. X#if    defined(HAVE_NLIST)
  3418. Xextern int kvm_nlist(kd, nl)
  3419. X     kvm_t                *kd;
  3420. X     struct nlist            *nl;
  3421. X{
  3422. X    if (!kd) {
  3423. X    return(SYSFAIL);
  3424. X    }
  3425. X
  3426. X    return(nlist(kd->namelist, nl));
  3427. X}
  3428. X#endif    /* HAVE_NLIST */
  3429. X
  3430. X#endif /* NEED_KVM */
  3431. END_OF_kvm.c
  3432. if test 4463 -ne `wc -c <kvm.c`; then
  3433.     echo shar: \"kvm.c\" unpacked with wrong size!
  3434. fi
  3435. # end of overwriting check
  3436. fi
  3437. if test -f kvm.h -a "${1}" != "-c" ; then 
  3438.   echo shar: Will not over-write existing file \"kvm.h\"
  3439. else
  3440. echo shar: Extracting \"kvm.h\" \(729 characters\)
  3441. sed "s/^X//" >kvm.h <<'END_OF_kvm.h'
  3442. X#ifndef __kvm_h__
  3443. X#define __kvm_h__
  3444. X/*
  3445. X * $Header: /src/common/usc/bin/sysinfo/RCS/kvm.h,v 1.3 1992/06/01 22:43:53 mcooper Exp $
  3446. X *
  3447. X * $Log: kvm.h,v $
  3448. X * Revision 1.3  1992/06/01  22:43:53  mcooper
  3449. X * Cleanup.
  3450. X *
  3451. X * Revision 1.2  1992/03/01  23:19:55  mcooper
  3452. X * Put surrounding #ifndef around file to avoid multiple include
  3453. X * problems.  Also move struct _kvmd here from kvm.c.
  3454. X *
  3455. X * Revision 1.1  1991/09/28  03:14:49  mcooper
  3456. X * Initial revision
  3457. X *
  3458. X */
  3459. X
  3460. Xstruct _kvmd {
  3461. X    int            kmemd;
  3462. X    char           *namelist;
  3463. X    char           *vmfile;
  3464. X};
  3465. Xtypedef struct _kvmd kvm_t;
  3466. X
  3467. Xextern kvm_t           *kvm_open();
  3468. Xextern int        kvm_close();
  3469. Xextern int        kvm_nlist();
  3470. Xextern int        kvm_read();
  3471. Xextern int        kvm_write();
  3472. X
  3473. X#endif /* __kvm_h__ */
  3474. END_OF_kvm.h
  3475. if test 729 -ne `wc -c <kvm.h`; then
  3476.     echo shar: \"kvm.h\" unpacked with wrong size!
  3477. fi
  3478. # end of overwriting check
  3479. fi
  3480. if test -f patchlevel.h -a "${1}" != "-c" ; then 
  3481.   echo shar: Will not over-write existing file \"patchlevel.h\"
  3482. else
  3483. echo shar: Extracting \"patchlevel.h\" \(50 characters\)
  3484. sed "s/^X//" >patchlevel.h <<'END_OF_patchlevel.h'
  3485. X/*
  3486. X * Patch level values
  3487. X */
  3488. X#define PATCHLEVEL 0
  3489. END_OF_patchlevel.h
  3490. if test 50 -ne `wc -c <patchlevel.h`; then
  3491.     echo shar: \"patchlevel.h\" unpacked with wrong size!
  3492. fi
  3493. # end of overwriting check
  3494. fi
  3495. if test -f strcasecmp.c -a "${1}" != "-c" ; then 
  3496.   echo shar: Will not over-write existing file \"strcasecmp.c\"
  3497. else
  3498. echo shar: Extracting \"strcasecmp.c\" \(3312 characters\)
  3499. sed "s/^X//" >strcasecmp.c <<'END_OF_strcasecmp.c'
  3500. X#ifndef lint
  3501. Xstatic char *RCSid = "$Header: /src/common/usc/lib/libgen/RCS/strcasecmp.c,v 1.3 1989/10/26 19:13:06 mcooper Exp $";
  3502. X#endif
  3503. X
  3504. X/*
  3505. X * $Log: strcasecmp.c,v $
  3506. X * Revision 1.3  1989/10/26  19:13:06  mcooper
  3507. X * This is the BSD version.
  3508. X *
  3509. X * Revision 1.3  1989/10/26  19:13:06  mcooper
  3510. X * This is the BSD version.
  3511. X *
  3512. X */
  3513. X
  3514. X#ifndef lint
  3515. Xstatic char sccsid[] = "@(#)strcasecmp.c 1.1 89/05/19 SMI"; /* from UCB 1.3 8/3/87 */
  3516. X#endif
  3517. X
  3518. X/*
  3519. X * Copyright (c) 1987 Regents of the University of California.
  3520. X * All rights reserved.  The Berkeley software License Agreement
  3521. X * specifies the terms and conditions for redistribution.
  3522. X */
  3523. X
  3524. X/*
  3525. X * This array is designed for mapping upper and lower case letter
  3526. X * together for a case independent comparison.  The mappings are
  3527. X * based upon ascii character sequences.
  3528. X */
  3529. Xstatic char charmap[] = {
  3530. X    '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  3531. X    '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  3532. X    '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  3533. X    '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  3534. X    '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  3535. X    '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  3536. X    '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  3537. X    '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  3538. X    '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  3539. X    '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  3540. X    '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  3541. X    '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  3542. X    '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  3543. X    '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  3544. X    '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  3545. X    '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  3546. X    '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  3547. X    '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  3548. X    '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  3549. X    '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  3550. X    '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  3551. X    '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  3552. X    '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  3553. X    '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  3554. X    '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  3555. X    '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  3556. X    '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  3557. X    '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
  3558. X    '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  3559. X    '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  3560. X    '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  3561. X    '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  3562. X};
  3563. X
  3564. Xstrcasecmp(s1, s2)
  3565. X    register char *s1, *s2;
  3566. X{
  3567. X    register char *cm = charmap;
  3568. X
  3569. X    while (cm[*s1] == cm[*s2++])
  3570. X        if (*s1++ == '\0')
  3571. X            return(0);
  3572. X    return(cm[*s1] - cm[*--s2]);
  3573. X}
  3574. X
  3575. Xstrncasecmp(s1, s2, n)
  3576. X    register char *s1, *s2;
  3577. X    register int n;
  3578. X{
  3579. X    register char *cm = charmap;
  3580. X
  3581. X    while (--n >= 0 && cm[*s1] == cm[*s2++])
  3582. X        if (*s1++ == '\0')
  3583. X            return(0);
  3584. X    return(n < 0 ? 0 : cm[*s1] - cm[*--s2]);
  3585. X}
  3586. END_OF_strcasecmp.c
  3587. if test 3312 -ne `wc -c <strcasecmp.c`; then
  3588.     echo shar: \"strcasecmp.c\" unpacked with wrong size!
  3589. fi
  3590. # end of overwriting check
  3591. fi
  3592. if test -f strdup.c -a "${1}" != "-c" ; then 
  3593.   echo shar: Will not over-write existing file \"strdup.c\"
  3594. else
  3595. echo shar: Extracting \"strdup.c\" \(684 characters\)
  3596. sed "s/^X//" >strdup.c <<'END_OF_strdup.c'
  3597. X#ifndef lint
  3598. Xstatic char *RCSid = "$Header: /src/common/usc/lib/libgen/RCS/strdup.c,v 1.2 1992/04/16 01:28:02 mcooper Exp $";
  3599. X#endif
  3600. X
  3601. X/*
  3602. X * $Log: strdup.c,v $
  3603. X * Revision 1.2  1992/04/16  01:28:02  mcooper
  3604. X * Some de-linting.
  3605. X *
  3606. X * Revision 1.2  1992/04/16  01:28:02  mcooper
  3607. X * Some de-linting.
  3608. X *
  3609. X * Revision 1.1  1992/03/21  02:48:11  mcooper
  3610. X * Initial revision
  3611. X *
  3612. X */
  3613. X
  3614. X
  3615. X#include <stdio.h>
  3616. X
  3617. X/*
  3618. X * Most systems don't have this (yet)
  3619. X */
  3620. Xchar *strdup(str)
  3621. X     char *str;
  3622. X{
  3623. X    char                *p;
  3624. X    extern char               *malloc();
  3625. X    extern char               *strcpy();
  3626. X
  3627. X    if ((p = malloc(strlen(str)+1)) == NULL)
  3628. X    return((char *) NULL);
  3629. X
  3630. X    (void) strcpy(p, str);
  3631. X
  3632. X    return(p);
  3633. X}
  3634. END_OF_strdup.c
  3635. if test 684 -ne `wc -c <strdup.c`; then
  3636.     echo shar: \"strdup.c\" unpacked with wrong size!
  3637. fi
  3638. # end of overwriting check
  3639. fi
  3640. if test -f strerror.c -a "${1}" != "-c" ; then 
  3641.   echo shar: Will not over-write existing file \"strerror.c\"
  3642. else
  3643. echo shar: Extracting \"strerror.c\" \(683 characters\)
  3644. sed "s/^X//" >strerror.c <<'END_OF_strerror.c'
  3645. X#ifndef lint
  3646. Xstatic char *RCSid = "$Header: /src/common/usc/lib/libgen/RCS/strerror.c,v 1.1 1992/03/21 02:48:11 mcooper Exp $";
  3647. X#endif
  3648. X
  3649. X/*
  3650. X * $Log: strerror.c,v $
  3651. X * Revision 1.1  1992/03/21  02:48:11  mcooper
  3652. X * Initial revision
  3653. X *
  3654. X * Revision 1.1  1992/03/21  02:48:11  mcooper
  3655. X * Initial revision
  3656. X *
  3657. X */
  3658. X
  3659. X#include <stdio.h>
  3660. X#include <sys/errno.h>
  3661. X
  3662. X/*
  3663. X * Return string for system error number "Num".
  3664. X */
  3665. Xchar *strerror(Num)
  3666. X     int            Num;
  3667. X{
  3668. X    extern int             sys_nerr;
  3669. X    extern char            *sys_errlist[];
  3670. X    static char         Unknown[100];
  3671. X
  3672. X    if (Num < 0 || Num > sys_nerr) {
  3673. X    (void) sprintf(Unknown, "Error %d", Num);
  3674. X    return(Unknown);
  3675. X    } else
  3676. X    return(sys_errlist[Num]);
  3677. X}
  3678. END_OF_strerror.c
  3679. if test 683 -ne `wc -c <strerror.c`; then
  3680.     echo shar: \"strerror.c\" unpacked with wrong size!
  3681. fi
  3682. # end of overwriting check
  3683. fi
  3684. if test -f options.c -a "${1}" != "-c" ; then 
  3685.   echo shar: Will not over-write existing file \"options.c\"
  3686. else
  3687. echo shar: Extracting \"options.c\" \(11038 characters\)
  3688. sed "s/^X//" >options.c <<'END_OF_options.c'
  3689. X/*
  3690. X * Copyright (c) 1990 Michael A. Cooper.
  3691. X * This software may be freely distributed provided it is not sold for 
  3692. X * profit and the author is credited appropriately.
  3693. X */
  3694. X
  3695. X#ifndef lint
  3696. Xstatic char *RCSid = "$Header: /src/common/usc/lib/libgen/RCS/options.c,v 1.14 1992/04/16 01:28:02 mcooper Exp $";
  3697. X#endif
  3698. X
  3699. X/*
  3700. X * $Log: options.c,v $
  3701. X * Revision 1.14  1992/04/16  01:28:02  mcooper
  3702. X * Some de-linting.
  3703. X *
  3704. X * Revision 1.14  1992/04/16  01:28:02  mcooper
  3705. X * Some de-linting.
  3706. X *
  3707. X * Revision 1.13  1990/12/15  18:13:28  mcooper
  3708. X * Add copywrite notice.
  3709. X *
  3710. X * Revision 1.12  90/12/15  17:51:46  mcooper
  3711. X * Add #ifdef HAS_VARARGS around include for <varargs>.
  3712. X * 
  3713. X * Revision 1.11  90/11/13  16:39:28  mcooper
  3714. X * Add #ifdef HAS_VARARGS for systems without
  3715. X * varargs.
  3716. X * 
  3717. X * Revision 1.10  90/11/13  15:28:01  mcooper
  3718. X * - Add OptBool cvtarg routine.
  3719. X * - Print default values in HelpOptions() 
  3720. X *   when appropriate.
  3721. X * 
  3722. X * Revision 1.9  90/11/13  15:19:00  mcooper
  3723. X * Added supported for options being both
  3724. X * SepArg and StickyArg.
  3725. X * 
  3726. X * Revision 1.8  90/10/30  21:02:31  mcooper
  3727. X * Need to exit() if -help is specified.
  3728. X * 
  3729. X * Revision 1.7  90/10/30  20:24:33  mcooper
  3730. X * Fixed bug in UsageString().
  3731. X * 
  3732. X * Revision 1.6  90/10/30  19:53:05  mcooper
  3733. X * Cleaned up some NeXT cc and lint stuff.
  3734. X * 
  3735. X * Revision 1.5  90/10/30  19:45:31  mcooper
  3736. X * Remove unneeded paramter to HelpOptions().
  3737. X * 
  3738. X * Revision 1.4  90/10/29  14:47:42  mcooper
  3739. X * Added real function UsageString() to
  3740. X * handle formating usage option strings.
  3741. X * 
  3742. X * Revision 1.3  90/10/29  14:17:00  mcooper
  3743. X * Allow options to be abbreviated 
  3744. X * (for all non StickArg options).
  3745. X * 
  3746. X * Revision 1.2  90/10/26  15:56:11  mcooper
  3747. X * - Fix bug in SepArg code that ate arguments.
  3748. X * - Cleanup help message.
  3749. X * - Add ArgHidden code.
  3750. X * 
  3751. X * Revision 1.1  90/10/26  14:42:51  mcooper
  3752. X * Initial revision
  3753. X * 
  3754. X */
  3755. X
  3756. X/*
  3757. X * Functions to parse options.
  3758. X */
  3759. X
  3760. X#include "options.h"
  3761. X#ifdef HAS_VARARGS
  3762. X#include <varargs.h>
  3763. X#endif
  3764. X
  3765. Xchar *OptionChars = "-+";    /* Default option switching characters */
  3766. Xchar *ProgramName = NULL;    /* Name of this program */
  3767. Xchar *UsageString();
  3768. Xstatic int isopt();
  3769. Xstatic int suppress_help_msg = 0;
  3770. Xchar *strcat();
  3771. X
  3772. X/*
  3773. X * ParseOptions - Parse options found in argv using "options".
  3774. X *          Returns the number of options parsed if there
  3775. X *          were no errors.  Returns -1 if an error occurs.
  3776. X */
  3777. Xint ParseOptions(options, num_options, argc, argv)
  3778. X     OptionDescRec *options;
  3779. X     int num_options;
  3780. X     int argc;
  3781. X     char **argv;
  3782. X{
  3783. X    OptionDescRec *opt;
  3784. X    register int x;
  3785. X    char *p;
  3786. X
  3787. X    if (ProgramName == NULL)
  3788. X    ProgramName = argv[0];
  3789. X
  3790. X#ifdef OPTION_DEBUG
  3791. X    (void) printf("Option list is:\n");
  3792. X    for (x = 0; x < num_options; ++x) {
  3793. X    opt = &options[x];
  3794. X    (void) printf("%s\n", opt->option);
  3795. X    }
  3796. X
  3797. X    (void) printf("Arguments (%d):", argc);
  3798. X    for (x = 0; x < argc; ++x) {
  3799. X    (void) printf(" %s", argv[x]);
  3800. X    }
  3801. X    (void) printf("\n");
  3802. X#endif /* OPTION_DEBUG */
  3803. X
  3804. X    for (x = 1; x < argc; ++x) {
  3805. X    if (strcmp(HELPSTR, argv[x]) == 0) {
  3806. X        HelpOptions(options, num_options, (char **)NULL);
  3807. X        exit(0);
  3808. X    }
  3809. X
  3810. X    opt = FindOption(options, num_options, argv[x]);
  3811. X    if (opt == NULL) {
  3812. X        if (isopt(argv[x])) { /* this was suppose to be an option */
  3813. X        UsageOptions(options, num_options, argv[x]);
  3814. X        return(-1);
  3815. X        } else { /* must be end of options */
  3816. X        break;
  3817. X        }
  3818. X    }
  3819. X
  3820. X    if (opt->flags & NoArg) {
  3821. X        if (!(*opt->cvtarg)(opt, opt->value, FALSE)) {
  3822. X        UsageOptions(options, num_options, opt->option);
  3823. X        return(-1);
  3824. X        }
  3825. X    } else if (opt->flags & IsArg) {
  3826. X        if (!(*opt->cvtarg)(opt, opt->option, FALSE)) {
  3827. X        UsageOptions(options, num_options, opt->option);
  3828. X        return(-1);
  3829. X        }
  3830. X    } else if ((opt->flags & StickyArg) && (opt->flags & SepArg)) {
  3831. X        p = (char *) &argv[x][strlen(opt->option)];
  3832. X        if (!*p) {        /*** SepArg ***/
  3833. X        if (x + 1 >= argc || isopt(argv[x+1])) {
  3834. X            if (opt->value == (caddr_t) NULL) {
  3835. X            UserError("%s: Option requires an argument.", argv[x]);
  3836. X            UsageOptions(options, num_options, opt->option);
  3837. X            return(-1);
  3838. X            }
  3839. X            p = opt->value;
  3840. X        } else {
  3841. X            p = argv[++x];
  3842. X        }
  3843. X        }
  3844. X        if (!(*opt->cvtarg)(opt, p, TRUE)) {
  3845. X        UsageOptions(options, num_options, opt->option);
  3846. X        return(-1);
  3847. X        }
  3848. X    } else if (opt->flags & StickyArg) {
  3849. X        p = (char *) &argv[x][strlen(opt->option)];
  3850. X        if (!*p) {
  3851. X        if (opt->value == (caddr_t) NULL) {
  3852. X            UserError("%s: Option requires an argument.", argv[x]);
  3853. X            UsageOptions(options, num_options, opt->option);
  3854. X            return(-1);
  3855. X        } else {
  3856. X            p = opt->value;
  3857. X        }
  3858. X        }
  3859. X        if (!(*opt->cvtarg)(opt, p, TRUE)) {
  3860. X        UsageOptions(options, num_options, opt->option);
  3861. X        return(-1);
  3862. X        }
  3863. X    } else if (opt->flags & SepArg) {
  3864. X        if (x + 1 >= argc || isopt(argv[x+1])) {
  3865. X        if (opt->value == (caddr_t) NULL) {
  3866. X            UserError("%s: Option requires an argument.", argv[x]);
  3867. X            UsageOptions(options, num_options, opt->option);
  3868. X            return(-1);
  3869. X        } else {
  3870. X            p = opt->value;
  3871. X        }
  3872. X        } else {
  3873. X        p = argv[++x];
  3874. X        }
  3875. X        if (!(*opt->cvtarg)(opt, p, TRUE)) {
  3876. X        UsageOptions(options, num_options, opt->option);
  3877. X        return(-1);
  3878. X        }
  3879. X    } else if (opt->flags & SkipArg) {
  3880. X        x += 2;
  3881. X    } else if (opt->flags & SkipLine) {
  3882. X        return(x);
  3883. X    } else if (opt->flags & SkipNArgs) {
  3884. X        if (opt->value) {
  3885. X        x += atoi(opt->value);
  3886. X        } else {
  3887. X        UserError("Internal Error: No 'value' set for SkipNArgs.");
  3888. X        return(-1);
  3889. X        }
  3890. X    } else {
  3891. X        UserError("Internal Error: Unknown argument type for option '%s'.",
  3892. X             opt->option);
  3893. X        return(-1);
  3894. X    }
  3895. X    }
  3896. X
  3897. X    return(x);
  3898. X}
  3899. X
  3900. X/*
  3901. X * FindOption - Find "option" in "options".  Returns NULL if not found.
  3902. X */
  3903. XOptionDescRec *FindOption(options, num_options, option)
  3904. X     OptionDescRec *options;
  3905. X     int num_options;
  3906. X     char *option;
  3907. X{
  3908. X    OptionDescRec *opt;
  3909. X    register int x;
  3910. X
  3911. X    for (x = 0; x < num_options; ++x) {
  3912. X    opt = &options[x];
  3913. X    if (opt->flags & StickyArg) {
  3914. X        if (strncmp(option, opt->option, strlen(opt->option)) == 0)
  3915. X        return(opt);
  3916. X    } else {
  3917. X        if (strncmp(option, opt->option, strlen(option)) == 0)
  3918. X        return(opt);
  3919. X    }
  3920. X    }
  3921. X
  3922. X    return(NULL);
  3923. X}
  3924. X
  3925. X/*
  3926. X * isopt - Is "str" an option string?  Compare first char of str against
  3927. X *       list of option switch characters.  Returns TRUE if it is an option.
  3928. X */
  3929. Xstatic int isopt(str)
  3930. X     char *str;
  3931. X{
  3932. X    register char *p;
  3933. X
  3934. X    for (p = OptionChars; p && *p; ++p) {
  3935. X    if (*str == *p) {
  3936. X        return(TRUE);
  3937. X    }
  3938. X    }
  3939. X
  3940. X    return(FALSE);
  3941. X}
  3942. X
  3943. X/*
  3944. X * UsageOptions - Print a usage message based on "options".
  3945. X */
  3946. Xvoid UsageOptions(options, num_opts, badOption)
  3947. X     OptionDescRec *options;
  3948. X     int num_opts;
  3949. X     char *badOption;
  3950. X{
  3951. X    OptionDescRec *opt;
  3952. X    char *optstr;
  3953. X    register int x;
  3954. X    int col, len;
  3955. X
  3956. X    if (badOption) 
  3957. X    (void) fprintf (stderr, "%s:  bad command line option \"%s\"\r\n\n",
  3958. X            ProgramName, badOption);
  3959. X
  3960. X    (void) fprintf (stderr, "usage:  %s", ProgramName);
  3961. X    col = 8 + strlen(ProgramName);
  3962. X    for (x = 0; x < num_opts; x++) {
  3963. X    opt = &options[x];
  3964. X    if (opt->flags & ArgHidden)
  3965. X        continue;
  3966. X    optstr = UsageString(opt);
  3967. X    len = strlen(optstr) + 3;    /* space [ string ] */
  3968. X    if (col + len > 79) {
  3969. X        (void) fprintf (stderr, "\r\n   ");  /* 3 spaces */
  3970. X        col = 3;
  3971. X    }
  3972. X    (void) fprintf (stderr, " [%s]", optstr);
  3973. X    col += len;
  3974. X    }
  3975. X
  3976. X    if (suppress_help_msg)
  3977. X    (void) fprintf(stderr, "\r\n\n");
  3978. X    else
  3979. X    (void) fprintf(stderr, 
  3980. X               "\r\n\nType \"%s %s\" for a full description.\r\n\n",
  3981. X               ProgramName, HELPSTR);
  3982. X}
  3983. X
  3984. X/*
  3985. X * HelpOptions - Print a nice help/usage message based on options.
  3986. X */
  3987. Xvoid HelpOptions(options, num_opts, message)
  3988. X     OptionDescRec *options;
  3989. X     int num_opts;
  3990. X     char **message;
  3991. X{
  3992. X    OptionDescRec *opt;
  3993. X    register int x;
  3994. X    char **cpp;
  3995. X
  3996. X    suppress_help_msg = 1;
  3997. X    UsageOptions(options, num_opts, (char *)NULL);
  3998. X    suppress_help_msg = 0;
  3999. X
  4000. X    (void) fprintf (stderr, "where options include:\n");
  4001. X    for (x = 0; x < num_opts; x++) {
  4002. X    opt = &options[x];
  4003. X    if (opt->flags & ArgHidden)
  4004. X        continue;
  4005. X    (void) fprintf (stderr, "    %-28s %s\n", UsageString(opt), 
  4006. X         (opt->desc) ? opt->desc : "");
  4007. X    if (opt->value && opt->cvtarg != OptBool)
  4008. X        (void) fprintf (stderr, "    %-28s [ Default value is %s ]\n", 
  4009. X                "", opt->value);
  4010. X    }
  4011. X
  4012. X    if (message) {
  4013. X    (void) putc ('\n', stderr);
  4014. X    for (cpp = message; *cpp; cpp++) {
  4015. X        (void) fputs (*cpp, stderr);
  4016. X        (void) putc ('\n', stderr);
  4017. X    }
  4018. X    (void) putc ('\n', stderr);
  4019. X    }
  4020. X}
  4021. X
  4022. X/*
  4023. X * UserError - Print a user error.
  4024. X */
  4025. X#ifdef HAS_VARARGS
  4026. Xvoid UserError(va_alist)
  4027. X     va_dcl
  4028. X{
  4029. X    va_list args;
  4030. X    char *fmt;
  4031. X
  4032. X    va_start(args);
  4033. X    if (ProgramName)
  4034. X    (void) fprintf(stderr, "%s: ", ProgramName);
  4035. X    fmt = (char *) va_arg(args, char *);
  4036. X    (void) vfprintf(stderr, fmt, args);
  4037. X    va_end(args);
  4038. X    (void) fprintf(stderr, "\n");
  4039. X}
  4040. X#else
  4041. Xvoid UserError(fmt, a1, a2, a3, a4, a5, a6)
  4042. X     char *fmt;
  4043. X{
  4044. X    if (ProgramName)
  4045. X    (void) fprintf(stderr, "%s: ", ProgramName);
  4046. X    (void) fprintf(stderr, fmt, a1, a2, a3, a4, a5, a6);
  4047. X    (void) fprintf(stderr, "\n");
  4048. X}
  4049. X#endif
  4050. X
  4051. XOptBool(opt, value, docopy)
  4052. X     OptionDescRec *opt;
  4053. X     caddr_t value;
  4054. X     int docopy; /*ARGSUSED*/
  4055. X{
  4056. X    char *vpp;
  4057. X
  4058. X    *(int *) opt->valp = (int) strtol(value, &vpp, 0);
  4059. X    if (*vpp) {
  4060. X    UserError("Invalid integer argument for '%s'.", opt->option);
  4061. X    return(FALSE);
  4062. X    } else {
  4063. X    return(TRUE);
  4064. X    }
  4065. X}
  4066. X
  4067. XOptInt(opt, value, docopy)
  4068. X     OptionDescRec *opt;
  4069. X     caddr_t value;
  4070. X     int docopy; /*ARGSUSED*/
  4071. X{
  4072. X    char *vpp;
  4073. X
  4074. X    *(int *) opt->valp = (int) strtol(value, &vpp, 0);
  4075. X    if (*vpp) {
  4076. X    UserError("Invalid integer argument for '%s'.", opt->option);
  4077. X    return(FALSE);
  4078. X    } else {
  4079. X    return(TRUE);
  4080. X    }
  4081. X}
  4082. X
  4083. XOptShort(opt, value, docopy)
  4084. X     OptionDescRec *opt;
  4085. X     caddr_t value;
  4086. X     int docopy; /*ARGSUSED*/
  4087. X{
  4088. X    char *vpp;
  4089. X
  4090. X    *(short *) opt->valp = (short) strtol(value, &vpp, 0);
  4091. X    if (*vpp) {
  4092. X    UserError("Invalid integer argument for '%s'.", opt->option);
  4093. X    return(FALSE);
  4094. X    } else {
  4095. X    return(TRUE);
  4096. X    }
  4097. X}
  4098. X
  4099. XOptLong(opt, value, docopy)
  4100. X     OptionDescRec *opt;
  4101. X     caddr_t value;
  4102. X     int docopy; /*ARGSUSED*/
  4103. X{
  4104. X    char *vpp;
  4105. X
  4106. X    *(long *) opt->valp = (long) strtol(value, &vpp, 0);
  4107. X    if (*vpp) {
  4108. X    UserError("Invalid integer argument for '%s'.", opt->option);
  4109. X    return(FALSE);
  4110. X    } else {
  4111. X    return(TRUE);
  4112. X    }
  4113. X}
  4114. X
  4115. XOptStr(opt, value, docopy)
  4116. X     OptionDescRec *opt;
  4117. X     caddr_t value;
  4118. X     int docopy;
  4119. X{
  4120. X    char *p;
  4121. X
  4122. X    if (docopy) {
  4123. X    if ((p = (char *) malloc((unsigned)strlen(value)+1)) == NULL) {
  4124. X        UserError("Cannot malloc memory: %s", SYSERR);
  4125. X        return(FALSE);
  4126. X    }
  4127. X    (void) strcpy(p, value);
  4128. X    } else {
  4129. X    p = value;
  4130. X    }
  4131. X
  4132. X    *(char **) opt->valp = p;
  4133. X
  4134. X    return(TRUE);
  4135. X}
  4136. X
  4137. Xstatic char *UsageString(opt)
  4138. X     OptionDescRec *opt;
  4139. X{
  4140. X    static char buf[BUFSIZ], buf2[BUFSIZ];
  4141. X
  4142. X    (void) sprintf(buf, opt->option);
  4143. X    (void) strcpy(buf2, "");
  4144. X    if (opt->usage) {
  4145. X    (void) sprintf(buf2, "%s%s%s%s",
  4146. X               ((opt->flags & StickyArg) && 
  4147. X            !((opt->flags & StickyArg) && (opt->flags & SepArg))) 
  4148. X               ? "" : " ",
  4149. X               (opt->value) ? "[" : "",
  4150. X               opt->usage,
  4151. X               (opt->value) ? "]" : ""
  4152. X               );
  4153. X    }
  4154. X    (void) strcat(buf, buf2);
  4155. X
  4156. X    return(buf);
  4157. X}
  4158. END_OF_options.c
  4159. if test 11038 -ne `wc -c <options.c`; then
  4160.     echo shar: \"options.c\" unpacked with wrong size!
  4161. fi
  4162. # end of overwriting check
  4163. fi
  4164. if test -f options.h -a "${1}" != "-c" ; then 
  4165.   echo shar: Will not over-write existing file \"options.h\"
  4166. else
  4167. echo shar: Extracting \"options.h\" \(2596 characters\)
  4168. sed "s/^X//" >options.h <<'END_OF_options.h'
  4169. X/*
  4170. X * Copyright (c) 1990 Michael A. Cooper.
  4171. X * This software may be freely distributed provided it is not sold for 
  4172. X * profit and the author is credited appropriately.
  4173. X */
  4174. X
  4175. X/*
  4176. X * $Header: /src/common/usc/lib/libgen/RCS/options.h,v 1.7 1990/12/15 18:13:30 mcooper Exp mcooper $
  4177. X *
  4178. X * $Log: options.h,v $
  4179. X * Revision 1.7  1990/12/15  18:13:30  mcooper
  4180. X * Add copywrite notice.
  4181. X *
  4182. X * Revision 1.6  90/11/13  15:28:39  mcooper
  4183. X * Add OptBool cvtarg routine.
  4184. X * 
  4185. X * Revision 1.5  90/10/29  19:34:03  mcooper
  4186. X * Fixed comment for NoArg.
  4187. X * 
  4188. X * Revision 1.4  90/10/29  18:48:43  mcooper
  4189. X * Cleanup some comments.
  4190. X * 
  4191. X * Revision 1.3  90/10/29  14:47:29  mcooper
  4192. X * UsageString is now a real function.
  4193. X * 
  4194. X * Revision 1.2  90/10/26  15:55:44  mcooper
  4195. X * Add defines for "__" and ArgHidden.
  4196. X * 
  4197. X * Revision 1.1  90/10/26  14:42:53  mcooper
  4198. X * Initial revision
  4199. X * 
  4200. X */
  4201. X
  4202. X
  4203. X#include <stdio.h>
  4204. X#include <sys/types.h>
  4205. X#include <sys/errno.h>
  4206. X
  4207. X#define Num_Opts(o)    (sizeof(o)/sizeof(OptionDescRec))
  4208. X#define HELPSTR        "-help"
  4209. X#define __        (caddr_t)
  4210. X
  4211. X#ifndef SYSERR
  4212. X#define SYSERR        sys_errlist[errno]
  4213. X#endif
  4214. X#ifndef TRUE
  4215. X#define TRUE    1
  4216. X#endif
  4217. X#ifndef FALSE
  4218. X#define FALSE    0
  4219. X#endif
  4220. X
  4221. X/*
  4222. X * Values for OptionDescRec.flags.
  4223. X */
  4224. X#define NoArg        0x001    /* No argument for this option.  Use
  4225. X                   OptionDescRec.value. */
  4226. X#define IsArg        0x002    /* Value is the option string itself */
  4227. X#define SepArg        0x004    /* Value is in next argument in argv */
  4228. X#define StickyArg    0x008    /* Value is characters immediately following 
  4229. X                   option */
  4230. X#define SkipArg        0x010    /* Ignore this option and the next argument in 
  4231. X                   argv */
  4232. X#define SkipLine    0x020    /* Ignore this option and the rest of argv */
  4233. X#define SkipNArgs    0x040    /* Ignore this option and the next 
  4234. X                   OptionDescRes.value arguments in argv */
  4235. X#define ArgHidden    0x080    /* Don't show in usage or help messages */
  4236. X
  4237. X/*
  4238. X * Option description record.
  4239. X */
  4240. Xtypedef struct {
  4241. X    char    *option;        /* Option string in argv        */
  4242. X    int         flags;            /* Flag bits                */
  4243. X    int        (*cvtarg)();        /* Function to convert argument     */
  4244. X    caddr_t     valp;            /* Variable to set            */
  4245. X    caddr_t     value;            /* Default value to provide        */
  4246. X    char    *usage;            /* Usage message            */
  4247. X    char    *desc;            /* Description message            */
  4248. X} OptionDescRec, *OptionDescList;
  4249. X
  4250. Xvoid UsageOptions();
  4251. Xvoid HelpOptions();
  4252. Xvoid UserError();
  4253. Xint ParseOptions();
  4254. XOptionDescRec *FindOption();
  4255. X
  4256. Xint OptBool();
  4257. Xint OptInt();
  4258. Xint OptLong();
  4259. Xint OptShort();
  4260. Xint OptStr();
  4261. X
  4262. Xextern char *OptionChars;
  4263. Xextern int errno;
  4264. Xextern char *sys_errlist[];
  4265. Xextern long strtol();
  4266. Xextern char *malloc();
  4267. Xextern char *strcpy();
  4268. END_OF_options.h
  4269. if test 2596 -ne `wc -c <options.h`; then
  4270.     echo shar: \"options.h\" unpacked with wrong size!
  4271. fi
  4272. # end of overwriting check
  4273. fi
  4274. if test -f system.h -a "${1}" != "-c" ; then 
  4275.   echo shar: Will not over-write existing file \"system.h\"
  4276. else
  4277. echo shar: Extracting \"system.h\" \(6582 characters\)
  4278. sed "s/^X//" >system.h <<'END_OF_system.h'
  4279. X/*
  4280. X * Copyright (c) 1992 Michael A. Cooper.
  4281. X * This software may be freely distributed provided it is not sold for 
  4282. X * profit and the author is credited appropriately.
  4283. X */
  4284. X
  4285. X/*
  4286. X * $Header: /src/common/usc/bin/sysinfo/RCS/system.h,v 1.23 1992/04/26 23:32:06 mcooper Exp $
  4287. X *
  4288. X * $Log: system.h,v $
  4289. X * Revision 1.23  1992/04/26  23:32:06  mcooper
  4290. X * Add Copyright notice
  4291. X *
  4292. X * Revision 1.22  1992/04/18  20:47:43  mcooper
  4293. X * Merge Solbourne stuff back into main "sun" area.
  4294. X *
  4295. X * Revision 1.20  1992/04/17  01:08:56  mcooper
  4296. X * BROKEN_NLIST_CHECK is no longer needed.
  4297. X *
  4298. X * Revision 1.19  1992/04/12  22:02:15  mcooper
  4299. X * - Add Tadpole support.
  4300. X * - Remove obsolete MODEL_SHIFTVAL.
  4301. X * - Update solbourne to current "sun" stuff.
  4302. X *
  4303. X * Revision 1.17  1992/03/31  02:44:32  mcooper
  4304. X * Add BROKEN_NLIST_CHECK to hp300.
  4305. X *
  4306. X * Revision 1.16  1992/03/22  00:27:11  mcooper
  4307. X * Remove obsolete items.
  4308. X *
  4309. X * Revision 1.15  1992/03/09  01:08:10  mcooper
  4310. X * Ultrix now has HAVE_MODELNAME.
  4311. X *
  4312. X * Revision 1.14  1992/03/08  23:10:27  mcooper
  4313. X * Add HAVE_PACKETFILTER to Ultrix.
  4314. X *
  4315. X * Revision 1.13  1992/03/08  04:56:17  mcooper
  4316. X * Add NEED_SOCKIO for suns and HAVE_IF_VERSION for ultrix.
  4317. X *
  4318. X * Revision 1.12  1992/03/06  18:39:55  mcooper
  4319. X * - Add HAVE_NLIST where needed.
  4320. X * - Add ultrix stuff for devices.
  4321. X * - Define HAVE_KVM if NEED_KVM is defined.
  4322. X *
  4323. X * Revision 1.11  1992/03/01  23:29:39  mcooper
  4324. X * Add new MODELNAME and ?ARCHNAME stuff.
  4325. X *
  4326. X * Revision 1.10  1992/02/27  00:09:36  mcooper
  4327. X * Update solbourne to have HAVE_MAINBUS and HAVE_OPENPROM.
  4328. X *
  4329. X * Revision 1.9  1992/02/22  02:18:44  mcooper
  4330. X * Add definitions for sun HAVE_MAINBUS and HAVE_OPENPROM.
  4331. X *
  4332. X * Revision 1.8  1992/02/17  01:00:14  mcooper
  4333. X * Update solbourne.
  4334. X *
  4335. X * Revision 1.7  1992/02/10  21:04:51  mcooper
  4336. X * - Add #ifdef's for HAVE_IPI
  4337. X * - Change sun #include <arch/cpu.h> to <machine/cpu.h
  4338. X * - Define SECSIZE, HAVE_DK_IOCTL, and HAVE_NIT.
  4339. X *
  4340. X * Revision 1.6  1991/10/09  03:37:17  mcooper
  4341. X * Add support for getting serial number
  4342. X * and model name directly from system on
  4343. X * Alliant FX80 series.
  4344. X *
  4345. X * Revision 1.5  1991/10/01  01:48:56  mcooper
  4346. X * Add HAVE_SERIALNUM for Alliant 2800.
  4347. X *
  4348. X * Revision 1.4  1991/09/30  05:28:34  mcooper
  4349. X * Set OSVERS_FROM_KERNVER correctly for alliant 2800.
  4350. X *
  4351. X * Revision 1.3  1991/09/30  05:21:57  mcooper
  4352. X * Add support for getting memory and model
  4353. X * number on Alliant 2800's.
  4354. X *
  4355. X * Revision 1.2  1991/09/30  04:48:10  mcooper
  4356. X * Don't need to define COFF for Sun386i
  4357. X * since it is predefined.
  4358. X *
  4359. X * Revision 1.1  1991/09/30  04:32:36  mcooper
  4360. X * Initial revision
  4361. X *
  4362. X */
  4363. X
  4364. X#ifndef __sysinfo_system__
  4365. X#define __sysinfo_system__
  4366. X
  4367. X/*
  4368. X * System dependant information
  4369. X */
  4370. X
  4371. X#if defined(sun)
  4372. X#    include <sys/param.h>
  4373. X#    include <sys/file.h>
  4374. X#    include <machine/cpu.h>
  4375. X    /*
  4376. X     * What manufacturer is this?
  4377. X     */
  4378. X#    if defined(TAD_SPBK_ARCH)
  4379. X#        define MAN_SHORT    "Tadpole"
  4380. X#        define MAN_LONG        "Tadpole Technology Inc"
  4381. X#        define TADPOLE
  4382. X#    elif defined(CPU_TYPE_SERIES4) || defined(CPU_TYPE_SERIES5) || \
  4383. X             defined(CPU_TYPE_SERIES5E) || defined(CPU_TYPE_SERIES6)
  4384. X#        define MAN_SHORT    "Solbourne"
  4385. X#        define MAN_LONG        "Solbourne Computer Corporation"
  4386. X#        define SOLBOURNE
  4387. X#    else
  4388. X#        define MAN_SHORT    "Sun"
  4389. X#        define MAN_LONG        "Sun Microsystems Incorporated"
  4390. X#        define HAVE_SUNROMVEC
  4391. X#    endif
  4392. X
  4393. X#    if defined(mc68020)
  4394. X#        define ARCH_TYPE     "sun3"
  4395. X#        define HAVE_IPI
  4396. X#        define HAVE_MAINBUS
  4397. X#    endif
  4398. X#    if defined(sparc)
  4399. X#        define ARCH_TYPE     "sun4"
  4400. X#        if !defined(TADPOLE) && !defined(SOLBOURNE)
  4401. X#            define HAVE_IPI
  4402. X#        endif
  4403. X#        if !defined(TADPOLE)
  4404. X#            define HAVE_MAINBUS
  4405. X#        endif
  4406. X#    endif
  4407. X#    if defined(i386)
  4408. X#        define ARCH_TYPE     "sun386"
  4409. X#        define HAVE_MAINBUS
  4410. X#    endif
  4411. X#    if defined(OPENPROMS)
  4412. X#        define HAVE_OPENPROM
  4413. X#    endif
  4414. X#    define NEED_SOCKIO
  4415. X#    define HAVE_IDMETHOD
  4416. X#    define HAVE_VARARGS
  4417. X#    define HAVE_UNAME
  4418. X#    define HAVE_KVM
  4419. X#    define HAVE_NLIST
  4420. X#    define HAVE_NIT
  4421. X#    define HAVE_KARCHNAME
  4422. X#    if !defined(SECSIZE)
  4423. X#        define SECSIZE    512        /* Size of a disk sector */
  4424. X#    endif
  4425. X#    define KERNSTR_END    '\n'
  4426. X/*
  4427. X * This is to get around an error on Sun386i's in <sun386/cpu.h>
  4428. X */
  4429. X#if defined(SUN386_ARCH) && !defined(I386_ARCH)
  4430. X#define I386_ARCH SUN386_ARCH
  4431. X#endif
  4432. X#endif /* sun */
  4433. X
  4434. X#if defined(ultrix) || defined(vax)
  4435. X#    if defined(ultrix)
  4436. X#        define HAVE_UNAME
  4437. X#        include <unistd.h>
  4438. X#    else
  4439. X#        include <sys/file.h>
  4440. X#        define OS_NAME    "BSD"
  4441. X#    endif
  4442. X#    define MAN_SHORT    "DEC"
  4443. X#    define MAN_LONG        "Digital Equipment Corporation"
  4444. X#    define HAVE_VARARGS
  4445. X#    define HAVE_UBA
  4446. X#    define HAVE_IF_VERSION
  4447. X#    define HAVE_PACKETFILTER
  4448. X#    define HAVE_NLIST
  4449. X#    define NEED_KVM
  4450. X#    define KERNSTR_END    '\n'
  4451. X#    if !defined(SECSIZE)
  4452. X#        define SECSIZE    512        /* Size of a disk sector */
  4453. X#    endif
  4454. X#endif /* ultrix || vax */
  4455. X
  4456. X#if defined(hp300)
  4457. X#    include <sys/file.h>
  4458. X#    include <sys/param.h>
  4459. X#    define MAN_SHORT    "HP"
  4460. X#    define MAN_LONG        "Hewlett Packard"
  4461. X#    define OS_NAME        "BSD"
  4462. X#    if defined(BSD) && BSD == 43
  4463. X#        define OS_VERSION    "4.3"
  4464. X#    endif
  4465. X#    define CPU_NAME        "MC68030"
  4466. X#    define HAVE_VARARGS
  4467. X#    define HAVE_NLIST
  4468. X#    define KERNSTR_END    '\n'
  4469. X#    define NEED_KVM
  4470. X#endif /* hp300 */
  4471. X
  4472. X#if defined(alliant)
  4473. X#    include <sys/file.h>
  4474. X#    define MAN_SHORT    "Alliant"
  4475. X#    define MAN_LONG        "Alliant Computer Corporation"
  4476. X#    if defined(i860)
  4477. X#        include <sys/alliant2800.h>
  4478. X#        define CPU_NAME        "i860"
  4479. X#        define ARCH_TYPE     "alliant2800"
  4480. X#        define OS_NAME        "Concentrix 2800"
  4481. X#        define HAVE_MODELNUM
  4482. X#        define HAVE_MEMORYSIZE
  4483. X#        define HAVE_SERIALNUM
  4484. X#        define OSVERS_FROM_KERNVER 4
  4485. X#    else
  4486. X#        include <sys/param.h>
  4487. X#        include <machine/vmparam.h>
  4488. X#        include <machine/bpb.h>
  4489. X#        define OS_NAME        "Concentrix"
  4490. X#        define ARCH_TYPE     "alliant"
  4491. X#        define HAVE_LIB_SYSCFG
  4492. X#        define HAVE_USERETC
  4493. X#        define OSVERS_FROM_KERNVER 3
  4494. X#    endif
  4495. X#    define HAVE_NLIST
  4496. X#    define NEED_KVM
  4497. X#endif /* alliant */
  4498. X
  4499. X#if defined(NeXT)
  4500. X#    include <sys/file.h>
  4501. X#    include <kern/mach_host.h>
  4502. X#    define MAN_SHORT    "NeXT"
  4503. X#    define MAN_LONG        "NeXT Computer"
  4504. X#    define OS_NAME        "NeXT Mach"
  4505. X#    define HAVE_VARARGS
  4506. X#    define HAVE_HOST_INFO
  4507. X#    define HAVE_KARCHNAME
  4508. X#    define HAVE_AARCHNAME
  4509. X#    define HAVE_NLIST
  4510. X#    define NEED_KVM
  4511. X#    define KERNSTR_END    ';'
  4512. X#    if !defined(mc68k)
  4513. X#        define mc68k
  4514. X#    endif
  4515. X#endif /* NeXT */
  4516. X
  4517. X#if defined(_AIX)
  4518. X#    include <sys/file.h>
  4519. X#    define MAN_SHORT    "IBM"
  4520. X#    define MAN_LONG        "International Business Machines Corporation"
  4521. X#    ifdef _IBMR2
  4522. X#        define CPU_NAME    "rios"
  4523. X#    endif
  4524. X#    define ARCH_TYPE    "rs6000"
  4525. X#    define KARCH_TYPE    ARCH_TYPE
  4526. X#    define HAVE_VARARGS
  4527. X#    define HAVE_UNAME
  4528. X#    define UNAME_REL_VER_COMB
  4529. X#    define HAVE_NLIST
  4530. X#    define NEED_KVM
  4531. X#endif /* _AIX */
  4532. X
  4533. X/*
  4534. X * Everything depends on HAVE_KVM
  4535. X */
  4536. X#if    defined(NEED_KVM) && !defined(HAVE_KVM)
  4537. X#define HAVE_KVM
  4538. X#endif
  4539. X
  4540. X#endif /* __sysinfo_system__ */
  4541. END_OF_system.h
  4542. if test 6582 -ne `wc -c <system.h`; then
  4543.     echo shar: \"system.h\" unpacked with wrong size!
  4544. fi
  4545. # end of overwriting check
  4546. fi
  4547. if test -f defs.h -a "${1}" != "-c" ; then 
  4548.   echo shar: Will not over-write existing file \"defs.h\"
  4549. else
  4550. echo shar: Extracting \"defs.h\" \(13978 characters\)
  4551. sed "s/^X//" >defs.h <<'END_OF_defs.h'
  4552. X/*
  4553. X * Copyright (c) 1992 Michael A. Cooper.
  4554. X * This software may be freely distributed provided it is not sold for 
  4555. X * profit and the author is credited appropriately.
  4556. X */
  4557. X
  4558. X/*
  4559. X * $Header: /src/common/usc/bin/sysinfo/RCS/defs.h,v 1.30 1992/04/26 23:32:06 mcooper Exp $
  4560. X *
  4561. X * $Log: defs.h,v $
  4562. X * Revision 1.30  1992/04/26  23:32:06  mcooper
  4563. X * Add Copyright notice
  4564. X *
  4565. X * Revision 1.29  1992/04/17  23:27:51  mcooper
  4566. X * Add support for ROM Version information (Sun only for now).
  4567. X *
  4568. X * Revision 1.28  1992/04/17  01:07:59  mcooper
  4569. X * More de-linting
  4570. X *
  4571. X * Revision 1.27  1992/04/16  02:25:39  mcooper
  4572. X * Bug fixes, de-linting, and other changes found with CodeCenter.
  4573. X *
  4574. X * Revision 1.26  1992/04/15  02:00:36  mcooper
  4575. X * Major re-write and simplification of command line options.
  4576. X *
  4577. X * Revision 1.25  1992/03/31  18:58:16  mcooper
  4578. X * Change "verbose" to "Show".
  4579. X *
  4580. X * Revision 1.24  1992/03/31  03:10:17  mcooper
  4581. X * Put frontend macro around CheckNlist() to avoid
  4582. X * broken things in Ultrix.
  4583. X *
  4584. X * Revision 1.23  1992/03/31  00:34:59  mcooper
  4585. X * Add new GetNlName() and GetNlNamePtr() macros.
  4586. X *
  4587. X * Revision 1.22  1992/03/31  00:15:55  mcooper
  4588. X * Make GetNlName() global.
  4589. X *
  4590. X * Revision 1.21  1992/03/28  22:01:16  mcooper
  4591. X * Add dd_slave to DEVDATA.
  4592. X *
  4593. X * Revision 1.20  1992/03/25  03:31:28  mcooper
  4594. X * Fix verbose flags.
  4595. X *
  4596. X * Revision 1.19  1992/03/25  03:18:52  mcooper
  4597. X * Convert verbosity levels to bit flags.
  4598. X *
  4599. X * Revision 1.18  1992/03/22  00:54:53  mcooper
  4600. X * Add GetNlName().
  4601. X *
  4602. X * Revision 1.17  1992/03/22  00:20:10  mcooper
  4603. X * Major cleanup and re-org.
  4604. X *
  4605. X * Revision 1.16  1992/03/08  05:00:40  mcooper
  4606. X * Remove obsolete NETIFTAB.
  4607. X *
  4608. X * Revision 1.15  1992/03/08  04:55:42  mcooper
  4609. X * Add support for address families and multiple addresses
  4610. X * per network interface.
  4611. X *
  4612. X * Revision 1.14  1992/03/06  18:36:06  mcooper
  4613. X * Add new NAMETAB to replace other similiar types.
  4614. X *
  4615. X * Revision 1.13  1992/03/03  03:18:59  mcooper
  4616. X * Seperate and cleanup KVM*() from kvm*().
  4617. X *
  4618. X * Revision 1.12  1992/03/01  23:29:19  mcooper
  4619. X * Move kvm_t to kvm.h.
  4620. X *
  4621. X * Revision 1.11  1992/03/01  22:51:02  mcooper
  4622. X * Add kvm_t structure.
  4623. X *
  4624. X * Revision 1.10  1992/03/01  21:34:07  mcooper
  4625. X * Put #ifdef HAVE_KVM around KVM_*() function declarations.
  4626. X *
  4627. X * Revision 1.9  1992/03/01  21:30:18  mcooper
  4628. X * Add dd_secsize to DISKDRIVE and add new MODELTAB.
  4629. X *
  4630. X * Revision 1.8  1992/02/27  22:01:22  mcooper
  4631. X * Add support for getting CPU info for sun4m.
  4632. X *
  4633. X * Revision 1.7  1992/02/27  02:42:33  mcooper
  4634. X * Cleanup.
  4635. X *
  4636. X * Revision 1.6  1992/02/25  00:59:35  mcooper
  4637. X * Move tape info to local MTINFO.
  4638. X *
  4639. X * Revision 1.5  1992/02/25  00:15:56  mcooper
  4640. X * Update DT_* and other misc.
  4641. X *
  4642. X * Revision 1.4  1992/02/22  02:20:19  mcooper
  4643. X * Major changes to support scanning kernel mainbus and
  4644. X * openprom data for device's.
  4645. X *
  4646. X * Revision 1.3  1992/02/16  23:50:23  mcooper
  4647. X * Add verbosity level macros.
  4648. X *
  4649. X * Revision 1.2  1992/02/16  23:03:51  mcooper
  4650. X * Declare extern verbose.
  4651. X *
  4652. X * Revision 1.1  1992/02/16  22:53:52  mcooper
  4653. X * Initial revision
  4654. X *
  4655. X */
  4656. X
  4657. X#ifndef __sysinfo_defs__
  4658. X#define __sysinfo_defs__ 
  4659. X
  4660. X/* Need to include options.h before errno.h */
  4661. X#include "options.h"
  4662. X#include <errno.h>
  4663. X#include "patchlevel.h"
  4664. X
  4665. X/*
  4666. X * Version of this program
  4667. X */
  4668. X#define VERSION_STR        "1.0"
  4669. X
  4670. X#if    defined(NEED_KVM)
  4671. X#include "kvm.h"
  4672. X#else
  4673. X#if    defined(HAVE_KVM)
  4674. X#include <kvm.h>
  4675. X#endif    /* HAVE_KVM */
  4676. X#endif    /* NEED_KVM */
  4677. X
  4678. X/*
  4679. X * File containing our CPU model name.  Overrides all other methods
  4680. X * for determing model name.
  4681. X */
  4682. X#ifndef MODELFILE
  4683. X#define MODELFILE         "/etc/sysmodel"
  4684. X#endif
  4685. X
  4686. X/*
  4687. X * System call failure value
  4688. X */
  4689. X#ifndef SYSFAIL
  4690. X#define SYSFAIL            -1
  4691. X#endif
  4692. X
  4693. X#define C_NULL            '\0'
  4694. X
  4695. X/*
  4696. X * System error numbers and message strings
  4697. X */
  4698. Xextern int errno;
  4699. X
  4700. X#ifdef SYSERR
  4701. X#undef SYSERR
  4702. X#endif
  4703. X
  4704. X#if    defined(HAVE_STRERROR)
  4705. X#define SYSERR            strerror(errno)
  4706. X#else
  4707. Xextern char *sys_errmsg[];
  4708. X#define SYSERR             sys_errlist[errno]
  4709. X#endif    /* HAVE_STRERROR */
  4710. X
  4711. X#ifndef MAXHOSTNAMLEN
  4712. X#define MAXHOSTNAMLEN         256
  4713. X#endif
  4714. X
  4715. X#define MBYTES            1048576            /* Megabytes */
  4716. X
  4717. X/*
  4718. X * Misc macros
  4719. X */
  4720. X#define EQ(a,b)            (strcasecmp(a,b)==0)
  4721. X#define EQN(a,b,n)        (strncasecmp(a,b,n)==0)
  4722. X
  4723. X/*
  4724. X * CheckNlist() breaks in a variety of ways on
  4725. X * various OS's.
  4726. X */
  4727. X#if     !defined(BROKEN_NLIST_CHECK)
  4728. X#define CheckNlist(p)         _CheckNlist(p)
  4729. X#else
  4730. X#define CheckNlist(p)         0
  4731. X#endif
  4732. X
  4733. X/*
  4734. X * Get nlist n_name
  4735. X */
  4736. X#if    defined(__MACH__)
  4737. X#define GetNlName(n)        (n.n_un.n_name)
  4738. X#define GetNlNamePtr(n)        (n->n_un.n_name)
  4739. X#else
  4740. X#define GetNlName(n)        (n.n_name)
  4741. X#define GetNlNamePtr(n)        (n->n_name)
  4742. X#endif    /* __MACH__ */
  4743. X
  4744. X/*
  4745. X * Conversion macros
  4746. X */
  4747. X#define bytes_to_mbytes(n)    ((float) n / (float) 1048576)
  4748. X#define bytes_to_kbytes(n)    ((u_long)(n / 1024))
  4749. X#define mbytes_to_bytes(n)    ((u_long)((u_long) n * 1048576))
  4750. X#define kbytes_to_mbytes(n)    ((u_long)((u_long) n * 1024))
  4751. X#define nsect_to_bytes(n,s)      ((((float) n) / (float) (1024 / s)) * 1024)
  4752. X
  4753. X/*
  4754. X * Are flags f set in b?
  4755. X */
  4756. X#define FLAGS_ON(b,f)        ((b != 0) && (b & f))
  4757. X
  4758. X/*
  4759. X * Verbosity levels
  4760. X */
  4761. X#define L_BRIEF            0x01        /* Briefest */
  4762. X#define L_GENERAL        0x02        /* General verbosity */
  4763. X#define L_DESC            0x04        /* Description info */
  4764. X#define L_CONFIG        0x10        /* Configuratin info */
  4765. X#define L_DEBUG            0x20        /* Debug info */
  4766. X#define L_ALL (L_BRIEF|L_GENERAL|L_DESC|L_CONFIG)
  4767. X/*
  4768. X * Verbosity macros
  4769. X */
  4770. X#define VL_BRIEF        (Level & L_BRIEF)
  4771. X#define VL_GENERAL        (Level & L_GENERAL)
  4772. X#define VL_DESC            (Level & L_DESC)
  4773. X#define VL_CONFIG        (Level & L_CONFIG)
  4774. X#define VL_ALL            (Level == L_ALL)
  4775. X#define VL_DEBUG        (Level & L_DEBUG)
  4776. X
  4777. X/*
  4778. X * Show info
  4779. X */
  4780. Xstruct ShowInfo {
  4781. X    int                Type;
  4782. X    char               *Name;
  4783. X    char               *Label;
  4784. X    void              (*ShowFunc)();
  4785. X    char             *(*GetFunc)();
  4786. X    int                   *OptCompat;
  4787. X    int                Enable;
  4788. X};
  4789. Xtypedef struct ShowInfo SHOWINFO;
  4790. X
  4791. X/*
  4792. X * ShowInfo types (ShowInfo.Type)
  4793. X */
  4794. X#define S_GEN            1        /* General info */
  4795. X#define S_DEV            2        /* Device info */
  4796. X
  4797. X/*
  4798. X * Main Device information
  4799. X *
  4800. X * Used after device info has been obtained 
  4801. X */
  4802. Xstruct _device {
  4803. X    char        *dv_name;        /* Name (e.g. cgtwo0) */
  4804. X    char           **dv_files;        /* Device files */
  4805. X    int             dv_type;        /* Device type (eg DT_TAPE) */
  4806. X    char        *dv_model;        /* Model */
  4807. X    char        *dv_desc;        /* Description */
  4808. X    int             dv_unit;        /* Unit number */
  4809. X    int             dv_addr;        /* Address */
  4810. X    int             dv_prio;        /* Priority */
  4811. X    int             dv_vec;        /* Vector */
  4812. X    char        *dv_mastername;        /* Name of master */
  4813. X    caddr_t        *dv_devspec;        /* Device specific info */
  4814. X    struct _device    *dv_master;        /* Device controller */
  4815. X    struct _device    *dv_slaves;        /* Devices on this device */
  4816. X    struct _device    *dv_nxt;        /* Pointer to next device */
  4817. X};
  4818. Xtypedef struct _device DEVICE;
  4819. X
  4820. X/*
  4821. X * Device types (DEVICE.dv_type)
  4822. X */
  4823. X#define DT_GENERIC         1        /* Generic Device */
  4824. X#define DT_DISKDRIVE         2        /* Disk Drive */
  4825. X#define DT_DISKCTLR         3        /* Disk Controller */
  4826. X#define DT_TAPEDRIVE         4        /* Tape Drive */
  4827. X#define DT_TAPECTLR         5        /* Tape Controller */
  4828. X#define DT_FRAMEBUFFER         6        /* Frame Buffer */
  4829. X#define DT_NETIF         7        /* Network Interface */
  4830. X#define DT_BUS             9        /* System Bus */
  4831. X#define DT_PSEUDO        10        /* Pseudo Device */
  4832. X#define DT_CPU            11        /* CPU */
  4833. X
  4834. X/*
  4835. X * Disk Partition information.
  4836. X */
  4837. Xstruct _dkpart {
  4838. X    char        *dp_name;        /* Partition name */
  4839. X    char        *dp_mnt;        /* Mount information */
  4840. X    int             dp_stsect;        /* Starting sector */
  4841. X    int             dp_nsect;        /* Number of sectors */
  4842. X    struct _dkpart    *dp_nxt;        /* Pointer to next DISKPART */
  4843. X};
  4844. Xtypedef struct _dkpart DISKPART;
  4845. X
  4846. X/*
  4847. X * Disk Drive specific data
  4848. X */
  4849. Xstruct _dkdrive {
  4850. X    char        *dd_label;        /* Disk label */
  4851. X    int             dd_unit;        /* Unit number */
  4852. X    int             dd_slave;        /* Slave number */
  4853. X    int             dd_dcyl;        /* # data cylinders */
  4854. X    int             dd_pcyl;        /* # physical cylinders */
  4855. X    int             dd_acyl;        /* # alternate cylinders */
  4856. X    int             dd_heads;        /* Number of heads */
  4857. X    int             dd_sect;        /* Number of sectors */
  4858. X    int             dd_psect;        /* Number of physical sector */
  4859. X    int             dd_promrev;        /* PROM Revision */
  4860. X    int             dd_apc;        /* Alternates / Cyl (SCSI) */
  4861. X    int             dd_rpm;        /* Revolutions Per Minute */
  4862. X    int             dd_intrlv;        /* Interleave factor */
  4863. X    int             dd_secsize;        /* Size of Sector (bytes) */
  4864. X    u_long         dd_size;        /* Size of disk in bytes */
  4865. X    int             dd_flags;        /* Info flags */
  4866. X    DEVICE        *dd_ctlr;        /* Controller disk is on */
  4867. X    struct _dkpart    *dd_part;        /* Partition information */
  4868. X    struct _dkdrive    *dd_nxt;        /* Pointer to next disk */
  4869. X};
  4870. Xtypedef struct _dkdrive DISKDRIVE;
  4871. X
  4872. X/*
  4873. X * Disk Flags (DISKDRIVE.dd_flags)
  4874. X */
  4875. X#define DF_HEXUNIT    0x01            /* Unit is prt 3 hex digits */
  4876. X
  4877. X/*
  4878. X * Generic Name/Value table
  4879. X */
  4880. Xstruct _nametab {
  4881. X    int            value;            /* Value field */
  4882. X    char                  *name;            /* Corresponding name */
  4883. X    char                  *valuestr;        /* Value string field */
  4884. X};
  4885. Xtypedef struct _nametab NAMETAB;
  4886. X
  4887. X/*
  4888. X * Disk Controller Table
  4889. X */
  4890. Xstruct dkctlrtab {
  4891. X    u_short             ct_ctype;    /* Ctlr type index */
  4892. X    char            *ct_model;    /* Ctlr model name */
  4893. X    int                 ct_rdcmd;    /* Read command flag */
  4894. X};
  4895. Xtypedef struct dkctlrtab DKCTLRTAB;
  4896. X
  4897. X/*
  4898. X * FrameBuffer specific data
  4899. X */
  4900. Xstruct _framebuffer {
  4901. X    int             fb_height;        /* Height (in pixels) */
  4902. X    int             fb_width;        /* Width (in pixels) */
  4903. X    int             fb_depth;        /* Depth (bits/pixel) */
  4904. X    u_long         fb_size;        /* Total size (in bytes) */
  4905. X    u_long         fb_vmsize;        /* Video memory (in bytes) */
  4906. X    int             fb_cmsize;        /* Color Map Size (#entries) */
  4907. X};
  4908. Xtypedef struct _framebuffer FRAMEBUFFER;
  4909. X
  4910. X/*
  4911. X * Network Interface specific data
  4912. X */
  4913. Xstruct _netif {
  4914. X    char        *ni_typename;        /* Name of address type */
  4915. X    char        *ni_hostaddr;        /* Host address */
  4916. X    char        *ni_hostname;        /* Host name */
  4917. X    char        *ni_macaddr;        /* MAC address */
  4918. X    char        *ni_macname;        /* MAC name */
  4919. X    char        *ni_netaddr;        /* Network address */
  4920. X    char        *ni_netname;        /* Network name */
  4921. X    struct _netif    *ni_nxt;        /* Pointer to next element */
  4922. X};
  4923. Xtypedef struct _netif NETIF;
  4924. X
  4925. X/*
  4926. X * Address family table
  4927. X */
  4928. Xstruct _aftab {
  4929. X    int            af_type;        /* Type value */
  4930. X    char           *af_name;        /* Name value */
  4931. X    NETIF         *(*af_getnetif)();        /* Function to get netif */
  4932. X};
  4933. Xtypedef struct _aftab AFTAB;
  4934. X
  4935. X/*
  4936. X * Table of devices
  4937. X */
  4938. Xstruct devicetab {
  4939. X    int             d_type;        /* Device type */
  4940. X    char           **d_list;        /* List of devices */
  4941. X    DEVICE          *(*d_query)();        /* Query function */
  4942. X};
  4943. X
  4944. X/*
  4945. X * Basic device data
  4946. X *
  4947. X * Used when searching for initial list of devices
  4948. X */
  4949. Xstruct _devdata {
  4950. X    char        *dd_devname;        /* Name of device */
  4951. X    int             dd_devunit;        /* Device specific unit # */
  4952. X    int             dd_slave;        /* Slave number */
  4953. X    char        *dd_ctlrname;        /* Name of Controller */
  4954. X    int             dd_ctlrunit;        /* Controller # */
  4955. X    int             dd_flags;        /* Device flags */
  4956. X};
  4957. Xtypedef struct _devdata DEVDATA;
  4958. X
  4959. X/*
  4960. X * Flags for DEVDATA.dd_flags
  4961. X */
  4962. X#define DD_MAYBE_ALIVE    0x1            /* Device may be alive */
  4963. X#define DD_IS_ALIVE    0x2            /* Device is alive */
  4964. X
  4965. X/*
  4966. X * Device Data Table structure
  4967. X */
  4968. Xstruct _devdatatab {
  4969. X    char        *ddt_name;        /* Name of device */
  4970. X    int             ddt_type;        /* Type of device */
  4971. X    char        *ddt_model;        /* Model */
  4972. X    char        *ddt_desc;        /* Description */
  4973. X    DEVICE          *(*ddt_probe)();        /* Probe device */
  4974. X};
  4975. Xtypedef struct _devdatatab DEVDATATAB;
  4976. X
  4977. X/*
  4978. X * Declarations
  4979. X */
  4980. Xextern int             DoPrintUnknown;
  4981. Xextern int             Debug;
  4982. Xextern int             Level;
  4983. X
  4984. Xchar                    *index();
  4985. Xchar                    *rindex();
  4986. Xchar                    *strdup();
  4987. Xchar                    *strcat();
  4988. Xchar                    *strtok();
  4989. X
  4990. Xchar                   *itoa();
  4991. Xchar                    *xmalloc();
  4992. Xchar                    *xcalloc();
  4993. X
  4994. Xextern DEVDATATAB           *GetDevDataTab();
  4995. Xextern DEVICE                *NewDevice();
  4996. Xextern DEVICE                *ProbeCPU();
  4997. Xextern DEVICE                *ProbeDiskDrive();
  4998. Xextern DEVICE                *ProbeFrameBuffer();
  4999. Xextern DEVICE                *ProbeGeneric();
  5000. Xextern DEVICE                *ProbeNetif();
  5001. Xextern DEVICE                *ProbeTapeDrive();
  5002. Xextern DEVICE                *MkMasterFromDevData();
  5003. Xextern DEVICE                *ProbeDevice();
  5004. Xextern DEVICE                *ProbeUnknown();
  5005. Xextern DISKDRIVE               *NewDiskDrive();
  5006. Xextern DISKPART             *NewDiskPart();
  5007. Xextern FRAMEBUFFER            *NewFrameBuffer();
  5008. Xextern NETIF                *NewNetif();
  5009. Xextern char               *GetHostName();
  5010. Xextern char               *GetKernArch();
  5011. Xextern char               *GetKernArchName();
  5012. Xextern char               *GetKernelVersionFromVersion();
  5013. Xextern char               *GetKernelVersionStr();
  5014. Xextern char               *GetModelName();
  5015. Xextern char               *GetNameTabName();
  5016. Xextern char               *GetOSNameStr();
  5017. Xextern char               *GetOSVersionStr();
  5018. Xextern char               *GetSerialNoStr();
  5019. Xextern char               *MkDevName();
  5020. Xextern char               *RunCmds();
  5021. Xextern char               *RunTestFiles();
  5022. Xextern char                *GetAppArchFromHostInfo();
  5023. Xextern char                *GetCpuTypeFromHostInfo();
  5024. Xextern char                *GetKernArchFromHostInfo();
  5025. Xextern char                *GetKernelVersionFromHostInfo();
  5026. Xextern char                *GetMemoryFromHostInfo();
  5027. Xextern char                *GetMemoryFromPhysmem();
  5028. Xextern char                *GetModelFromHostInfo();
  5029. Xextern char                *GetOSNameFromUname();
  5030. Xextern char                *GetOSVersionFromHostInfo();
  5031. Xextern char                *GetOSVersionFromKernVer();
  5032. Xextern char                *GetOSVersionFromUname();
  5033. Xextern char                *MkDevName();
  5034. Xextern char                *GetAppArch();    
  5035. Xextern char                *GetCPU();
  5036. Xextern char                *GetCharFile();
  5037. Xextern char                *GetHostAddrs();
  5038. Xextern char                *GetHostAliases();
  5039. Xextern char                *GetHostID();
  5040. Xextern char                *GetKernelVersion();
  5041. Xextern char                *GetMan();
  5042. Xextern char                *GetMemory();
  5043. Xextern char                *GetModel();
  5044. Xextern char                *GetOSName();
  5045. Xextern char                *GetOSVersion();
  5046. Xextern char                *GetRawFile();
  5047. Xextern char                *GetRomVer();
  5048. Xextern char                *GetSerialNo();
  5049. Xextern int                AddDevice();
  5050. Xextern void            Error();
  5051. Xextern void                ShowDevices();
  5052. Xextern void                 ShowGeneral();
  5053. X
  5054. X#if    defined(HAVE_KVM)
  5055. Xextern kvm_t                *KVM_open();
  5056. Xextern void            KVM_close();
  5057. Xextern int            KVM_read();
  5058. X#endif    /* HAVE_KVM */
  5059. X
  5060. X#endif /* __sysinfo_defs__ */
  5061. END_OF_defs.h
  5062. if test 13978 -ne `wc -c <defs.h`; then
  5063.     echo shar: \"defs.h\" unpacked with wrong size!
  5064. fi
  5065. # end of overwriting check
  5066. fi
  5067. if test -f netif.c -a "${1}" != "-c" ; then 
  5068.   echo shar: Will not over-write existing file \"netif.c\"
  5069. else
  5070. echo shar: Extracting \"netif.c\" \(9874 characters\)
  5071. sed "s/^X//" >netif.c <<'END_OF_netif.c'
  5072. X/*
  5073. X * Copyright (c) 1992 Michael A. Cooper.
  5074. X * This software may be freely distributed provided it is not sold for 
  5075. X * profit and the author is credited appropriately.
  5076. X */
  5077. X
  5078. X#ifndef lint
  5079. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/netif.c,v 1.18 1992/04/26 23:32:06 mcooper Exp $";
  5080. X#endif
  5081. X
  5082. X/*
  5083. X * $Log: netif.c,v $
  5084. X * Revision 1.18  1992/04/26  23:32:06  mcooper
  5085. X * Add Copyright notice
  5086. X *
  5087. X * Revision 1.17  1992/04/17  01:07:59  mcooper
  5088. X * More de-linting
  5089. X *
  5090. X * Revision 1.16  1992/04/16  02:25:39  mcooper
  5091. X * Bug fixes, de-linting, and other changes found with CodeCenter.
  5092. X *
  5093. X * Revision 1.15  1992/03/31  01:55:17  mcooper
  5094. X * Use new CheckNlist to check nlist success.
  5095. X *
  5096. X * Revision 1.14  1992/03/31  00:15:09  mcooper
  5097. X * Add error check for nlist.n_type.
  5098. X *
  5099. X * Revision 1.13  1992/03/28  21:29:38  mcooper
  5100. X * Initial port to NeXT.  Only works partially.
  5101. X *
  5102. X * Revision 1.12  1992/03/22  00:20:10  mcooper
  5103. X * Major cleanup and re-org.
  5104. X *
  5105. X * Revision 1.11  1992/03/09  01:24:05  mcooper
  5106. X * Remove HAVE_NIT stuff.
  5107. X *
  5108. X * Revision 1.10  1992/03/08  23:09:18  mcooper
  5109. X * - Cleanup set_macinfo() code to support Ultrix packetfilter.
  5110. X * - Pass device down to set_macinfo().
  5111. X *
  5112. X * Revision 1.9  1992/03/08  04:53:39  mcooper
  5113. X * Major re-write to clean things up and add better
  5114. X * support for multiple addresses per interface.
  5115. X *
  5116. X * Revision 1.8  1992/03/05  22:36:35  mcooper
  5117. X * Cleanup format.
  5118. X *
  5119. X * Revision 1.7  1992/03/05  22:11:02  mcooper
  5120. X * Cleanup variable declarations.
  5121. X *
  5122. X * Revision 1.6  1992/02/25  23:36:58  mcooper
  5123. X * Remove NULL garbage at end of source file.
  5124. X *
  5125. X * Revision 1.5  1992/02/25  03:08:43  mcooper
  5126. X * Fix gethostbyaddr() stuff for sun3/sun386.
  5127. X *
  5128. X * Revision 1.4  1992/02/25  00:16:57  mcooper
  5129. X * Use new mkmaster_from_devdata().
  5130. X *
  5131. X * Revision 1.3  1992/02/22  02:20:19  mcooper
  5132. X * Major changes to support scanning kernel mainbus and
  5133. X * openprom data for device's.
  5134. X *
  5135. X * Revision 1.2  1992/02/20  04:15:16  mcooper
  5136. X * Update known interfaces.
  5137. X *
  5138. X * Revision 1.1  1992/02/16  22:48:39  mcooper
  5139. X * Initial revision
  5140. X *
  5141. X */
  5142. X
  5143. X
  5144. X/*
  5145. X * Portions of code found in this file are based on the 4.3BSD 
  5146. X * netstat(8) program.
  5147. X */
  5148. X
  5149. X/*
  5150. X * Network Interface routines
  5151. X */
  5152. X
  5153. X#include <stdio.h>
  5154. X#include "system.h"
  5155. X
  5156. X#include <fcntl.h>
  5157. X#include <nlist.h>
  5158. X#include <sys/types.h>
  5159. X#include <sys/socket.h>
  5160. X#if    defined(NEED_SOCKIO)
  5161. X#include <sys/sockio.h>
  5162. X#endif    /* NEED_SOCKIO */
  5163. X#include <sys/param.h>
  5164. X#include <sys/errno.h>
  5165. X#include <net/if.h>
  5166. X#include <netinet/in.h>
  5167. X#include <netinet/in_var.h>
  5168. X#include <netinet/if_ether.h>
  5169. X#include <netdb.h>
  5170. X
  5171. X#include "defs.h"
  5172. X
  5173. X/*
  5174. X * Network Interface name list
  5175. X */
  5176. Xstruct nlist NetifNL[] = {
  5177. X#if    defined(COFF)
  5178. X    { "ifnet" },
  5179. X#else
  5180. X    { "_ifnet" },
  5181. X#endif    /* COFF */
  5182. X    { 0 },
  5183. X};
  5184. X
  5185. Xstatic struct netent            *GetNet();
  5186. Xstatic void             SetMacInfo();
  5187. X
  5188. X/*
  5189. X * Interface Address union
  5190. X */
  5191. Xunion {
  5192. X    struct ifaddr     ifa;
  5193. X    struct in_ifaddr     in;
  5194. X}                 ifaddr;
  5195. X
  5196. X/*
  5197. X * Create a DEVICE for a network interface.
  5198. X */
  5199. Xstatic DEVICE *CreateNetif(FullName, IfNet, DevData, DevDataTab)
  5200. X    char               *FullName;
  5201. X    struct ifnet               *IfNet;
  5202. X    DEVDATA               *DevData;
  5203. X    DEVDATATAB               *DevDataTab;
  5204. X{
  5205. X    DEVICE               *dev;
  5206. X
  5207. X    dev = NewDevice(NULL);
  5208. X
  5209. X    dev->dv_name     = strdup(FullName);
  5210. X    dev->dv_type     = DT_NETIF;
  5211. X    dev->dv_unit     = IfNet->if_unit;
  5212. X    dev->dv_master     = MkMasterFromDevData(DevData);
  5213. X
  5214. X#if    defined(HAVE_IF_VERSION)
  5215. X    if (IfNet->if_version && IfNet->if_version[0])
  5216. X    dev->dv_model     = strdup(IfNet->if_version);
  5217. X    else
  5218. X#endif    /* HAVE_IF_VERSION */
  5219. X    dev->dv_model     = DevDataTab->ddt_model;
  5220. X
  5221. X    dev->dv_desc     = DevDataTab->ddt_desc;
  5222. X
  5223. X    return(dev);
  5224. X}
  5225. X
  5226. X/*
  5227. X * Get NETIF for an Internet address
  5228. X */
  5229. Xextern NETIF *GetNetifINET(aftab)
  5230. X    AFTAB               *aftab;
  5231. X{
  5232. X    struct in_addr        in_addr;
  5233. X    struct netent            *np;
  5234. X    struct hostent            *hp;
  5235. X    struct sockaddr_in            *sin;
  5236. X    char               *inet_ntoa();
  5237. X    NETIF               *ni;
  5238. X
  5239. X    ni = NewNetif(NULL);
  5240. X
  5241. X    np = GetNet(htonl(ifaddr.in.ia_subnet), ifaddr.in.ia_subnetmask);
  5242. X    in_addr.s_addr = ntohl(ifaddr.in.ia_subnet);
  5243. X    ni->ni_netaddr = strdup(inet_ntoa(in_addr));
  5244. X    if (np)
  5245. X    ni->ni_netname = strdup(np->n_name);
  5246. X        
  5247. X    sin = (struct sockaddr_in *)&ifaddr.in.ia_addr;
  5248. X    ni->ni_hostaddr = strdup(inet_ntoa(sin->sin_addr));
  5249. X    hp = gethostbyaddr((char *) &(sin->sin_addr),
  5250. X               sizeof(struct in_addr),
  5251. X               AF_INET);
  5252. X    if (hp)
  5253. X    ni->ni_hostname = strdup(hp->h_name);
  5254. X
  5255. X    if (aftab)
  5256. X    ni->ni_typename = aftab->af_name;
  5257. X
  5258. X    return(ni);
  5259. X}
  5260. X
  5261. X/*
  5262. X * Get NETIF for an unknown address type
  5263. X */
  5264. Xextern NETIF *GetNetifUnknown(aftab)
  5265. X    AFTAB               *aftab;
  5266. X{
  5267. X    NETIF               *ni = NULL;
  5268. X
  5269. X    ni = NewNetif(NULL);
  5270. X    ni->ni_hostaddr = "<unknown>";
  5271. X    if (aftab) {
  5272. X    ni->ni_typename = aftab->af_name;
  5273. X    }
  5274. X
  5275. X    return(ni);
  5276. X}
  5277. X
  5278. X/*
  5279. X * Get an Address Family table entry
  5280. X */
  5281. Xstatic AFTAB *GetAFTab(type)
  5282. X    int                type;
  5283. X{
  5284. X    extern AFTAB        AFTab[];
  5285. X    register int        i;
  5286. X
  5287. X    for (i = 0; AFTab[i].af_name; ++i)
  5288. X    if (AFTab[i].af_type == type)
  5289. X        return(&AFTab[i]);
  5290. X
  5291. X    return((AFTAB *) NULL);
  5292. X}
  5293. X
  5294. X/*
  5295. X * Get a linked list of NETIF's for each address starting at 'startaddr'.
  5296. X */
  5297. Xstatic NETIF *GetNetifAddrs(kd, startaddr, FullName, Device)
  5298. X    kvm_t               *kd;
  5299. X    off_t            startaddr;
  5300. X    char               *FullName;
  5301. X    DEVICE               *Device;
  5302. X{
  5303. X    u_long            addr;
  5304. X    NETIF               *base = NULL;
  5305. X    register NETIF           *ni, *pni;
  5306. X    AFTAB               *paftab;
  5307. X
  5308. X    for (addr = startaddr; addr; addr = (off_t) ifaddr.ifa.ifa_next) {
  5309. X    /*
  5310. X     * Read the ifaddr structure from kernel space
  5311. X     */
  5312. X    if (KVM_read(kd, addr, (char *) &ifaddr, sizeof(ifaddr))) {
  5313. X        Error("cannot read if address");
  5314. X        continue;
  5315. X    }
  5316. X
  5317. X    /*
  5318. X     * Now get and call the Address Family specific routine
  5319. X     * to extract a NETIF.
  5320. X     */
  5321. X    if (paftab = GetAFTab(ifaddr.ifa.ifa_addr.sa_family)) {
  5322. X        if (ni = (*paftab->af_getnetif)(paftab))
  5323. X        SetMacInfo(FullName, ni, Device);
  5324. X    } else {
  5325. X        if (Debug) Error("Address family %d is not defined.", 
  5326. X                 ifaddr.ifa.ifa_addr.sa_family);
  5327. X        continue;
  5328. X    }
  5329. X
  5330. X    /*
  5331. X     * Add the new NETIF to the base of the linked list.
  5332. X     */
  5333. X    if (base) {
  5334. X        for (pni = base; pni && pni->ni_nxt; pni = pni->ni_nxt);
  5335. X        pni->ni_nxt = ni;
  5336. X    } else {
  5337. X        base = ni;
  5338. X    }
  5339. X    }
  5340. X
  5341. X    return(base);
  5342. X}
  5343. X
  5344. X/*
  5345. X * Find and set the MAC info
  5346. X */
  5347. Xstatic void SetMacInfo(DevName, NetIf, Device)
  5348. X    char                *DevName;
  5349. X    NETIF                *NetIf;
  5350. X    DEVICE               *Device;    /* ARGSUSED */
  5351. X{
  5352. X#if    defined(HAVE_NIT)
  5353. X    extern void         SetMacInfoNIT();
  5354. X
  5355. X    SetMacInfoNIT(DevName, NetIf);
  5356. X    return;
  5357. X#endif    /* HAVE_NIT */
  5358. X
  5359. X#if    defined(HAVE_PACKETFILTER)
  5360. X    extern void            SetMacInfoPacketFilter();
  5361. X
  5362. X    SetMacInfoPacketFilter(DevName, NetIf, Device);
  5363. X    return;
  5364. X#endif    /* HAVE_PACKETFILTER */
  5365. X}
  5366. X
  5367. X/*
  5368. X * Return the netent of the network whose address is given.
  5369. X * The address is assumed to be that of a net or subnet, not a host.
  5370. X */
  5371. Xstatic struct netent *GetNet(inaddr, mask)
  5372. X    u_long             inaddr;
  5373. X    u_long             mask;
  5374. X{
  5375. X    u_long             net;
  5376. X    register u_long         i, netaddr;
  5377. X    int             subnetshift;
  5378. X    static struct in_addr     in;
  5379. X
  5380. X    if (in.s_addr = ntohl(inaddr)) {
  5381. X    i = in.s_addr;
  5382. X    if (mask == 0) {
  5383. X        if (IN_CLASSA(i)) {
  5384. X        mask = IN_CLASSA_NET;
  5385. X        subnetshift = 8;
  5386. X        } else if (IN_CLASSB(i)) {
  5387. X        mask = IN_CLASSB_NET;
  5388. X        subnetshift = 8;
  5389. X        } else {
  5390. X        mask = IN_CLASSC_NET;
  5391. X        subnetshift = 4;
  5392. X        }
  5393. X        /*
  5394. X         * If there are more bits than the standard mask
  5395. X         * would suggest, subnets must be in use.
  5396. X         * Guess at the subnet mask, assuming reasonable
  5397. X         * width subnet fields.
  5398. X         */
  5399. X        while (in.s_addr &~ mask)
  5400. X        mask = (long)mask >> subnetshift;
  5401. X    }
  5402. X    net = in.s_addr & mask;
  5403. X    while ((mask & 1) == 0)
  5404. X        mask >>= 1, net >>= 1;
  5405. X    netaddr = net;
  5406. X    } else {
  5407. X    netaddr = inaddr;
  5408. X    }
  5409. X
  5410. X    return(getnetbyaddr(netaddr, AF_INET));
  5411. X}
  5412. X
  5413. X/*
  5414. X * Query/find network interface devices and add them to devicelist
  5415. X */
  5416. Xextern DEVICE *ProbeNetif(name, DevData, DevDataTab)
  5417. X    char                *name;
  5418. X    DEVDATA                *DevData;
  5419. X    DEVDATATAB                *DevDataTab;
  5420. X{
  5421. X    DEVICE                *dev = NULL;
  5422. X    static struct ifnet         ifnet;
  5423. X    static char         ifname[16], FullName[17];
  5424. X    register char           *p;
  5425. X    u_long                 ifnetaddr;
  5426. X    kvm_t                *kd;
  5427. X
  5428. X    if (!(kd = KVM_open(NetifNL))) {
  5429. X    if (Debug) Error("Cannot read ifnet from kernel");
  5430. X    return((DEVICE *) NULL);
  5431. X    }
  5432. X
  5433. X    /*
  5434. X     * See if we got a valid entry
  5435. X     */
  5436. X    if (CheckNlist(&NetifNL[0]))
  5437. X    return((DEVICE *) NULL);
  5438. X
  5439. X    /*
  5440. X     * Read address of ifnet structure from kernel space
  5441. X     */
  5442. X    if (KVM_read(kd, NetifNL[0].n_value, (char *) &ifnetaddr, 
  5443. X         sizeof(ifnetaddr))) {
  5444. X    if (Debug) Error("kvm_read ifnetaddr failed");
  5445. X    KVM_close(kd);
  5446. X    return((DEVICE *) NULL);
  5447. X    }
  5448. X
  5449. X    /*
  5450. X     * Read and then check each ifnet entry we found.
  5451. X     */
  5452. X    for (; ifnetaddr; ifnetaddr = (off_t) ifnet.if_next) {
  5453. X    /*
  5454. X     * Read the ifnet structure
  5455. X     */
  5456. X    if (KVM_read(kd, ifnetaddr, (char *)&ifnet, sizeof(ifnet))) {
  5457. X        if (Debug) Error("kvm_read ifnetaddr ifnet failed");
  5458. X        continue;
  5459. X    }
  5460. X
  5461. X    /*
  5462. X     * Read if_name from kernel space
  5463. X     */
  5464. X    if (KVM_read(kd, (u_long)ifnet.if_name, ifname, sizeof(ifname))) {
  5465. X        if (Debug) Error("kvm_read ifname failed");
  5466. X        continue;
  5467. X    }
  5468. X
  5469. X    /*
  5470. X     * Copy if_name to 'FullName' and add unit number
  5471. X     */
  5472. X    strncpy(FullName, ifname, sizeof(ifname));
  5473. X    p = (char *) index(FullName, C_NULL);
  5474. X    *p++ = ifnet.if_unit + '0';
  5475. X    *p = C_NULL;
  5476. X    ifname[sizeof(ifname)-1] = C_NULL;
  5477. X
  5478. X    /*
  5479. X     * Check to see if this is the interface we want.
  5480. X     */
  5481. X    if (!EQ(FullName, name))
  5482. X        continue;
  5483. X
  5484. X    /*
  5485. X     * Create and set device
  5486. X     */
  5487. X    dev = CreateNetif(FullName, &ifnet, DevData, DevDataTab);
  5488. X
  5489. X    /*
  5490. X     * Get and set address info
  5491. X     */
  5492. X    if (ifnet.if_addrlist) {
  5493. X        NETIF            *ni;
  5494. X
  5495. X        if (ni = GetNetifAddrs(kd, (off_t) ifnet.if_addrlist, 
  5496. X                   FullName, dev))
  5497. X        dev->dv_devspec = (caddr_t *) ni;
  5498. X    }
  5499. X    }
  5500. X
  5501. X    KVM_close(kd);
  5502. X
  5503. X    return(dev);
  5504. X}
  5505. END_OF_netif.c
  5506. if test 9874 -ne `wc -c <netif.c`; then
  5507.     echo shar: \"netif.c\" unpacked with wrong size!
  5508. fi
  5509. # end of overwriting check
  5510. fi
  5511. if test -f info-netif.c -a "${1}" != "-c" ; then 
  5512.   echo shar: Will not over-write existing file \"info-netif.c\"
  5513. else
  5514. echo shar: Extracting \"info-netif.c\" \(2385 characters\)
  5515. sed "s/^X//" >info-netif.c <<'END_OF_info-netif.c'
  5516. X/*
  5517. X * Copyright (c) 1992 Michael A. Cooper.
  5518. X * This software may be freely distributed provided it is not sold for 
  5519. X * profit and the author is credited appropriately.
  5520. X */
  5521. X/*
  5522. X * Copyright (c) 1992 Michael A. Cooper.
  5523. X * This software may be freely distributed provided it is not sold for 
  5524. X * profit and the author is credited appropriately.
  5525. X */
  5526. X#ifndef lint
  5527. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/info-netif.c,v 1.3 1992/04/26 23:32:06 mcooper Exp $";
  5528. X#endif
  5529. X
  5530. X/*
  5531. X * $Log: info-netif.c,v $
  5532. X * Revision 1.3  1992/04/26  23:32:06  mcooper
  5533. X * Add Copyright notice
  5534. X *
  5535. X * Revision 1.2  1992/03/22  00:20:10  mcooper
  5536. X * Major cleanup and re-org.
  5537. X *
  5538. X * Revision 1.1  1992/03/08  04:55:33  mcooper
  5539. X * Initial revision
  5540. X *
  5541. X */
  5542. X
  5543. X/*
  5544. X * This file contains information specific to network interfaces that
  5545. X * will need periodic updating.
  5546. X */
  5547. X
  5548. X#include <stdio.h>
  5549. X#include "system.h"
  5550. X#include "defs.h"
  5551. X
  5552. X#include <sys/types.h>
  5553. X#include <sys/socket.h>
  5554. X
  5555. X/*
  5556. X * Address family table
  5557. X */
  5558. XNETIF *GetNetifINET();
  5559. XNETIF *GetNetifUnknown();
  5560. X
  5561. XAFTAB AFTab[] = {
  5562. X#ifdef AF_INET
  5563. X    {  AF_INET,        "Internet",        GetNetifINET },
  5564. X#endif
  5565. X#ifdef AF_UNSPEC
  5566. X    {  AF_UNSPEC,    "Unspecified",        GetNetifUnknown },
  5567. X#endif
  5568. X#ifdef AF_DECnet
  5569. X    {  AF_DECnet,    "DECnet",        GetNetifUnknown },
  5570. X#endif
  5571. X#ifdef AF_LAT
  5572. X    {  AF_LAT,        "LAT",            GetNetifUnknown },
  5573. X#endif
  5574. X#ifdef AF_GOSIP
  5575. X    {  AF_GOSIP,    "GOSIP",        GetNetifUnknown },
  5576. X#endif
  5577. X#ifdef AF_PUP
  5578. X    {  AF_PUP,        "PUP",            GetNetifUnknown },
  5579. X#endif
  5580. X#ifdef AF_CHAOS
  5581. X    {  AF_CHAOS,    "CHAOS",        GetNetifUnknown },
  5582. X#endif
  5583. X#ifdef AF_NS
  5584. X    {  AF_NS,        "XEROX NS",        GetNetifUnknown },
  5585. X#endif
  5586. X#ifdef AF_NBS
  5587. X    {  AF_NBS,        "NBS",            GetNetifUnknown },
  5588. X#endif
  5589. X#ifdef AF_ECMA
  5590. X    {  AF_ECMA,        "ECMA",            GetNetifUnknown },
  5591. X#endif
  5592. X#ifdef AF_DATAKIT
  5593. X    {  AF_DATAKIT,    "DATAKIT",        GetNetifUnknown },
  5594. X#endif
  5595. X#ifdef AF_CCITT
  5596. X    {  AF_CCITT,    "CCITT",        GetNetifUnknown },
  5597. X#endif
  5598. X#ifdef AF_LYLINK
  5599. X    {  AF_LYLINK,    "LYLINK",        GetNetifUnknown },
  5600. X#endif
  5601. X#ifdef AF_APPLETALK
  5602. X    {  AF_APPLETALK,    "APPLETALK",        GetNetifUnknown },
  5603. X#endif
  5604. X#ifdef AF_BSC
  5605. X    {  AF_BSC,        "BSC",            GetNetifUnknown },
  5606. X#endif
  5607. X#ifdef AF_DSS
  5608. X    {  AF_DSS,        "DSS",            GetNetifUnknown },
  5609. X#endif
  5610. X#ifdef AF_OSI
  5611. X    {  AF_OSI,        "OSI",            GetNetifUnknown },
  5612. X#endif
  5613. X#ifdef AF_NETMAN
  5614. X    {  AF_NETMAN,    "NETMAN",        GetNetifUnknown },
  5615. X#endif
  5616. X#ifdef AF_X25
  5617. X    {  AF_X25,        "X25",            GetNetifUnknown },
  5618. X#endif
  5619. X    {  0 },
  5620. X};
  5621. X
  5622. END_OF_info-netif.c
  5623. if test 2385 -ne `wc -c <info-netif.c`; then
  5624.     echo shar: \"info-netif.c\" unpacked with wrong size!
  5625. fi
  5626. # end of overwriting check
  5627. fi
  5628. if test -f os-mach.c -a "${1}" != "-c" ; then 
  5629.   echo shar: Will not over-write existing file \"os-mach.c\"
  5630. else
  5631. echo shar: Extracting \"os-mach.c\" \(3462 characters\)
  5632. sed "s/^X//" >os-mach.c <<'END_OF_os-mach.c'
  5633. X/*
  5634. X * Copyright (c) 1992 Michael A. Cooper.
  5635. X * This software may be freely distributed provided it is not sold for 
  5636. X * profit and the author is credited appropriately.
  5637. X */
  5638. X
  5639. X#ifndef lint
  5640. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/os-mach.c,v 1.4 1992/04/26 23:32:06 mcooper Exp $";
  5641. X#endif
  5642. X
  5643. X/*
  5644. X * $Log: os-mach.c,v $
  5645. X * Revision 1.4  1992/04/26  23:32:06  mcooper
  5646. X * Add Copyright notice
  5647. X *
  5648. X * Revision 1.3  1992/04/17  01:07:59  mcooper
  5649. X * More de-linting
  5650. X *
  5651. X * Revision 1.2  1992/03/22  01:05:09  mcooper
  5652. X * Major cleanup and re-org.
  5653. X *
  5654. X * Revision 1.1  1992/03/01  23:28:16  mcooper
  5655. X * Initial revision
  5656. X *
  5657. X */
  5658. X
  5659. X/*
  5660. X * Mach specific functions
  5661. X */
  5662. X
  5663. X#include <stdio.h>
  5664. X#include "system.h"
  5665. X#include "defs.h"
  5666. X
  5667. X#if    defined(HAVE_HOST_INFO)
  5668. X#include <sys/host_info.h>
  5669. X
  5670. X/*
  5671. X * Use the host_info() call to obtain type of CPU.
  5672. X */
  5673. Xextern char *GetCpuTypeFromHostInfo()
  5674. X{
  5675. X    extern NAMETAB         CpuTypeTab[];
  5676. X    struct host_basic_info     basic_info;
  5677. X    unsigned int         count = HOST_BASIC_INFO_COUNT;
  5678. X    register int         i;
  5679. X
  5680. X    if (host_info(host_self(), HOST_BASIC_INFO, 
  5681. X          (host_info_t) &basic_info, &count) != KERN_SUCCESS) {
  5682. X    return((char *)NULL);
  5683. X    }
  5684. X
  5685. X    for (i = 0; CpuTypeTab[i].name; ++i) {
  5686. X    if (CpuTypeTab[i].value == basic_info.cpu_type)
  5687. X        return(CpuTypeTab[i].name);
  5688. X    }
  5689. X
  5690. X    return((char *) NULL);
  5691. X}
  5692. X
  5693. X/*
  5694. X * Use the host_info() call to obtain the model of CPU.
  5695. X */
  5696. Xextern char *GetModelFromHostInfo()
  5697. X{
  5698. X    extern NAMETAB         ModelTabMach[];
  5699. X    struct host_basic_info     basic_info;
  5700. X    unsigned int         count = HOST_BASIC_INFO_COUNT;
  5701. X    register int         i;
  5702. X
  5703. X    if (host_info(host_self(), HOST_BASIC_INFO, 
  5704. X          (host_info_t) &basic_info, &count) != KERN_SUCCESS) {
  5705. X    return((char *)NULL);
  5706. X    }
  5707. X
  5708. X    for (i = 0; ModelTabMach[i].name; ++i) {
  5709. X    if (ModelTabMach[i].value == basic_info.cpu_subtype)
  5710. X        return(ModelTabMach[i].name);
  5711. X    }
  5712. X
  5713. X    return((char *) NULL);
  5714. X}
  5715. X
  5716. X/*
  5717. X * Get our application architecture name.
  5718. X */
  5719. Xextern char *GetAppArchFromHostInfo()
  5720. X{
  5721. X    return(GetCpuTypeFromHostInfo());
  5722. X}
  5723. X
  5724. X/*
  5725. X * Get our kernel architecture name.
  5726. X */
  5727. Xextern char *GetKernArchFromHostInfo()
  5728. X{
  5729. X    return(GetCpuTypeFromHostInfo());
  5730. X}
  5731. X
  5732. X/*
  5733. X * Get amount of memory.
  5734. X */
  5735. Xextern char *GetMemoryFromHostInfo()
  5736. X{
  5737. X    struct host_basic_info     BasicInfo;
  5738. X    unsigned int         count = HOST_BASIC_INFO_COUNT;
  5739. X    static char            Buf[BUFSIZ];
  5740. X    int                Amount = -1;
  5741. X
  5742. X    if (host_info(host_self(), HOST_BASIC_INFO, 
  5743. X          (host_info_t) &BasicInfo, &count) == KERN_SUCCESS) {
  5744. X    Amount = BasicInfo.memory_size / MBYTES;
  5745. X    (void) sprintf(Buf, "%d MB", Amount);
  5746. X    return(Buf);
  5747. X    } else
  5748. X    return((char *) NULL);
  5749. X}
  5750. X
  5751. X/*
  5752. X * Get kernel version string.
  5753. X */
  5754. Xextern char *GetKernelVersionFromHostInfo()
  5755. X{
  5756. X    static char         Version[BUFSIZ];
  5757. X    register char            *p;
  5758. X
  5759. X    Version[0] = C_NULL;
  5760. X    if (host_kernel_version(host_self(), Version) != KERN_SUCCESS) {
  5761. X    if (Debug) Error("host_kernel_version() failed: %s.\n", SYSERR);
  5762. X    }
  5763. X
  5764. X#if    defined(KERNSTR_END)
  5765. X    if (Version[0])
  5766. X    if ((p = index(Version, KERNSTR_END)) != NULL)
  5767. X        *p = C_NULL;
  5768. X#endif    /* KERNSTR_END */
  5769. X
  5770. X    return((Version[0]) ? Version : (char *) NULL);
  5771. X}
  5772. X
  5773. X/*
  5774. X * Get OS version
  5775. X */
  5776. Xextern char *GetOSVersionFromHostInfo()
  5777. X{
  5778. X    static char            Buf[BUFSIZ];
  5779. X    struct machine_info     Info;
  5780. X
  5781. X    if (xxx_host_info(host_self(), (machine_info_t) &Info) == KERN_SUCCESS) {
  5782. X    (void) sprintf(Buf, "%d.%d", Info.major_version, Info.minor_version);
  5783. X    return(Buf);
  5784. X    }
  5785. X
  5786. X    return((char *) NULL);
  5787. X}
  5788. X
  5789. X#endif    /* HAVE_HOST_INFO */
  5790. END_OF_os-mach.c
  5791. if test 3462 -ne `wc -c <os-mach.c`; then
  5792.     echo shar: \"os-mach.c\" unpacked with wrong size!
  5793. fi
  5794. # end of overwriting check
  5795. fi
  5796. if test -f info-mach.c -a "${1}" != "-c" ; then 
  5797.   echo shar: Will not over-write existing file \"info-mach.c\"
  5798. else
  5799. echo shar: Extracting \"info-mach.c\" \(4077 characters\)
  5800. sed "s/^X//" >info-mach.c <<'END_OF_info-mach.c'
  5801. X/*
  5802. X * Copyright (c) 1992 Michael A. Cooper.
  5803. X * This software may be freely distributed provided it is not sold for 
  5804. X * profit and the author is credited appropriately.
  5805. X */
  5806. X
  5807. X#ifndef lint
  5808. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/info-mach.c,v 1.4 1992/04/26 23:32:06 mcooper Exp $";
  5809. X#endif
  5810. X
  5811. X/*
  5812. X * $Log: info-mach.c,v $
  5813. X * Revision 1.4  1992/04/26  23:32:06  mcooper
  5814. X * Add Copyright notice
  5815. X *
  5816. X * Revision 1.3  1992/03/22  01:05:09  mcooper
  5817. X * Major cleanup and re-org.
  5818. X *
  5819. X * Revision 1.3  1992/03/22  01:05:09  mcooper
  5820. X * Major cleanup and re-org.
  5821. X *
  5822. X * Revision 1.2  1992/03/22  00:20:10  mcooper
  5823. X * Major cleanup and re-org.
  5824. X *
  5825. X * Revision 1.1  1992/03/01  23:28:16  mcooper
  5826. X * Initial revision
  5827. X *
  5828. X */
  5829. X
  5830. X/*
  5831. X * Mach specific information
  5832. X */
  5833. X
  5834. X#include <stdio.h>
  5835. X#include "system.h"
  5836. X#include "defs.h"
  5837. X
  5838. X/*
  5839. X * Table of system models
  5840. X */
  5841. XNAMETAB ModelTabMach[] = {
  5842. X#if    defined(vax)
  5843. X#ifdef CPU_SUBTYPE_VAX780
  5844. X    {  CPU_SUBTYPE_VAX780,        "VAX-11/780" },
  5845. X#endif
  5846. X#ifdef CPU_SUBTYPE_VAX785
  5847. X    {  CPU_SUBTYPE_VAX785,        "VAX-11/785" },
  5848. X#endif
  5849. X#ifdef CPU_SUBTYPE_VAX750
  5850. X    {  CPU_SUBTYPE_VAX750,        "VAX-11/750" },
  5851. X#endif
  5852. X#ifdef CPU_SUBTYPE_VAX730
  5853. X    {  CPU_SUBTYPE_VAX730,        "VAX-11/730" },
  5854. X#endif
  5855. X#ifdef CPU_SUBTYPE_UVAXI
  5856. X    {  CPU_SUBTYPE_UVAXI,        "MicroVAX-I" },
  5857. X#endif
  5858. X#ifdef CPU_SUBTYPE_UVAXII
  5859. X    {  CPU_SUBTYPE_UVAXII,        "MicroVAX-II" },
  5860. X#endif
  5861. X#ifdef CPU_SUBTYPE_VAX8200
  5862. X    {  CPU_SUBTYPE_VAX8200,        "VAX-8200" },
  5863. X#endif
  5864. X#ifdef CPU_SUBTYPE_VAX8500
  5865. X    {  CPU_SUBTYPE_VAX8500,        "VAX-8500" },
  5866. X#endif
  5867. X#ifdef CPU_SUBTYPE_VAX8600
  5868. X    {  CPU_SUBTYPE_VAX8600,        "VAX-8600" },
  5869. X#endif
  5870. X#ifdef CPU_SUBTYPE_VAX8650
  5871. X    {  CPU_SUBTYPE_VAX8650,        "VAX-8650" },
  5872. X#endif
  5873. X#ifdef CPU_SUBTYPE_VAX8800
  5874. X    {  CPU_SUBTYPE_VAX8800,        "VAX-8800" },
  5875. X#endif
  5876. X#ifdef CPU_SUBTYPE_UVAXIII
  5877. X    {  CPU_SUBTYPE_UVAXIII,        "MicroVAX-III" },
  5878. X#endif
  5879. X#endif    /* vax */
  5880. X#if    defined(ibm)
  5881. X#ifdef CPU_SUBTYPE_RT_PC
  5882. X    {  CPU_SUBTYPE_RT_PC,        "RT/PC" },
  5883. X#endif
  5884. X#ifdef CPU_SUBTYPE_RT_APC
  5885. X    {  CPU_SUBTYPE_RT_APC,        "RT/APC" },
  5886. X#endif
  5887. X#ifdef CPU_SUBTYPE_RT_135
  5888. X    {  CPU_SUBTYPE_RT_135,        "RT/135" },
  5889. X#endif
  5890. X#endif    /* ibm */
  5891. X#if    defined(mips)
  5892. X#ifdef CPU_SUBTYPE_MIPS_R2300
  5893. X    {  CPU_SUBTYPE_MIPS_R2300,        "MIPS R2300" },
  5894. X#endif
  5895. X#ifdef CPU_SUBTYPE_MIPS_R2600
  5896. X    {  CPU_SUBTYPE_MIPS_R2600,        "MIPS R2600" },
  5897. X#endif
  5898. X#ifdef CPU_SUBTYPE_MIPS_R2800
  5899. X    {  CPU_SUBTYPE_MIPS_R2800,        "MIPS R2800" },
  5900. X#endif
  5901. X#ifdef CPU_SUBTYPE_MIPS_R2000a
  5902. X    {  CPU_SUBTYPE_MIPS_R2000a,        "MIPS R2000a" },
  5903. X#endif
  5904. X#endif    /* mips */
  5905. X#if    defined(mc68k)
  5906. X#ifdef CPU_SUBTYPE_MC68030
  5907. X    {  CPU_SUBTYPE_MC68030,        "MC68030" },
  5908. X#endif
  5909. X#ifdef CPU_SUBTYPE_MC68040
  5910. X    {  CPU_SUBTYPE_MC68040,        "MC68040" },
  5911. X#endif
  5912. X#endif    /* mc68k */
  5913. X#if    defined(hp)
  5914. X#ifdef CPU_SUBTYPE_HPPA_825
  5915. X    {  CPU_SUBTYPE_HPPA_825,        "9000/825" },
  5916. X#endif
  5917. X#ifdef CPU_SUBTYPE_HPPA_835
  5918. X    {  CPU_SUBTYPE_HPPA_835,        "9000/835" },
  5919. X#endif
  5920. X#ifdef CPU_SUBTYPE_HPPA_840
  5921. X    {  CPU_SUBTYPE_HPPA_840,        "9000/840" },
  5922. X#endif
  5923. X#ifdef CPU_SUBTYPE_HPPA_850
  5924. X    {  CPU_SUBTYPE_HPPA_850,        "9000/850" },
  5925. X#endif
  5926. X#ifdef CPU_SUBTYPE_HPPA_855
  5927. X    {  CPU_SUBTYPE_HPPA_855,        "9000/855" },
  5928. X#endif
  5929. X#endif    /* hp */
  5930. X#if    defined(sun)
  5931. X#ifdef CPU_SUBTYPE_SUN4_260
  5932. X    {  CPU_SUBTYPE_SUN4_260,        "4/200" },
  5933. X#endif
  5934. X#ifdef CPU_SUBTYPE_SUN4_110
  5935. X    {  CPU_SUBTYPE_SUN4_110,        "4/110" },
  5936. X#endif
  5937. X#endif    /* sun */
  5938. X    {  0 },
  5939. X};
  5940. X
  5941. X/*
  5942. X * Table of CPU Types
  5943. X */
  5944. XNAMETAB CpuTypeTab[] = {
  5945. X#ifdef CPU_TYPE_VAX
  5946. X    {  CPU_TYPE_VAX,            "VAX" },
  5947. X#endif
  5948. X#ifdef CPU_TYPE_ROMP
  5949. X    {  CPU_TYPE_ROMP,            "ROMP" },
  5950. X#endif
  5951. X#ifdef CPU_TYPE_NS32032
  5952. X    {  CPU_TYPE_NS32032,        "NS32032" },
  5953. X#endif
  5954. X#ifdef CPU_TYPE_NS32332
  5955. X    {  CPU_TYPE_NS32332,        "NS32332" },
  5956. X#endif
  5957. X#ifdef CPU_TYPE_MC680x0
  5958. X    {  CPU_TYPE_MC680x0,        "MC680X0" },
  5959. X#endif
  5960. X#ifdef CPU_TYPE_I386
  5961. X    {  CPU_TYPE_I386,            "i386" },
  5962. X#endif
  5963. X#ifdef CPU_TYPE_NS32532
  5964. X    {  CPU_TYPE_NS32532,        "NS32532" },
  5965. X#endif
  5966. X#ifdef CPU_TYPE_HPPA
  5967. X    {  CPU_TYPE_HPPA,            "HPPA" },
  5968. X#endif
  5969. X#ifdef CPU_TYPE_ARM
  5970. X    {  CPU_TYPE_ARM,            "ARM" },
  5971. X#endif
  5972. X#ifdef CPU_TYPE_MC88000
  5973. X    {  CPU_TYPE_MC88000,        "MC88000" },
  5974. X#endif
  5975. X#ifdef CPU_TYPE_SPARC
  5976. X    {  CPU_TYPE_SPARC,            "SPARC" },
  5977. X#endif
  5978. X    {  0 },
  5979. X};
  5980. END_OF_info-mach.c
  5981. if test 4077 -ne `wc -c <info-mach.c`; then
  5982.     echo shar: \"info-mach.c\" unpacked with wrong size!
  5983. fi
  5984. # end of overwriting check
  5985. fi
  5986. if test -f os-sunos.c -a "${1}" != "-c" ; then 
  5987.   echo shar: Will not over-write existing file \"os-sunos.c\"
  5988. else
  5989. echo shar: Extracting \"os-sunos.c\" \(38554 characters\)
  5990. sed "s/^X//" >os-sunos.c <<'END_OF_os-sunos.c'
  5991. X/*
  5992. X * Copyright (c) 1992 Michael A. Cooper.
  5993. X * This software may be freely distributed provided it is not sold for 
  5994. X * profit and the author is credited appropriately.
  5995. X */
  5996. X
  5997. X#ifndef lint
  5998. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/os-sunos.c,v 1.30 1992/04/26 23:51:53 mcooper Exp $";
  5999. X#endif
  6000. X
  6001. X/*
  6002. X * $Log: os-sunos.c,v $
  6003. X * Revision 1.30  1992/04/26  23:51:53  mcooper
  6004. X * Add some comments.
  6005. X *
  6006. X * Revision 1.28  1992/04/19  23:17:46  mcooper
  6007. X * Suppress CodeCenter warning about "romp".
  6008. X *
  6009. X * Revision 1.27  1992/04/19  23:07:23  mcooper
  6010. X * Update GetRomVer() to be more portable.
  6011. X *
  6012. X * Revision 1.26  1992/04/18  20:48:18  mcooper
  6013. X * Add #ifdef HAVE_SUNROMVEC around GetRomVer.
  6014. X *
  6015. X * Revision 1.25  1992/04/17  23:27:51  mcooper
  6016. X * Add support for ROM Version information (Sun only for now).
  6017. X *
  6018. X * Revision 1.24  1992/04/17  01:07:59  mcooper
  6019. X * More de-linting
  6020. X *
  6021. X * Revision 1.23  1992/04/16  02:25:39  mcooper
  6022. X * Bug fixes, de-linting, and other changes found with CodeCenter.
  6023. X *
  6024. X * Revision 1.22  1992/04/15  02:46:34  mcooper
  6025. X * - Add better MainBus() and OPENPROM() build debug messages.
  6026. X * - Make GetKernArchName() use "cpu" kernel symbol like GetModelName().
  6027. X *
  6028. X * Revision 1.21  1992/04/15  02:02:17  mcooper
  6029. X * Change GetMemoryStr() to GetMemory().
  6030. X *
  6031. X * Revision 1.20  1992/04/12  22:03:56  mcooper
  6032. X * - Change GetModelName() to use kernel symbol "cpu" instead
  6033. X *   of gethostid() to be more portable to other SPARC clones.
  6034. X * - Update GetKernArchName() to support Solbourne CPU_TYPE.
  6035. X * - Add HAVE_IPI kludge for "id" disks.
  6036. X * - Various other cleanup bits.
  6037. X *
  6038. X * Revision 1.19  1992/03/31  01:55:17  mcooper
  6039. X * Use new CheckNlist to check nlist success.
  6040. X *
  6041. X * Revision 1.18  1992/03/31  00:45:27  mcooper
  6042. X * Fixed GetKernArchName() to use CPU_ARCH mask.
  6043. X *
  6044. X * Revision 1.17  1992/03/31  00:15:09  mcooper
  6045. X * Add error check for nlist.n_type.
  6046. X *
  6047. X * Revision 1.16  1992/03/25  03:28:32  mcooper
  6048. X * Skip partitions that have 0 size.
  6049. X *
  6050. X * Revision 1.15  1992/03/25  03:20:14  mcooper
  6051. X * Only read partition info we we're going to print it later.
  6052. X *
  6053. X * Revision 1.14  1992/03/22  00:20:10  mcooper
  6054. X * Major cleanup and re-org.
  6055. X *
  6056. X * Revision 1.13  1992/03/09  01:23:42  mcooper
  6057. X * Add need include files for NIT stuff.
  6058. X *
  6059. X * Revision 1.12  1992/03/08  04:58:30  mcooper
  6060. X * Move probe_generic() to devices.c.
  6061. X *
  6062. X * Revision 1.11  1992/03/06  18:37:26  mcooper
  6063. X * Move some general functions to devices.c.
  6064. X *
  6065. X * Revision 1.10  1992/03/05  22:36:35  mcooper
  6066. X * Cleanup format.
  6067. X *
  6068. X * Revision 1.9  1992/03/05  05:12:10  mcooper
  6069. X * Cleanup build_mainbus().
  6070. X *
  6071. X * Revision 1.8  1992/03/01  23:30:15  mcooper
  6072. X * More more SunOS specific code from sysinfo.c to here.
  6073. X *
  6074. X * Revision 1.7  1992/02/27  22:01:22  mcooper
  6075. X * Add support for getting CPU info for sun4m.
  6076. X *
  6077. X * Revision 1.6  1992/02/27  20:36:52  mcooper
  6078. X * Remove \n from error() messages.
  6079. X *
  6080. X * Revision 1.5  1992/02/26  19:07:21  mcooper
  6081. X * Add a debug statement.
  6082. X *
  6083. X * Revision 1.4  1992/02/25  00:59:35  mcooper
  6084. X * Move tape info to local MTINFO.
  6085. X *
  6086. X * Revision 1.3  1992/02/25  00:17:45  mcooper
  6087. X * Lots of fixes and changes.
  6088. X *
  6089. X * Revision 1.2  1992/02/22  02:30:29  mcooper
  6090. X * Fix fbtab stuff.
  6091. X *
  6092. X * Revision 1.1  1992/02/22  02:20:19  mcooper
  6093. X * Initial revision
  6094. X *
  6095. X * Revision 1.5  1992/02/19  22:30:44  mcooper
  6096. X * Fix calling problem.
  6097. X *
  6098. X * Revision 1.4  1992/02/17  01:00:23  mcooper
  6099. X * - More portability and support for solbourne.
  6100. X *
  6101. X * Revision 1.3  1992/02/17  00:24:22  mcooper
  6102. X * Update frame buffers.
  6103. X *
  6104. X * Revision 1.2  1992/02/16  22:55:44  mcooper
  6105. X * Add netif support.
  6106. X *
  6107. X * Revision 1.1  1991/11/30  23:28:53  mcooper
  6108. X * Initial revision
  6109. X *
  6110. X */
  6111. X
  6112. X#include <stdio.h>
  6113. X#include "system.h"
  6114. X#include "defs.h"
  6115. X
  6116. X#include <mntent.h>
  6117. X#include <nlist.h>
  6118. X#include <sys/param.h>
  6119. X#include <sys/types.h>
  6120. X#include <sys/buf.h>
  6121. X#include <sys/stat.h>
  6122. X#include <sys/mtio.h>
  6123. X#include <sun/dkio.h>
  6124. X#include <sun/dklabel.h>
  6125. X#include <sun/fbio.h>
  6126. X
  6127. X/*
  6128. X * Name of frame buffer "indirect" device.
  6129. X */
  6130. X#define FBDEVICE    "fb"
  6131. X
  6132. X/*
  6133. X * Name of generic magnetic tape device.
  6134. X */
  6135. X#define MTNAME        "mt"
  6136. X
  6137. X/*
  6138. X * Generally used variables
  6139. X */
  6140. Xstatic kvm_t             *kd = NULL;
  6141. Xstatic struct stat          StatBuf;
  6142. Xstatic DEVICE             *Device;
  6143. Xstatic char              Buf[BUFSIZ];
  6144. X
  6145. X#if    defined(HAVE_MAINBUS)
  6146. X/*
  6147. X * Build a device tree by searching the MainBus
  6148. X */
  6149. X#include <sundev/mbvar.h>
  6150. X
  6151. X#define DV_SIZE    (sizeof(struct mb_device))
  6152. X#define DR_SIZE (sizeof(struct mb_driver))
  6153. X
  6154. X/*
  6155. X * Build device tree by looking at mainbus (mb) devices
  6156. X */
  6157. Xstatic int BuildMainBus(TreePtr)
  6158. X    DEVICE                **TreePtr;
  6159. X{
  6160. X    extern struct nlist      MainBusNL[];
  6161. X    static struct mb_device      Device;
  6162. X    static struct mb_driver      Driver;
  6163. X    static char          CtlrName[BUFSIZ], DevName[BUFSIZ];
  6164. X    static DEVDATA          DevData;
  6165. X    u_long              Addr, DeviceAddr;
  6166. X    DEVICE             *Dev;
  6167. X
  6168. X    /*
  6169. X     * Read table address from kernel
  6170. X     */
  6171. X    if (!(kd = KVM_open(MainBusNL))) {
  6172. X    if (Debug) Error("Cannot open & nlist mainbus device table.");
  6173. X    return(-1);
  6174. X    }
  6175. X
  6176. X    /*
  6177. X     * See if we got a valid entry
  6178. X     */
  6179. X    if (CheckNlist(&MainBusNL[0]))
  6180. X    return(-1);
  6181. X
  6182. X    /*
  6183. X     * Read each device table entry.  A NULL device.mb_driver
  6184. X     * indicates that we're at the end of the table.
  6185. X     */
  6186. X    for (DeviceAddr = MainBusNL[0].n_value; DeviceAddr; 
  6187. X     DeviceAddr += DV_SIZE) {
  6188. X
  6189. X    /*
  6190. X     * Read this device
  6191. X     */
  6192. X    if (KVM_read(kd, DeviceAddr, (char *) &Device, DV_SIZE)) {
  6193. X        if (Debug) 
  6194. X        Error("Cannot read mainbus device from address 0x%x.", 
  6195. X              DeviceAddr);
  6196. X        KVM_close(kd);
  6197. X        return(-1);
  6198. X    }
  6199. X
  6200. X    /*
  6201. X     * See if we're done.
  6202. X     */
  6203. X    if (!Device.md_driver)
  6204. X        break;
  6205. X
  6206. X    /*
  6207. X     * Read the driver structure
  6208. X     */
  6209. X    Addr = (u_long) Device.md_driver;
  6210. X    if (KVM_read(kd, Addr, (char *) &Driver, DR_SIZE)) {
  6211. X        if (Debug) 
  6212. X        Error("Cannot read driver for mainbus address 0x%x.", Addr);
  6213. X        continue;
  6214. X    }
  6215. X
  6216. X    /*
  6217. X     * Get the device name
  6218. X     */
  6219. X    if (Addr = (u_long) Driver.mdr_dname) {
  6220. X        if (KVM_read(kd, Addr, (char *) DevName, sizeof(DevName))) {
  6221. X        if (Debug)
  6222. X            Error("Cannot read device name from address 0x%x.", Addr);
  6223. X        continue;
  6224. X        }
  6225. X    } else
  6226. X        DevName[0] = C_NULL;
  6227. X
  6228. X    /*
  6229. X     * Get the controller name
  6230. X     */
  6231. X    if (Addr = (u_long) Driver.mdr_cname) {
  6232. X        if (KVM_read(kd, Addr, (char *) CtlrName, sizeof(CtlrName))) {
  6233. X        if (Debug)
  6234. X            Error(
  6235. X              "Cannot read controller name from address 0x%x.", Addr);
  6236. X        continue;
  6237. X        }
  6238. X    } else
  6239. X        CtlrName[0] = C_NULL;
  6240. X
  6241. X    /* Make sure devdata is clean */
  6242. X    bzero(&DevData, sizeof(DEVDATA));
  6243. X
  6244. X    /* Set what we know */
  6245. X    if (DevName[0]) {
  6246. X        DevData.dd_devname = strdup(DevName);
  6247. X        DevData.dd_devunit = Device.md_unit;
  6248. X    }
  6249. X    if (CtlrName[0]) {
  6250. X        DevData.dd_ctlrname = strdup(CtlrName);
  6251. X        DevData.dd_ctlrunit = Device.md_ctlr;
  6252. X    }
  6253. X    /* 
  6254. X     * Mainbus devices such, as SCSI targets, may not exist
  6255. X     * but the controller reports them as present
  6256. X     */
  6257. X    if (Device.md_alive)
  6258. X        DevData.dd_flags |= DD_MAYBE_ALIVE;
  6259. X
  6260. X    if (Debug)
  6261. X        printf("MainBus: Found \"%s\" (Unit %d) on \"%s\" (Unit %d) %s\n", 
  6262. X           DevData.dd_devname, DevData.dd_devunit,
  6263. X           DevData.dd_ctlrname, DevData.dd_ctlrunit,
  6264. X           (DevData.dd_flags & DD_MAYBE_ALIVE) ? "[MAYBE-ALIVE]" : "");
  6265. X
  6266. X    /* Probe and add device */
  6267. X    if (Dev = ProbeDevice(&DevData, TreePtr))
  6268. X        AddDevice(Dev, TreePtr);
  6269. X    }
  6270. X
  6271. X    KVM_close(kd);
  6272. X    return(0);
  6273. X}
  6274. X#endif    /* HAVE_MAINBUS */
  6275. X
  6276. X#if     defined(HAVE_OPENPROM)
  6277. X/*
  6278. X * OpenPROM stuff
  6279. X */
  6280. X#include <sun/openprom.h>
  6281. X
  6282. X/*
  6283. X * Build device tree by looking at OpenPROM (op)
  6284. X */
  6285. Xstatic int BuildOpenPROM(TreePtr)
  6286. X    DEVICE               **TreePtr;
  6287. X{
  6288. X    static struct dev_info     Root, *PtrRoot;
  6289. X    extern struct nlist     OpenPROMNL[];
  6290. X    u_long             Addr;
  6291. X
  6292. X    if (!(kd = KVM_open(OpenPROMNL))) {
  6293. X    if (Debug) Error("Cannot open kernel and read openprom devinfo");
  6294. X    return(-1);
  6295. X    }
  6296. X
  6297. X    /*
  6298. X     * See if we got a valid entry
  6299. X     */
  6300. X    if (CheckNlist(&OpenPROMNL[0]))
  6301. X    return(-1);
  6302. X
  6303. X    /*
  6304. X     * Read pointer to "top_devinfo" from kernel
  6305. X     */
  6306. X    Addr = OpenPROMNL[0].n_value;
  6307. X    if (KVM_read(kd, Addr, (char *) &PtrRoot, sizeof(struct dev_info *))) {
  6308. X    if (Debug) Error("Cannot read openprom devinfo pointer from kernel");
  6309. X    return(-1);
  6310. X    }
  6311. X
  6312. X    if (KVM_read(kd, (u_long)PtrRoot, (char *)&Root, 
  6313. X         sizeof(struct dev_info))) {
  6314. X    if (Debug) Error("Cannot read openprom devinfo root from kernel");
  6315. X    return(-1);
  6316. X    }
  6317. X
  6318. X    return(OpenPROMTraverse(&Root, NULL, TreePtr));
  6319. X}
  6320. X
  6321. X/*
  6322. X * Check an OpenPROM device.
  6323. X */
  6324. Xstatic int CheckOpenPROMDevice(DevInfo, Parent, TreePtr)
  6325. X    struct dev_info         *DevInfo;
  6326. X    struct dev_info         *Parent;
  6327. X    DEVICE                **TreePtr;
  6328. X{
  6329. X    static DEVDATA          DevData;
  6330. X    DEVICE             *Device;    
  6331. X
  6332. X    /* Make sure devdata is clean */
  6333. X    bzero(&DevData, sizeof(DEVDATA));
  6334. X
  6335. X    /* Set what we know */
  6336. X    if (DevInfo && DevInfo->devi_name) {
  6337. X    DevData.dd_devname = DevInfo->devi_name;
  6338. X    DevData.dd_devunit = DevInfo->devi_unit;
  6339. X    }
  6340. X    if (Parent && Parent->devi_name) {
  6341. X    DevData.dd_ctlrname = Parent->devi_name;
  6342. X    DevData.dd_ctlrunit = Parent->devi_unit;
  6343. X    }
  6344. X    /* 
  6345. X     * OpenPROM nodes that have a driver ALWAYS exist.
  6346. X     * Some nodes may exist, without a driver, however.
  6347. X     */
  6348. X    if (DevInfo->devi_driver)
  6349. X    DevData.dd_flags |= DD_IS_ALIVE;
  6350. X
  6351. X    if (Debug)
  6352. X    printf("OPENPROM: Found \"%s\" (Unit %d) on \"%s\" (Unit %d) %s\n", 
  6353. X           DevData.dd_devname, DevData.dd_devunit,
  6354. X           DevData.dd_ctlrname, DevData.dd_ctlrunit,
  6355. X           (DevData.dd_flags & DD_IS_ALIVE) ? "[ALIVE]" : "");
  6356. X
  6357. X    /* Probe and add device */
  6358. X    if (Device = (DEVICE *) ProbeDevice(&DevData, TreePtr))
  6359. X    AddDevice(Device, TreePtr);
  6360. X}
  6361. X
  6362. X/*
  6363. X * Recursively traverse and descend the OpenPROM devinfo tree.
  6364. X */
  6365. Xstatic int OpenPROMTraverse(DevPtr, Parent, TreePtr)
  6366. X    struct dev_info         *DevPtr;
  6367. X    struct dev_info         *Parent;
  6368. X    DEVICE                **TreePtr;
  6369. X{
  6370. X    static char          Name[BUFSIZ];
  6371. X    struct dev_info         *Ptr;
  6372. X
  6373. X    /*
  6374. X     * If node name is a valid pointer, read the name from kernel space
  6375. X     * and call openprom_probe to handle checking the device.
  6376. X     */
  6377. X    if (DevPtr->devi_name) {
  6378. X    if (KVM_read(kd, (u_long) DevPtr->devi_name, (char *) Name, 
  6379. X             sizeof(Name))) {
  6380. X        Error("Cannot read openprom device name.");
  6381. X        Name[0] = C_NULL;
  6382. X    } else {
  6383. X        DevPtr->devi_name = (char *) strdup(Name);
  6384. X        CheckOpenPROMDevice(DevPtr, Parent, TreePtr);
  6385. X    }
  6386. X    }
  6387. X
  6388. X    /*
  6389. X     * If this node has slaves, read the slave data from kernel space
  6390. X     * and descend.
  6391. X     */
  6392. X    if (DevPtr->devi_slaves) {
  6393. X    Ptr = (struct dev_info *) xcalloc(1, sizeof(struct dev_info));
  6394. X    if (KVM_read(kd, (u_long) DevPtr->devi_slaves, (char *) Ptr,
  6395. X             sizeof(struct dev_info))) {
  6396. X        Error("Cannot read openprom slave data for %s.", Name);
  6397. X    } else {
  6398. X        DevPtr->devi_slaves = (struct dev_info *) Ptr;
  6399. X        OpenPROMTraverse(DevPtr->devi_slaves, DevPtr, TreePtr);
  6400. X    }
  6401. X    }
  6402. X
  6403. X    /*
  6404. X     * If this node has a next pointer, read the next data from kernel space
  6405. X     * and traverse.
  6406. X     */
  6407. X    if (DevPtr->devi_next) {
  6408. X    Ptr = (struct dev_info *) xcalloc(1, sizeof(struct dev_info));
  6409. X    if (KVM_read(kd, (u_long) DevPtr->devi_next, (char *) Ptr,
  6410. X             sizeof(struct dev_info))) {
  6411. X        Error("Cannot read openprom next data for %s.", Name);
  6412. X    } else {
  6413. X        DevPtr->devi_next = (struct dev_info *) Ptr;
  6414. X        OpenPROMTraverse(DevPtr->devi_next, Parent, TreePtr);
  6415. X    }
  6416. X    }
  6417. X
  6418. X    return(0);
  6419. X}
  6420. X#endif /* HAVE_OPENPROM */
  6421. X
  6422. X/*
  6423. X * Build device tree using TreePtr.
  6424. X * Calls bus and method specific functions to
  6425. X * search for devices.
  6426. X */
  6427. Xextern int BuildDevicesSunOS(TreePtr)
  6428. X    DEVICE                **TreePtr;
  6429. X{
  6430. X    int              Found = 1;
  6431. X
  6432. X#if    defined(HAVE_OPENPROM)
  6433. X    if (BuildOpenPROM(TreePtr) == 0)
  6434. X    Found = 0;
  6435. X#endif    /* HAVE_OPENPROM */
  6436. X
  6437. X#if    defined(HAVE_MAINBUS)
  6438. X    if (BuildMainBus(TreePtr) == 0)
  6439. X    Found = 0;
  6440. X#endif    /* HAVE_MAINBUS */
  6441. X
  6442. X    return(Found);
  6443. X}
  6444. X
  6445. X/*
  6446. X * Scan the Disk Controller table looking for
  6447. X * a specific type.
  6448. X */
  6449. Xstatic DKCTLRTAB *GetDkCtlrTab(DkCtrlType)
  6450. X    int             DkCtrlType;
  6451. X{
  6452. X    extern DKCTLRTAB         DkCtlrTab[];
  6453. X    register int         i;
  6454. X
  6455. X    for (i = 0; DkCtlrTab[i].ct_model; ++i) {
  6456. X    if (DkCtrlType == DkCtlrTab[i].ct_ctype)
  6457. X        return(&DkCtlrTab[i]);
  6458. X    }
  6459. X
  6460. X    return((DKCTLRTAB *) NULL);
  6461. X}
  6462. X
  6463. X/*
  6464. X * Scan the Frame Buffer table looking for 
  6465. X * a specific fb type.
  6466. X */
  6467. Xstatic NAMETAB *GetFBTab(FBType)
  6468. X    int             FBType;
  6469. X{
  6470. X    extern NAMETAB         FBTab[];
  6471. X    register int         i;
  6472. X
  6473. X    for (i = 0; FBTab[i].name; ++i) {
  6474. X    if (FBType == FBTab[i].value)
  6475. X        return(&FBTab[i]);
  6476. X    }
  6477. X
  6478. X    return((NAMETAB *) NULL);
  6479. X}
  6480. X
  6481. X/*
  6482. X * Get disk info structure.
  6483. X */
  6484. Xstatic struct dk_info *GETdk_info(d, file)
  6485. X    int             d;
  6486. X    char                *file;
  6487. X{
  6488. X    static struct dk_info     dk_info;
  6489. X
  6490. X    if (ioctl(d, DKIOCINFO, &dk_info) < 0) {
  6491. X    if (Debug) Error("%s: DKIOCINFO: %s.", file, SYSERR);
  6492. X    return(NULL);
  6493. X    }
  6494. X
  6495. X    return(&dk_info);
  6496. X}
  6497. X
  6498. X/*
  6499. X * Get disk configuration structure.
  6500. X */
  6501. Xstatic struct dk_conf *GETdk_conf(d, file)
  6502. X    int             d;
  6503. X    char                *file;
  6504. X{
  6505. X    static struct dk_conf     dk_conf;
  6506. X
  6507. X    if (ioctl(d, DKIOCGCONF, &dk_conf) < 0) {
  6508. X    if (Debug) Error("%s: DKIOCGCONF: %s.", file, SYSERR);
  6509. X    return(NULL);
  6510. X    }
  6511. X
  6512. X    return(&dk_conf);
  6513. X}
  6514. X
  6515. X/*
  6516. X * Get disk geometry structure.
  6517. X */
  6518. Xstatic struct dk_geom *GETdk_geom(d, file)
  6519. X    int             d;
  6520. X    char                *file;
  6521. X{
  6522. X    static struct dk_geom     dk_geom;
  6523. X
  6524. X    if (ioctl(d, DKIOCGGEOM, &dk_geom) < 0) {
  6525. X    if (Debug) Error("%s: DKIOCGGEOM: %s.", file, SYSERR);
  6526. X    return(NULL);
  6527. X    }
  6528. X
  6529. X    return(&dk_geom);
  6530. X}
  6531. X
  6532. X/*
  6533. X * Get disk type structure.
  6534. X */
  6535. Xstatic struct dk_type *GETdk_type(d, file)
  6536. X    int             d;
  6537. X    char                *file;
  6538. X{
  6539. X    static struct dk_type     dk_type;
  6540. X
  6541. X    if (ioctl(d, DKIOCGTYPE, &dk_type) < 0) {
  6542. X    if (errno != ENOTTY)
  6543. X        if (Debug) Error("%s: DKIOCGTYPE: %s.", file, SYSERR);
  6544. X    return(NULL);
  6545. X    }
  6546. X
  6547. X    return(&dk_type);
  6548. X}
  6549. X
  6550. X/*
  6551. X * Check the checksum of a disklabel.
  6552. X */
  6553. Xstatic int DkLblCheckSum(DkLabel)
  6554. X    struct dk_label            *DkLabel;
  6555. X{
  6556. X    register short            *Ptr, Sum = 0;
  6557. X    register short         Count;
  6558. X
  6559. X    Count = (sizeof (struct dk_label)) / (sizeof (short));
  6560. X    Ptr = (short *)DkLabel;
  6561. X
  6562. X    /*
  6563. X     * Take the xor of all the half-words in the label.
  6564. X     */
  6565. X    while (Count--)
  6566. X    Sum ^= *Ptr++;
  6567. X
  6568. X    /*
  6569. X     * The total should be zero for a correct checksum
  6570. X     */
  6571. X    return(Sum);
  6572. X}
  6573. X
  6574. X/*
  6575. X * Get label information from label on disk.
  6576. X * The label is stored in the first sector of the disk.
  6577. X * We use the driver specific "read" flag with the DKIOCSCMD
  6578. X * ioctl to read the first sector.  There should be a special
  6579. X * ioctl to just read the label.
  6580. X */
  6581. Xstatic struct dk_label *GETdk_label(d, file, dk_info)
  6582. X    int             d;
  6583. X    char                *file;
  6584. X    struct dk_info            *dk_info;
  6585. X{
  6586. X    static struct dk_label     dk_label;
  6587. X    struct dk_cmd         dk_cmd;
  6588. X    struct dkctlrtab            *pct;
  6589. X
  6590. X    if (!file || !dk_info)
  6591. X    return((struct dk_label *) NULL);
  6592. X
  6593. X    if (!(pct = GetDkCtlrTab((int) dk_info->dki_ctype))) {
  6594. X    Error("Controller type %d is unknown.", 
  6595. X          dk_info->dki_ctype);
  6596. X    return((struct dk_label *) NULL);
  6597. X    }
  6598. X
  6599. X    if (pct->ct_rdcmd < 0) {
  6600. X    if (Debug)
  6601. X        Error("Read block on controller type \"%s\" is unsupported.",
  6602. X          pct->ct_model);
  6603. X    return((struct dk_label *) NULL);
  6604. X    }
  6605. X
  6606. X    bzero((char *) &dk_cmd, sizeof(dk_cmd));
  6607. X    dk_cmd.dkc_cmd = pct->ct_rdcmd;
  6608. X    dk_cmd.dkc_flags = DK_SILENT | DK_ISOLATE;
  6609. X    dk_cmd.dkc_blkno = (daddr_t)0;
  6610. X    dk_cmd.dkc_secnt = 1;
  6611. X    dk_cmd.dkc_bufaddr = (char *) &dk_label;
  6612. X    dk_cmd.dkc_buflen = SECSIZE;
  6613. X
  6614. X    if (ioctl(d, DKIOCSCMD, &dk_cmd) < 0) {
  6615. X    if (Debug) Error("%s: DKIOCSCMD: %s.", file, SYSERR);
  6616. X    return((struct dk_label *) NULL);
  6617. X    }
  6618. X
  6619. X    if (dk_label.dkl_magic != DKL_MAGIC) {
  6620. X    Error("%s: Disk not labeled.", file);
  6621. X    return((struct dk_label *) NULL);
  6622. X    }
  6623. X
  6624. X    if (DkLblCheckSum(&dk_label)) {
  6625. X    Error("%s: Bad label checksum.", file);
  6626. X    return((struct dk_label *) NULL);
  6627. X    }
  6628. X
  6629. X    return(&dk_label);
  6630. X}
  6631. X
  6632. X/*
  6633. X * Get the name of a disk (i.e. sd0).
  6634. X */
  6635. Xstatic char *GetDiskName(name, dk_conf, dk_info)
  6636. X    char                *name;
  6637. X    struct dk_conf            *dk_conf;
  6638. X    struct dk_info            *dk_info;
  6639. X{
  6640. X    if (!dk_conf || !dk_info) {
  6641. X    if (name)
  6642. X        return(name);
  6643. X    return((char *) NULL);
  6644. X    }
  6645. X
  6646. X#if    defined(DKI_HEXUNIT)
  6647. X    if (FLAGS_ON(dk_info->dki_flags, DKI_HEXUNIT))
  6648. X    (void) sprintf(Buf, "%s%3.3x", dk_conf->dkc_dname, dk_conf->dkc_unit);
  6649. X    else
  6650. X#endif     /* DKI_HEXUNIT */
  6651. X    (void) sprintf(Buf, "%s%d", dk_conf->dkc_dname, dk_conf->dkc_unit);
  6652. X
  6653. X    return(strdup(Buf));
  6654. X}
  6655. X
  6656. X/*
  6657. X * Get the name of the controller for a disk.
  6658. X */
  6659. Xstatic char *GetDkCtlrName(dk_conf)
  6660. X    struct dk_conf            *dk_conf;
  6661. X{
  6662. X    if (!dk_conf)
  6663. X    return((char *) NULL);
  6664. X
  6665. X    (void) sprintf(Buf, "%s%d", dk_conf->dkc_cname, dk_conf->dkc_cnum);
  6666. X
  6667. X    return(strdup(Buf));
  6668. X}
  6669. X
  6670. X/*
  6671. X * Get the disk controller model name from a disk.
  6672. X */
  6673. Xstatic char *GetDkCtlrModel(dk_info)
  6674. X    struct dk_info            *dk_info;
  6675. X{
  6676. X    struct dkctlrtab            *pct;
  6677. X
  6678. X    if (!dk_info)
  6679. X    return((char *) NULL);
  6680. X
  6681. X    if (!(pct = GetDkCtlrTab(dk_info->dki_ctype)))
  6682. X    return(NULL);
  6683. X
  6684. X    return(pct->ct_model);
  6685. X}
  6686. X
  6687. X/*
  6688. X * Get a disk controller device from disk info.
  6689. X */
  6690. Xstatic DEVICE *GetDkCtlrDevice(DevData, dk_info, dk_conf)
  6691. X    DEVDATA                *DevData;
  6692. X    struct dk_info            *dk_info;
  6693. X    struct dk_conf            *dk_conf;
  6694. X{
  6695. X    DEVICE                *MkMasterFromDevData();
  6696. X    DEVICE                *dkctlr;
  6697. X
  6698. X    if ((dkctlr = NewDevice(NULL)) == NULL)
  6699. X    return((DEVICE *) NULL);
  6700. X
  6701. X    bzero((char *) dkctlr, sizeof(*dkctlr));
  6702. X
  6703. X    dkctlr->dv_type = DT_DISKCTLR;
  6704. X
  6705. X    /*
  6706. X     * Get name of controller from devdata if available
  6707. X     */
  6708. X    if (DevData && DevData->dd_ctlrname) {
  6709. X    dkctlr = MkMasterFromDevData(DevData);
  6710. X    }
  6711. X
  6712. X    if (dk_conf) {
  6713. X    if (!dkctlr->dv_name) {
  6714. X        dkctlr->dv_name = GetDkCtlrName(dk_conf);
  6715. X        dkctlr->dv_unit = dk_conf->dkc_cnum;
  6716. X    }
  6717. X    dkctlr->dv_addr = dk_conf->dkc_addr;
  6718. X    dkctlr->dv_prio = dk_conf->dkc_prio;
  6719. X    dkctlr->dv_vec = dk_conf->dkc_vec;
  6720. X    }
  6721. X
  6722. X    if (dk_info) {
  6723. X    dkctlr->dv_model = GetDkCtlrModel(dk_info);
  6724. X    }
  6725. X
  6726. X    return(dkctlr);
  6727. X}
  6728. X
  6729. X/*
  6730. X * Get disk label info from the extracted dk_label info.
  6731. X */
  6732. Xstatic char *GetDiskLabel(dk_label)
  6733. X    struct dk_label            *dk_label;
  6734. X{
  6735. X    register char            *p;
  6736. X
  6737. X    if (!dk_label)
  6738. X    return((char *) NULL);
  6739. X
  6740. X    (void) strcpy(Buf, dk_label->dkl_asciilabel);
  6741. X
  6742. X    /*
  6743. X     * The label normally has geometry information in it we don't want
  6744. X     * to see, so we trim out anything starting with " cyl".
  6745. X     */
  6746. X    for (p = Buf; p && *p; ++p) {
  6747. X    if (*p == ' ' && strncasecmp(p, " cyl", 4) == 0)
  6748. X        *p = C_NULL;
  6749. X    }
  6750. X
  6751. X    return(strdup(Buf));
  6752. X}
  6753. X
  6754. X/*
  6755. X * Get filesystem mount info for a partition.
  6756. X */
  6757. Xstatic char *GetMountInfo(name, part)
  6758. X    char                *name;
  6759. X    char                *part;
  6760. X{
  6761. X    FILE                *mf;
  6762. X    struct mntent            *mntent;
  6763. X    char                *file;
  6764. X
  6765. X    if (!name)
  6766. X    return((char *) NULL);
  6767. X
  6768. X    file = GetCharFile(name, part);
  6769. X
  6770. X    if ((mf = setmntent(MNTTAB, "r")) == NULL) {
  6771. X    Error("%s: Cannot open for reading: %s.", MNTTAB, SYSERR);
  6772. X    return(NULL);
  6773. X    }
  6774. X
  6775. X    while (mntent = getmntent(mf)) {
  6776. X    if (strcmp(mntent->mnt_fsname, file) == 0)
  6777. X        break;
  6778. X    }
  6779. X
  6780. X    endmntent(mf);
  6781. X
  6782. X    return((mntent) ? mntent->mnt_dir : (char *) NULL);
  6783. X}
  6784. X
  6785. X/*
  6786. X * Extract the disk partition info from a disk.
  6787. X */
  6788. Xstatic DISKPART *ExtractDiskPart(name, part, dk_conf, dk_geom)
  6789. X    char                *name;
  6790. X    char                *part;
  6791. X    struct dk_conf            *dk_conf;
  6792. X    struct dk_geom            *dk_geom;
  6793. X{
  6794. X    static DISKPART         diskpart;
  6795. X    struct dk_map         dk_map;
  6796. X    char                *file;
  6797. X    char                *p;
  6798. X    int             d;
  6799. X
  6800. X    if (!name || !dk_conf || !dk_geom)
  6801. X    return((DISKPART *) NULL);
  6802. X
  6803. X    file = GetRawFile(name, part);
  6804. X
  6805. X    if (stat(file, &StatBuf) != 0) {
  6806. X    if (Debug) Error("%s: No such partition.", file);
  6807. X    return((DISKPART *) NULL);
  6808. X    }
  6809. X
  6810. X    if ((d = open(file, O_RDONLY)) < 0) {
  6811. X    if (Debug)
  6812. X        Error("%s: Cannot open for read: %s.", file, SYSERR);
  6813. X    return((DISKPART *) NULL);
  6814. X    }
  6815. X
  6816. X    if (ioctl(d, DKIOCGPART, &dk_map) != 0) {
  6817. X    Error("%s: Cannot extract partition info: %s.", 
  6818. X        file, SYSERR);
  6819. X    return((DISKPART *) NULL);
  6820. X    }
  6821. X    (void) close(d);
  6822. X
  6823. X    /*
  6824. X     * Skip empty partitions
  6825. X     */
  6826. X    if (!dk_map.dkl_nblk) {
  6827. X    if (Debug) Error("%s: partition has no size.", file);
  6828. X    return((DISKPART *) NULL);
  6829. X    }
  6830. X
  6831. X    bzero((char *) &diskpart, sizeof(DISKPART));
  6832. X
  6833. X    diskpart.dp_name = strdup(part);
  6834. X
  6835. X    if (p = GetMountInfo(name, part))
  6836. X    diskpart.dp_mnt = strdup(p);
  6837. X    /* 
  6838. X     * If this is the "b" partition on the root device, 
  6839. X     *  then assume it's swap 
  6840. X     */
  6841. X    else if (dk_conf->dkc_unit == 0 && strcmp(part, "b") == 0)
  6842. X    diskpart.dp_mnt = "swap";
  6843. X
  6844. X    diskpart.dp_stsect = dk_map.dkl_cylno *
  6845. X    (dk_geom->dkg_nhead * dk_geom->dkg_nsect);
  6846. X    diskpart.dp_nsect = dk_map.dkl_nblk;
  6847. X
  6848. X    return(&diskpart);
  6849. X}
  6850. X
  6851. X/*
  6852. X * Translate disk partition information from basic
  6853. X * extracted disk info.
  6854. X */
  6855. Xstatic DISKPART *GetDiskPart(name, dk_conf, dk_geom)
  6856. X    char                *name;
  6857. X    struct dk_conf            *dk_conf;
  6858. X    struct dk_geom            *dk_geom;
  6859. X{
  6860. X    extern char         PartChars[];
  6861. X    register DISKPART            *pdp, *dp;
  6862. X    register int         i;
  6863. X    static char         pname[2];
  6864. X    DISKPART                *base = NULL;
  6865. X
  6866. X    if (!name || !dk_conf || !dk_geom)
  6867. X    return((DISKPART *) NULL);
  6868. X
  6869. X    pname[1] = C_NULL;
  6870. X    for (i = 0; PartChars[i]; ++i) {
  6871. X    pname[0] = PartChars[i];
  6872. X    if (dp = ExtractDiskPart(name, pname, dk_conf, dk_geom)) {
  6873. X        if (base) {
  6874. X        for (pdp = base; pdp && pdp->dp_nxt; pdp = pdp->dp_nxt);
  6875. X        pdp->dp_nxt = NewDiskPart(dp);
  6876. X        } else {
  6877. X        base = NewDiskPart(dp);
  6878. X        }
  6879. X    }
  6880. X    }
  6881. X
  6882. X    return(base);
  6883. X}
  6884. X
  6885. X/*
  6886. X * Convert all we've learned about a disk to a DEVICE.
  6887. X */
  6888. Xstatic DEVICE *dkToDiskDevice(name, DevData,
  6889. X                  dk_info, dk_label, dk_conf, dk_geom, dk_type)
  6890. X    char                *name;
  6891. X    DEVDATA                *DevData;
  6892. X    struct dk_info            *dk_info;
  6893. X    struct dk_label            *dk_label;
  6894. X    struct dk_conf            *dk_conf;
  6895. X    struct dk_geom            *dk_geom;
  6896. X    struct dk_type            *dk_type;
  6897. X{
  6898. X    DEVICE                *Device, *dkctlr;
  6899. X    DISKDRIVE                *diskdrive;
  6900. X
  6901. X    if ((Device = NewDevice(NULL)) == NULL) {
  6902. X    Error("Cannot create new device entry.");
  6903. X    return((DEVICE *) NULL);
  6904. X    }
  6905. X
  6906. X    if ((dkctlr = NewDevice(NULL)) == NULL) {
  6907. X    Error("Cannot create new dkctlr device entry.");
  6908. X    return((DEVICE *) NULL);
  6909. X    }
  6910. X
  6911. X    if ((diskdrive = NewDiskDrive(NULL)) == NULL) {
  6912. X    Error("Cannot create new diskdrive entry.");
  6913. X    return((DEVICE *) NULL);
  6914. X    }
  6915. X
  6916. X    Device->dv_name = GetDiskName(name, dk_conf, dk_info);
  6917. X    Device->dv_type = DT_DISKDRIVE;
  6918. X    /*
  6919. X     * Only read partition info we we're going to print it later.
  6920. X     */
  6921. X    if (VL_ALL)
  6922. X    diskdrive->dd_part = GetDiskPart(name, dk_conf, dk_geom);
  6923. X    diskdrive->dd_label = GetDiskLabel(dk_label);
  6924. X    Device->dv_model = diskdrive->dd_label;
  6925. X
  6926. X    if (dk_conf) {
  6927. X    diskdrive->dd_unit = dk_conf->dkc_unit;
  6928. X    diskdrive->dd_slave = dk_conf->dkc_slave;;
  6929. X    }
  6930. X    if (dk_geom) {
  6931. X    diskdrive->dd_dcyl = dk_geom->dkg_ncyl;
  6932. X    diskdrive->dd_pcyl = dk_geom->dkg_pcyl;
  6933. X    diskdrive->dd_acyl = dk_geom->dkg_acyl;
  6934. X    diskdrive->dd_heads = dk_geom->dkg_nhead;
  6935. X    diskdrive->dd_sect = dk_geom->dkg_nsect;
  6936. X    diskdrive->dd_apc = dk_geom->dkg_apc;
  6937. X    diskdrive->dd_rpm = dk_geom->dkg_rpm;
  6938. X    diskdrive->dd_intrlv = dk_geom->dkg_intrlv;
  6939. X    }
  6940. X    if (dk_type) {
  6941. X    diskdrive->dd_psect = dk_type->dkt_hsect;
  6942. X    diskdrive->dd_promrev = dk_type->dkt_promrev;
  6943. X    }
  6944. X    if (dk_info) {
  6945. X#if    defined(DKI_HEXUNIT)
  6946. X    if (FLAGS_ON(dk_info->dki_flags, DKI_HEXUNIT))
  6947. X        diskdrive->dd_flags |= DF_HEXUNIT;
  6948. X#endif     /* DKI_HEXUNIT */
  6949. X    }
  6950. X
  6951. X    diskdrive->dd_secsize = SECSIZE;
  6952. X    if (diskdrive->dd_dcyl && diskdrive->dd_sect && diskdrive->dd_heads) {
  6953. X    static char Buf[BUFSIZ];
  6954. X
  6955. X    diskdrive->dd_size = nsect_to_bytes(diskdrive->dd_dcyl * 
  6956. X                         diskdrive->dd_sect * 
  6957. X                         diskdrive->dd_heads, 
  6958. X                        diskdrive->dd_secsize);
  6959. X
  6960. X    (void) sprintf(Buf, "%.2f MB capacity", 
  6961. X               (float) bytes_to_mbytes(diskdrive->dd_size));
  6962. X    Device->dv_desc = strdup(Buf);
  6963. X    }
  6964. X
  6965. X    dkctlr = GetDkCtlrDevice(DevData, dk_info, dk_conf);
  6966. X
  6967. X    Device->dv_devspec = (caddr_t *) diskdrive;
  6968. X    Device->dv_master = dkctlr;
  6969. X
  6970. X    return(Device);
  6971. X}
  6972. X
  6973. X/*
  6974. X * Query and learn about a disk.
  6975. X */
  6976. Xextern DEVICE *ProbeDiskDrive(name, DevData, DevDataTab)
  6977. X     /*ARGSUSED*/
  6978. X    char                *name;
  6979. X    DEVDATA                *DevData;
  6980. X    DEVDATATAB                     *DevDataTab;
  6981. X{
  6982. X    DEVICE                *diskdevice;
  6983. X    struct dk_info            *dk_info = NULL;
  6984. X    struct dk_conf            *dk_conf = NULL;
  6985. X    struct dk_type            *dk_type = NULL;
  6986. X    struct dk_label            *dk_label = NULL;
  6987. X    struct dk_geom            *dk_geom = NULL;
  6988. X    char                *rfile;
  6989. X    int             d;
  6990. X
  6991. X    if (!name)
  6992. X    return((DEVICE *) NULL);
  6993. X
  6994. X#if    defined(HAVE_IPI)
  6995. X    /*
  6996. X     * XXX - Kludge for IPI "id" disks.
  6997. X     */
  6998. X    if (EQ(DevData->dd_devname, "id")) {
  6999. X    static char        Buf[BUFSIZ];
  7000. X
  7001. X    (void) sprintf(Buf, "%s%3.3x", 
  7002. X               DevData->dd_devname, DevData->dd_devunit);
  7003. X    name = Buf;
  7004. X    }
  7005. X#endif    /* HAVE_IPI */
  7006. X
  7007. X    if (stat(rfile = GetRawFile(name, NULL), &StatBuf) != 0) {
  7008. X    /*
  7009. X     * Get the name of the whole disk raw device.
  7010. X     */
  7011. X    rfile = GetRawFile(name, "c");
  7012. X    }
  7013. X
  7014. X    if ((d = open(rfile, O_RDONLY)) < 0) {
  7015. X    if (Debug) Error("%s: Cannot open for reading: %s.", rfile, SYSERR);
  7016. X    /*
  7017. X     * If we know for sure this drive is present and we
  7018. X     * know something about it, then create a minimal device.
  7019. X     */
  7020. X    if ((DevDataTab->ddt_model || DevDataTab->ddt_desc) &&
  7021. X        FLAGS_ON(DevData->dd_flags, DD_IS_ALIVE)) {
  7022. X        Device = NewDevice((DEVICE *) NULL);
  7023. X        Device->dv_name = strdup(name);
  7024. X        Device->dv_unit = DevData->dd_devunit;
  7025. X        Device->dv_master = MkMasterFromDevData(DevData);
  7026. X        Device->dv_type = DT_DISKDRIVE;
  7027. X        Device->dv_model = DevDataTab->ddt_model;
  7028. X        Device->dv_desc = DevDataTab->ddt_desc;
  7029. X        return(Device);
  7030. X    } else
  7031. X        return((DEVICE *) NULL);
  7032. X    }
  7033. X
  7034. X    if ((dk_conf = GETdk_conf(d, rfile)) == NULL) {
  7035. X    if (Debug) Error("%s: get dk_conf failed.", rfile);
  7036. X    }
  7037. X
  7038. X    if ((dk_info = GETdk_info(d, rfile)) == NULL) {
  7039. X    if (Debug) Error("%s: get dk_info failed.", rfile);
  7040. X    }
  7041. X
  7042. X    if ((dk_geom = GETdk_geom(d, rfile)) == NULL) {
  7043. X    if (Debug) Error("%s: get dk_geom failed.", rfile);
  7044. X    }
  7045. X
  7046. X    if ((dk_label = GETdk_label(d, rfile, dk_info)) == NULL) {
  7047. X    if (Debug) Error("%s: get dk_label failed.", rfile);
  7048. X    }
  7049. X
  7050. X    /*
  7051. X     * Not all controllers support dk_type
  7052. X     */
  7053. X    dk_type = GETdk_type(d, rfile);
  7054. X
  7055. X    close(d);
  7056. X
  7057. X    if (!(diskdevice = dkToDiskDevice(name, DevData,
  7058. X                    dk_info, dk_label, 
  7059. X                    dk_conf, dk_geom, dk_type))) {
  7060. X    Error("%s: Cannot convert diskdrive information.", name);
  7061. X    return((DEVICE *) NULL);
  7062. X    }
  7063. X
  7064. X    return(diskdevice);
  7065. X}
  7066. X
  7067. X/*
  7068. X * Probe a tape device
  7069. X */
  7070. Xextern DEVICE *ProbeTapeDrive(name, DevData, DevDataTab)
  7071. X     /*ARGSUSED*/
  7072. X    char                *name;
  7073. X    DEVDATA                *DevData;
  7074. X    DEVDATATAB                *DevDataTab;
  7075. X{
  7076. X    extern NAMETAB        MtInfo[];
  7077. X    DEVICE                *Device;
  7078. X    char                *file;
  7079. X    char                *model = NULL;
  7080. X    static char         Buf[BUFSIZ];
  7081. X    struct mtget         mtget;
  7082. X    register int         i;
  7083. X    int             d;
  7084. X
  7085. X    file = GetRawFile(name, NULL);
  7086. X
  7087. X    if ((d = open(file, O_RDONLY)) < 0) {
  7088. X    if (Debug)
  7089. X        Error("%s Cannot open for read: %s.", file, SYSERR);
  7090. X
  7091. X    /*
  7092. X     * --RECURSE--
  7093. X     * If we haven't tried the "mt" name yet, try it now
  7094. X     */
  7095. X    if (strncmp(name, MTNAME, strlen(MTNAME)) != 0) {
  7096. X        (void) sprintf(Buf, "%s%d", MTNAME, DevData->dd_devunit);
  7097. X        Device = ProbeTapeDrive(Buf, DevData, DevDataTab);
  7098. X        if (Device)
  7099. X        return(Device);
  7100. X    }
  7101. X
  7102. X    /*
  7103. X     * If we know for sure this drive is present and we
  7104. X     * know something about it, then create a minimal device.
  7105. X     */
  7106. X    if ((DevDataTab->ddt_model || DevDataTab->ddt_desc) &&
  7107. X        FLAGS_ON(DevData->dd_flags, DD_IS_ALIVE)) {
  7108. X        Device = NewDevice((DEVICE *) NULL);
  7109. X        /* 
  7110. X         * Recreate name from devdata since we might have had to
  7111. X         * call ourself with name "rmt?"
  7112. X         */
  7113. X        (void) sprintf(Buf, "%s%d", DevData->dd_devname, 
  7114. X               DevData->dd_devunit);
  7115. X        Device->dv_name = strdup(Buf);
  7116. X        Device->dv_unit = DevData->dd_devunit;
  7117. X        Device->dv_master = MkMasterFromDevData(DevData);
  7118. X        Device->dv_type = DT_TAPEDRIVE;
  7119. X        Device->dv_model = DevDataTab->ddt_model;
  7120. X        Device->dv_desc = DevDataTab->ddt_desc;
  7121. X        return(Device);
  7122. X    } else
  7123. X        return((DEVICE *) NULL);
  7124. X    }
  7125. X
  7126. X    if (ioctl(d, MTIOCGET, &mtget) != 0) {
  7127. X    Error("%s: Cannot extract tape status: %s.", file, SYSERR);
  7128. X    return((DEVICE *) NULL);
  7129. X    }
  7130. X
  7131. X    (void) close(d);
  7132. X
  7133. X    model = "unknown";
  7134. X
  7135. X    for (i = 0; MtInfo[i].name; ++i) {
  7136. X    if ((MtInfo[i].value == mtget.mt_type)) {
  7137. X        model = MtInfo[i].name;
  7138. X        break;
  7139. X    }
  7140. X    }
  7141. X
  7142. X    /*
  7143. X     * Create and set device info
  7144. X     */
  7145. X    Device = NewDevice(NULL);
  7146. X    Device->dv_name = strdup(name);
  7147. X    Device->dv_type = DT_TAPEDRIVE;
  7148. X    if (model)
  7149. X    Device->dv_model = model;
  7150. X    else
  7151. X    Device->dv_model = DevDataTab->ddt_model;
  7152. X    Device->dv_desc = DevDataTab->ddt_desc;
  7153. X    Device->dv_unit = DevData->dd_devunit;
  7154. X    Device->dv_master = MkMasterFromDevData(DevData);
  7155. X
  7156. X    return(Device);
  7157. X}
  7158. X
  7159. X/*
  7160. X * Probe a CPU.  
  7161. X *
  7162. X * This function really "fakes" up an entry.
  7163. X *
  7164. X * Currently the info only comes from the OpenPROM.  We could
  7165. X * use the kernel mach_info and mod_info structures, but they
  7166. X * don't provide the model of CPU.  Maybe in a future release.
  7167. X */
  7168. Xextern DEVICE *ProbeCPU(name, DevData, DevDataTab)
  7169. X     /*ARGSUSED*/
  7170. X    char                *name;
  7171. X    DEVDATA                *DevData;
  7172. X    DEVDATATAB                *DevDataTab;
  7173. X{
  7174. X    static int             num_cpus = 0;
  7175. X
  7176. X    Device = NewDevice(NULL);
  7177. X    (void) sprintf(Buf, "cpu%d", num_cpus++);
  7178. X    Device->dv_name = strdup(Buf);
  7179. X    Device->dv_type = DT_CPU;
  7180. X    Device->dv_model = strdup(name);
  7181. X    Device->dv_desc = DevDataTab->ddt_desc;
  7182. X    Device->dv_master = MkMasterFromDevData(DevData);
  7183. X
  7184. X    return(Device);
  7185. X}
  7186. X
  7187. X/*
  7188. X * Probe a FrameBuffer.
  7189. X */
  7190. Xextern DEVICE *ProbeFrameBuffer(name, DevData, DevDataTab)
  7191. X    char                *name;
  7192. X    DEVDATA                *DevData;
  7193. X    DEVDATATAB                *DevDataTab;
  7194. X{
  7195. X    DEVICE                *fbdevice;
  7196. X    FRAMEBUFFER            *fb;
  7197. X    NAMETAB                *fbtab;
  7198. X    struct fbgattr         fbattr;
  7199. X#ifdef FBIOGXINFO
  7200. X    struct cg6_info         cg6_info;
  7201. X#endif
  7202. X    char                *file, Buf[BUFSIZ];
  7203. X    int             d;
  7204. X
  7205. X    if (!name)
  7206. X    return((DEVICE *) NULL);
  7207. X
  7208. X    /*
  7209. X     * Check the device file.  If the stat fails because
  7210. X     * the device doesn't exist, trying the default framebuffer
  7211. X     * device /dev/fb.
  7212. X     */
  7213. X    file = GetCharFile(name, NULL);
  7214. X    if (stat(file, &StatBuf) != 0) {
  7215. X    if (errno == ENOENT && !EQ(name, FBDEVICE)) {
  7216. X        if (Debug) 
  7217. X        Error("Framebuffer device %s does not exist.  Trying `fb'.",
  7218. X              name);
  7219. X        return(ProbeFrameBuffer(FBDEVICE, DevData, DevDataTab));
  7220. X    }
  7221. X    }
  7222. X
  7223. X    if ((d = open(file, O_RDONLY)) < 0) {
  7224. X    if (Debug) Error("%s: Cannot open for reading: %s.", file, SYSERR);
  7225. X    return((DEVICE *) NULL);
  7226. X    }
  7227. X
  7228. X    if (ioctl(d, FBIOGATTR, &fbattr) != 0) {
  7229. X    if (ioctl(d, FBIOGTYPE, &fbattr.fbtype) != 0) {
  7230. X        if (Debug) Error("%s: FBIOGATTR/FBIOGTYPE: %s.", 
  7231. X                 file, SYSERR);
  7232. X        return((DEVICE *) NULL);
  7233. X    }
  7234. X    }
  7235. X
  7236. X    Buf[0] = C_NULL;
  7237. X#if    defined(FBIOGXINFO)
  7238. X    if (ioctl(d, FBIOGXINFO, &cg6_info) == 0) {
  7239. X    sprintf(Buf, "SBus Slot %d, Revision %d",
  7240. X        cg6_info.slot, cg6_info.boardrev);
  7241. X    if (cg6_info.hdb_capable)
  7242. X        (void) strcat(Buf, ", double buffered");
  7243. X    else
  7244. X        (void) strcat(Buf, ", single buffered");
  7245. X    } else {
  7246. X    bzero((char *) &cg6_info, sizeof(struct cg6_info));
  7247. X    if (Debug) Error("%s: FBIOGXINFO: %s.", file, SYSERR);
  7248. X    }
  7249. X#endif     /* FBIOGXINFO */
  7250. X
  7251. X    close(d);
  7252. X
  7253. X    if (!(fb = NewFrameBuffer(NULL))) {
  7254. X    Error("Cannot create new frame buffer.");
  7255. X    return((DEVICE *) NULL);
  7256. X    }
  7257. X
  7258. X    if (!(fbdevice = NewDevice(NULL))) {
  7259. X    Error("Cannot create new frame buffer device entry.");
  7260. X    return((DEVICE *) NULL);
  7261. X    }
  7262. X
  7263. X    if (!(fbtab = GetFBTab(fbattr.fbtype.fb_type))) {
  7264. X    Error("Device %s is an unknown type (%d) of frame buffer.",
  7265. X          name, fbattr.fbtype.fb_type);
  7266. X    }
  7267. X
  7268. X    fbdevice->dv_name = name;
  7269. X    fbdevice->dv_type = DT_FRAMEBUFFER;
  7270. X    fbdevice->dv_devspec = (caddr_t *) fb;
  7271. X
  7272. X    if (Buf[0])
  7273. X    fbdevice->dv_desc = strdup(Buf);
  7274. X
  7275. X    if (fbtab) {
  7276. X    fbdevice->dv_model = fbtab->name;
  7277. X    } else {
  7278. X    fbdevice->dv_model = "UNKNOWN";
  7279. X    }
  7280. X
  7281. X    fb->fb_height = fbattr.fbtype.fb_height;
  7282. X    fb->fb_width = fbattr.fbtype.fb_width;
  7283. X    fb->fb_depth = fbattr.fbtype.fb_depth;
  7284. X    fb->fb_size = fbattr.fbtype.fb_size;
  7285. X    fb->fb_cmsize = fbattr.fbtype.fb_cmsize;
  7286. X#if    defined(FBIOGXINFO)
  7287. X    if (cg6_info.vmsize)
  7288. X    fb->fb_vmsize = mbytes_to_bytes(cg6_info.vmsize);
  7289. X#endif /* FBIOGXINFO */
  7290. X
  7291. X    fbdevice->dv_master = MkMasterFromDevData(DevData);
  7292. X
  7293. X    return(fbdevice);
  7294. X}
  7295. X
  7296. X/*
  7297. X * Determine our cpu model name.
  7298. X *
  7299. X * We lookup the kernel symbol "cpu" instead of using gethostid()
  7300. X * because some SPARC vendors do not encode cpu/model info in gethostid().
  7301. X */
  7302. Xextern char *GetModelName()
  7303. X{
  7304. X    extern NAMETAB         ModelTab[];
  7305. X    extern struct nlist        CpuNL[];
  7306. X    register int         i;
  7307. X    int                Cpu;
  7308. X    kvm_t               *kd;
  7309. X
  7310. X    if (!(kd = KVM_open(CpuNL))) {
  7311. X    if (Debug) Error("Cannot find cpu symbol in kernel.");
  7312. X    return((char *) NULL);
  7313. X    }
  7314. X
  7315. X    /*
  7316. X     * See if we got a valid entry
  7317. X     */
  7318. X    if (CheckNlist(&CpuNL[0]))
  7319. X    return((char *) NULL);
  7320. X
  7321. X    if (KVM_read(kd, (u_long) CpuNL[0].n_value, (char *) &Cpu, sizeof(Cpu))) {
  7322. X    if (Debug) Error("Cannot read cpu from kernel.");
  7323. X    return((char *) NULL);
  7324. X    }
  7325. X
  7326. X    KVM_close(kd);
  7327. X
  7328. X    for (i = 0; ModelTab[i].name; ++i)
  7329. X    if (Cpu == ModelTab[i].value)
  7330. X        return(ModelTab[i].name);
  7331. X
  7332. X    if (Debug)
  7333. X    Error("No model found; CPU = 0x%x.", Cpu);
  7334. X
  7335. X    return((char *) NULL);
  7336. X}
  7337. X
  7338. X#if     defined(CPU_ARCH) /* Sun */
  7339. X#define    ARCH_MASK CPU_ARCH
  7340. X#endif    /* CPU_ARCH */
  7341. X#if     defined(CPU_TYPE) /* Solbourne */
  7342. X#define ARCH_MASK CPU_TYPE
  7343. X#endif    /* CPU_TYPE */
  7344. X/*
  7345. X * Determine our kernel architecture name from our hostid.
  7346. X */
  7347. Xextern char *GetKernArchName()
  7348. X{
  7349. X#if    defined(ARCH_MASK)
  7350. X    extern NAMETAB         KernArchTab[];
  7351. X    extern struct nlist        CpuNL[];
  7352. X    kvm_t               *kd;
  7353. X    int                Cpu;
  7354. X    register int         i;
  7355. X
  7356. X    if (!(kd = KVM_open(CpuNL))) {
  7357. X    if (Debug) Error("Cannot find cpu symbol in kernel.");
  7358. X    return((char *) NULL);
  7359. X    }
  7360. X
  7361. X    /*
  7362. X     * See if we got a valid entry
  7363. X     */
  7364. X    if (CheckNlist(&CpuNL[0]))
  7365. X    return((char *) NULL);
  7366. X
  7367. X    if (KVM_read(kd, (u_long) CpuNL[0].n_value, (char *) &Cpu, sizeof(Cpu))) {
  7368. X    if (Debug) Error("Cannot read cpu from kernel.");
  7369. X    return((char *) NULL);
  7370. X    }
  7371. X
  7372. X    KVM_close(kd);
  7373. X
  7374. X    for (i = 0; KernArchTab[i].name; ++i)
  7375. X    if ((Cpu & ARCH_MASK) == KernArchTab[i].value)
  7376. X        return(KernArchTab[i].name);
  7377. X
  7378. X    if (Debug)
  7379. X    Error("Kernel Arch 0x%x not defined; Cpu = 0x%x Mask = 0x%x", 
  7380. X          Cpu & ARCH_MASK, Cpu, ARCH_MASK);
  7381. X#endif    /* ARCH_MASK */
  7382. X
  7383. X    return((char *) NULL);
  7384. X}
  7385. X
  7386. X#if    defined(HAVE_NIT)
  7387. X
  7388. X#include <sys/time.h>
  7389. X#include <sys/types.h>
  7390. X#include <sys/socket.h>
  7391. X#include <net/if.h>
  7392. X#include <net/nit_if.h>
  7393. X
  7394. X/*
  7395. X * Find and set the MAC info using the Network Interface Tap (NIT)
  7396. X */
  7397. Xextern void SetMacInfoNIT(DevName, NetIf)
  7398. X    char                *DevName;
  7399. X    NETIF                *NetIf;
  7400. X{
  7401. X    register struct sockaddr   *SockAddr;
  7402. X    struct ifreq             ifreq;
  7403. X    char                *ether_ntoa(), Buf[MAXHOSTNAMLEN+1];
  7404. X    int                 Desc;
  7405. X
  7406. X    if (!NetIf)
  7407. X    return;
  7408. X
  7409. X    if ((Desc = open("/dev/nit", O_RDONLY)) == SYSFAIL) {
  7410. X    if (Debug) Error("open /dev/nit failed");
  7411. X    return;
  7412. X    }
  7413. X
  7414. X    /*
  7415. X     * Bind to NIT for DevName
  7416. X     */
  7417. X    strncpy(ifreq.ifr_name, DevName, sizeof ifreq.ifr_name);
  7418. X    if (ioctl(Desc, NIOCBIND, (caddr_t) &ifreq) < 0) {
  7419. X    if (Debug) Error("ioctl:  NIOCBIND");
  7420. X    return;
  7421. X    }
  7422. X
  7423. X    /*
  7424. X     * Get address
  7425. X     */
  7426. X    if (ioctl(Desc, SIOCGIFADDR, (caddr_t)&ifreq) < 0) {
  7427. X    if (Debug) Error("ioctl (SIOCGIFADDR)");
  7428. X    return;
  7429. X    }
  7430. X
  7431. X    (void) close(Desc);
  7432. X
  7433. X    SockAddr = (struct sockaddr *)&ifreq.ifr_addr;
  7434. X    NetIf->ni_macaddr = strdup(ether_ntoa((struct ether_addr *) 
  7435. X                      SockAddr->sa_data));
  7436. X
  7437. X    if (ether_ntohost(Buf, (struct ether_addr *) SockAddr->sa_data) == 0)
  7438. X    NetIf->ni_macname = strdup(Buf);
  7439. X}
  7440. X#endif    /* HAVE_NIT */
  7441. X
  7442. X/*
  7443. X * Get kernel version string from kernel symbol "version".
  7444. X */
  7445. Xextern char *GetKernelVersionStr()
  7446. X{
  7447. X    return(GetKernelVersionFromVersion());
  7448. X}
  7449. X
  7450. X/*
  7451. X * Get amount of physical memory using kernel symbol "physmem".
  7452. X */
  7453. Xextern char *GetMemory()
  7454. X{
  7455. X    return(GetMemoryFromPhysmem());
  7456. X}
  7457. X
  7458. X/*
  7459. X * Get system serial number
  7460. X */
  7461. Xextern char *GetSerialNoStr()
  7462. X{
  7463. X    /* No support */
  7464. X    return((char *) NULL);
  7465. X}
  7466. X
  7467. X/*
  7468. X * Get name of OS
  7469. X */
  7470. Xextern char *GetOSNameStr()
  7471. X{
  7472. X    return(GetOSNameFromUname());
  7473. X}
  7474. X
  7475. X/*
  7476. X * Get version of OS
  7477. X */
  7478. Xextern char *GetOSVersionStr()
  7479. X{
  7480. X    return(GetOSVersionFromUname());
  7481. X}
  7482. X
  7483. X#if    defined(HAVE_SUNROMVEC)
  7484. X/*
  7485. X * Be backwards compatible with pre-4.1.2 code
  7486. X */
  7487. X#include <mon/sunromvec.h>
  7488. X#if    defined(OPENPROMS) && !(defined(ROMVEC_VERSION) && \
  7489. X                (ROMVEC_VERSION == 0 || ROMVEC_VERSION == 1))
  7490. X#define v_mon_id op_mon_id
  7491. X#endif
  7492. X#endif    /* HAVE_SUNROMVEC */
  7493. X
  7494. X/*
  7495. X * Get ROM Version number
  7496. X *
  7497. X * If "romp" is "defined" (in <mon/sunromvec.h>), then take that
  7498. X * as the address of the kernel pointer to "rom" (struct sunromvec).
  7499. X * Otherwise, nlist "romp" from the kernel.
  7500. X */
  7501. Xextern char *GetRomVer()
  7502. X{
  7503. X    static char            RomRev[16];
  7504. X#if    defined(HAVE_SUNROMVEC)
  7505. X    static struct sunromvec    Rom;
  7506. X    register char           *p;
  7507. X    register char           *Addr;
  7508. X    kvm_t               *kd;
  7509. X#if    !defined(romp)
  7510. X    struct sunromvec           *romp;
  7511. X    extern struct nlist        RomVecNL[];
  7512. X
  7513. X    if (!(kd = KVM_open(RomVecNL))) {
  7514. X    if (Debug) Error("Cannot find romvec symbol in kernel.");
  7515. X    return((char *) NULL);
  7516. X    }
  7517. X
  7518. X    /*
  7519. X     * See if we got a valid entry
  7520. X     */
  7521. X    if (CheckNlist(&RomVecNL[0]))
  7522. X    return((char *) NULL);
  7523. X
  7524. X    /*
  7525. X     * Read the kernel pointer to the sunromvec structure.
  7526. X     */
  7527. X    if (KVM_read(kd, (u_long) RomVecNL[0].n_value, (char *) &romp, 
  7528. X         sizeof(romp))) {
  7529. X    if (Debug) Error("Cannot read sunromvec pointer from kernel.");
  7530. X    return((char *) NULL);
  7531. X    }
  7532. X
  7533. X#else    /* romp */
  7534. X
  7535. X    if (!(kd = KVM_open((struct nlist *) NULL))) {
  7536. X    if (Debug) Error("KVM_open failed.");
  7537. X    return((char *) NULL);
  7538. X    }
  7539. X
  7540. X#endif    /* romp */
  7541. X
  7542. X    /*
  7543. X     * Read the sunromvec structure from the kernel
  7544. X     */
  7545. X    /*SUPPRESS 25*/
  7546. X    if (KVM_read(kd, (u_long) romp, (char *) &Rom, sizeof(struct sunromvec))) {
  7547. X    if (Debug) Error("Cannot read sunromvec from kernel.");
  7548. X    return((char *) NULL);
  7549. X    }
  7550. X
  7551. X#if    !defined(romp)
  7552. X
  7553. X    /*
  7554. X     * XXX Hardcoded values
  7555. X     */
  7556. X    (void) sprintf(RomRev, "%d.%d", Rom.v_mon_id >> 16, Rom.v_mon_id & 0xFFFF);
  7557. X
  7558. X#else    /* romp */
  7559. X
  7560. X    /*
  7561. X     * Read the version string from the address indicated by Rom.v_mon_id.
  7562. X     * Read 1 byte at a time until '\0' is encountered.
  7563. X     */
  7564. X    p = RomRev;
  7565. X    Addr = Rom.v_mon_id;
  7566. X    do {
  7567. X    if (KVM_read(kd, (u_long) Addr++, p, 1))
  7568. X        break;
  7569. X    } while (p < &RomRev[sizeof(RomRev)-1] && *p++);
  7570. X    *p = C_NULL;
  7571. X
  7572. X#endif    /* romp */
  7573. X
  7574. X    KVM_close(kd);
  7575. X
  7576. X#endif    /* HAVE_SUNROMVEC */
  7577. X
  7578. X    return((RomRev[0]) ? RomRev : (char *) NULL);
  7579. X}
  7580. END_OF_os-sunos.c
  7581. if test 38554 -ne `wc -c <os-sunos.c`; then
  7582.     echo shar: \"os-sunos.c\" unpacked with wrong size!
  7583. fi
  7584. # end of overwriting check
  7585. fi
  7586. if test -f info-sunos.c -a "${1}" != "-c" ; then 
  7587.   echo shar: Will not over-write existing file \"info-sunos.c\"
  7588. else
  7589. echo shar: Extracting \"info-sunos.c\" \(16354 characters\)
  7590. sed "s/^X//" >info-sunos.c <<'END_OF_info-sunos.c'
  7591. X/*
  7592. X * Copyright (c) 1992 Michael A. Cooper.
  7593. X * This software may be freely distributed provided it is not sold for 
  7594. X * profit and the author is credited appropriately.
  7595. X */
  7596. X
  7597. X#ifndef lint
  7598. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/info-sunos.c,v 1.19 1992/04/26 23:32:06 mcooper Exp $";
  7599. X#endif
  7600. X
  7601. X/*
  7602. X * $Log: info-sunos.c,v $
  7603. X * Revision 1.19  1992/04/26  23:32:06  mcooper
  7604. X * Add Copyright notice
  7605. X *
  7606. X * Revision 1.18  1992/04/19  18:44:59  mcooper
  7607. X * Change around GS framebuffer definition according to Greg Earle.
  7608. X *
  7609. X * Revision 1.17  1992/04/17  23:33:04  mcooper
  7610. X * Add RomVecNL.
  7611. X *
  7612. X * Revision 1.16  1992/04/17  01:10:11  mcooper
  7613. X * Moved DEVICE *() function declares to defs.h.
  7614. X *
  7615. X * Revision 1.15  1992/04/15  02:42:12  mcooper
  7616. X * Change "ipi3sc" to DT_GENERIC.
  7617. X *
  7618. X * Revision 1.14  1992/04/12  22:03:13  mcooper
  7619. X * - Add Tadpole/SPARCbook support.
  7620. X * - Add Solbourne models and arch's.
  7621. X *
  7622. X * Revision 1.13  1992/03/31  00:44:40  mcooper
  7623. X * Add sun386 kernel arch.
  7624. X *
  7625. X * Revision 1.12  1992/03/28  21:29:24  mcooper
  7626. X * Move NetifNL to netif.c.
  7627. X *
  7628. X * Revision 1.11  1992/03/22  00:20:10  mcooper
  7629. X * Major cleanup and re-org.
  7630. X *
  7631. X * Revision 1.10  1992/03/08  04:58:56  mcooper
  7632. X * The old NETIFTAB has been removed by placing the old data
  7633. X * directly in the devdatatab.
  7634. X *
  7635. X * Revision 1.9  1992/03/06  18:34:02  mcooper
  7636. X * - Use new NAMETAB whenever possible.
  7637. X * - Replace _size vars with { 0 } entries.
  7638. X *
  7639. X * Revision 1.8  1992/03/01  23:30:15  mcooper
  7640. X * More more SunOS specific code from sysinfo.c to here.
  7641. X *
  7642. X * Revision 1.7  1992/02/27  22:01:22  mcooper
  7643. X * Add support for getting CPU info for sun4m.
  7644. X *
  7645. X * Revision 1.6  1992/02/27  20:37:59  mcooper
  7646. X * Move netif names in devdatatab to top to avoid conflicts
  7647. X * of "fd" and "fddi".
  7648. X *
  7649. X * Revision 1.5  1992/02/27  00:14:22  mcooper
  7650. X * Add "ei" (Solbourne ethernet interface) to devdatatab.
  7651. X *
  7652. X * Revision 1.4  1992/02/26  19:07:02  mcooper
  7653. X * Add more random Sun devices.
  7654. X *
  7655. X * Revision 1.3  1992/02/25  00:59:35  mcooper
  7656. X * Move tape info to local MTINFO.
  7657. X *
  7658. X * Revision 1.2  1992/02/25  00:23:29  mcooper
  7659. X * - Cleanup framebuffers.
  7660. X * - Add mt info.
  7661. X * - Update device table.
  7662. X *
  7663. X * Revision 1.1  1992/02/22  02:20:19  mcooper
  7664. X * Initial revision
  7665. X *
  7666. X */
  7667. X
  7668. X
  7669. X/*
  7670. X * SunOS specific device info
  7671. X */
  7672. X
  7673. X#include <stdio.h>
  7674. X#include "system.h"
  7675. X#include "defs.h"
  7676. X
  7677. X#include <nlist.h>
  7678. X#include <sys/types.h>
  7679. X#include <sys/buf.h>
  7680. X#include <sys/mtio.h>
  7681. X#include <sun/dkio.h>
  7682. X#include <sun/fbio.h>
  7683. X
  7684. X#if     defined(TADPOLE)
  7685. X#include <taddev/ide_drvr_def.h>
  7686. X#else    /* !TADPOLE */
  7687. X#    if     defined(HAVE_IPI)
  7688. X#        include <sundev/ipvar.h>
  7689. X#    endif     /* HAVE_IPI */
  7690. X#    include <sundev/xdreg.h>
  7691. X#    include <sundev/xyreg.h>
  7692. X#    include <sundev/scsi.h>
  7693. X#    if     defined(i386)
  7694. X#        include <sundev/sdreg.h>
  7695. X#    endif
  7696. X#endif    /* TADPOLE */
  7697. X
  7698. X/*
  7699. X * Characters for disk partitions
  7700. X */
  7701. Xchar PartChars[] = "abcdefgh";
  7702. X
  7703. X/*
  7704. X * CPU (model) symbol
  7705. X */
  7706. Xstruct nlist CpuNL[] = {
  7707. X#if    defined(COFF)
  7708. X    { "cpu" },
  7709. X#else
  7710. X    { "_cpu" },
  7711. X#endif    /* COFF */
  7712. X    { 0 },
  7713. X};
  7714. X
  7715. X#if    defined(HAVE_MAINBUS)
  7716. X/*
  7717. X * MainBus name list
  7718. X */
  7719. Xstruct nlist MainBusNL[] = {
  7720. X#if    defined(COFF)
  7721. X    { "mbdinit" },
  7722. X#else
  7723. X    { "_mbdinit" },
  7724. X#endif    /* COFF */
  7725. X    { 0 },
  7726. X};
  7727. X#endif    /* HAVE_MAINBUS */
  7728. X
  7729. X#if    defined(HAVE_OPENPROM)
  7730. X/*
  7731. X * OpenPROM name list
  7732. X */
  7733. Xstruct nlist OpenPROMNL[] = {
  7734. X#if    defined(COFF)
  7735. X    { "top_devinfo" },
  7736. X#else
  7737. X    { "_top_devinfo" },
  7738. X#endif    /* COFF */
  7739. X    { 0 },
  7740. X};
  7741. X#endif    /* HAVE_OPENPROM */
  7742. X
  7743. X/*
  7744. X * RomVec
  7745. X */
  7746. Xstruct nlist RomVecNL[] = {
  7747. X#if    defined(COFF)
  7748. X    { "romp" },
  7749. X#else
  7750. X    { "_romp" },
  7751. X#endif    /* COFF */
  7752. X    { 0 },
  7753. X};
  7754. X
  7755. X/*
  7756. X * Sun system model table
  7757. X *
  7758. X * Not all values are real machines.  What is found below is
  7759. X * extracted from /usr/include/{sun3,sun3x,sun4,sun4c,sun4m}/cpu.h.
  7760. X */
  7761. XNAMETAB ModelTab[] = {
  7762. X/*
  7763. X * Sun-3 CPU's
  7764. X */
  7765. X#ifdef CPU_SUN3_50
  7766. X    {  CPU_SUN3_50,         "3/50" },
  7767. X#endif
  7768. X#ifdef CPU_SUN3_60
  7769. X    {  CPU_SUN3_60,         "3/60" },
  7770. X#endif
  7771. X#ifdef CPU_SUN3_E
  7772. X    {  CPU_SUN3_E,            "3/Eurocard" },
  7773. X#endif
  7774. X#ifdef CPU_SUN3_110
  7775. X    {  CPU_SUN3_110,            "3/110" },
  7776. X#endif
  7777. X#ifdef CPU_SUN3_160
  7778. X    {  CPU_SUN3_160,            "3/100 Series" },
  7779. X#endif
  7780. X#ifdef CPU_SUN3_260
  7781. X    {  CPU_SUN3_260,            "3/200 Series" },
  7782. X#endif
  7783. X
  7784. X/*
  7785. X * Sun-3x CPU's
  7786. X */
  7787. X#ifdef CPU_SUN3X_80:
  7788. X    {  CPU_SUN3X_80,        "3/80" },
  7789. X#endif
  7790. X#ifdef CPU_SUN3X_470
  7791. X    {  CPU_SUN3X_470,        "3/400 Series" },
  7792. X#endif
  7793. X
  7794. X/*
  7795. X * Sun-4c CPU's.
  7796. X */
  7797. X#ifdef CPU_SUN4C_05:
  7798. X    {  CPU_SUN4C_05,        "4/05" },
  7799. X#endif
  7800. X#ifdef CPU_SUN4C_10:
  7801. X    {  CPU_SUN4C_10,        "4/10" },
  7802. X#endif
  7803. X#ifdef CPU_SUN4C_20:
  7804. X    {  CPU_SUN4C_20,        "4/20 (SPARCstation SLC)" },
  7805. X#endif
  7806. X/*
  7807. X * XXX The 4/25 and 4/30 are both ELC's depending on your OS
  7808. X */
  7809. X#ifdef CPU_SUN4C_25:
  7810. X    {  CPU_SUN4C_25,        "4/25 (SPARCstation ELC)" },
  7811. X#endif
  7812. X#ifdef CPU_SUN4C_30:
  7813. X    {  CPU_SUN4C_30,        "4/30 (SPARCstation ELC)" },
  7814. X#endif
  7815. X#ifdef CPU_SUN4C_32:
  7816. X    {  CPU_SUN4C_32,        "4/32" },
  7817. X#endif
  7818. X#ifdef CPU_SUN4C_40:
  7819. X    {  CPU_SUN4C_40,        "4/40 (SPARCstation IPC)" },
  7820. X#endif
  7821. X#ifdef CPU_SUN4C_45:
  7822. X    {  CPU_SUN4C_45,        "4/45" },
  7823. X#endif
  7824. X#ifdef CPU_SUN4C_50:
  7825. X    {  CPU_SUN4C_50,        "4/50 (SPARCstation IPX)" },
  7826. X#endif
  7827. X#ifdef CPU_SUN4C_60:
  7828. X    {  CPU_SUN4C_60,        "4/60 (SPARCstation 1)" },
  7829. X#endif
  7830. X#ifdef CPU_SUN4C_65:
  7831. X    {  CPU_SUN4C_65,        "4/65 (SPARCstation 1+)" },
  7832. X#endif
  7833. X#ifdef CPU_SUN4C_70:
  7834. X    {  CPU_SUN4C_70,        "4/70" },
  7835. X#endif
  7836. X#ifdef CPU_SUN4C_75:
  7837. X    {  CPU_SUN4C_75,        "4/75 (SPARCstation 2)" },
  7838. X#endif
  7839. X#ifdef CPU_SUN4C_80:
  7840. X    {  CPU_SUN4C_80,        "4/80" },
  7841. X#endif
  7842. X#ifdef CPU_SUN4C_85:
  7843. X    {  CPU_SUN4C_85,        "4/85" },
  7844. X#endif
  7845. X
  7846. X/*
  7847. X * Sun-4 CPU's
  7848. X */
  7849. X#ifdef CPU_SUN4_110
  7850. X    {  CPU_SUN4_110,            "4/110" },
  7851. X#endif
  7852. X#ifdef CPU_SUN4_260
  7853. X    {  CPU_SUN4_260,            "SPARCsystem 200" },
  7854. X#endif
  7855. X#ifdef CPU_SUN4_330
  7856. X    {  CPU_SUN4_330,        "SPARCsystem 300" },
  7857. X#endif
  7858. X#ifdef CPU_SUN4_460    /* Sun changed the 4_460 to 4_470 in 4.1.1 */
  7859. X    {  CPU_SUN4_460,        "SPARCsystem 400" },
  7860. X#endif
  7861. X#ifdef CPU_SUN4_470
  7862. X    {  CPU_SUN4_470,        "SPARCsystem 400" },
  7863. X#endif
  7864. X
  7865. X/*
  7866. X * Sun-4m CPU's
  7867. X */
  7868. X#ifdef CPU_SUN4M_690
  7869. X    {  CPU_SUN4M_690,            "SPARCsystem 600" },
  7870. X#endif
  7871. X
  7872. X/*
  7873. X * Sun-386i CPU's
  7874. X */
  7875. X#ifdef CPU_SUN386_MB1
  7876. X    {  CPU_SUN386_MB1,        "386i (MB1)" },
  7877. X#endif
  7878. X#ifdef CPU_SUN386_150
  7879. X    /* The 386i/150 and 386i/250 are the same */
  7880. X    {  CPU_SUN386_150,        "386i" },
  7881. X#endif
  7882. X
  7883. X/*
  7884. X * Solbourne CPU's
  7885. X */
  7886. X#ifdef CPU_SERIES4_500
  7887. X    {  CPU_SERIES4_500,        "Series4/500" },
  7888. X#endif
  7889. X#ifdef CPU_SERIES4_600
  7890. X    {  CPU_SERIES4_600,        "Series4/600" },
  7891. X#endif
  7892. X#ifdef CPU_SERIES5_500
  7893. X    {  CPU_SERIES5_500,        "Series5/500" },
  7894. X#endif
  7895. X#ifdef CPU_SERIES5_600
  7896. X    {  CPU_SERIES5_600,        "Series5/600" },
  7897. X#endif
  7898. X#ifdef CPU_SERIES5_900
  7899. X    {  CPU_SERIES5_900,        "Series5/900" },
  7900. X#endif
  7901. X#ifdef CPU_SERIES5E_500
  7902. X    {  CPU_SERIES5E_500,    "Series5E/500" },
  7903. X#endif
  7904. X#ifdef CPU_SERIES5E_600
  7905. X    {  CPU_SERIES5E_600,    "Series5E/600" },
  7906. X#endif
  7907. X#ifdef CPU_SERIES5E_900
  7908. X    {  CPU_SERIES5E_900,    "Series5E/900" },
  7909. X#endif
  7910. X#ifdef CPU_SERIES6_500
  7911. X    {  CPU_SERIES6_500,        "Series6/500" },
  7912. X#endif
  7913. X#ifdef CPU_SERIES6_600
  7914. X    {  CPU_SERIES6_600,        "Series6/600" },
  7915. X#endif
  7916. X#ifdef CPU_SERIES6_900
  7917. X    {  CPU_SERIES6_900,        "Series6/900" },
  7918. X#endif
  7919. X
  7920. X/*
  7921. X * TadPole CPU's
  7922. X */
  7923. X#ifdef CPU_TAD_SPBK_S1
  7924. X    {  CPU_TAD_SPBK_S1,        "SPARCbook-1" },
  7925. X#endif
  7926. X
  7927. X    { 0 },
  7928. X};
  7929. X
  7930. X/*
  7931. X * Kernel Architecture table
  7932. X */
  7933. XNAMETAB KernArchTab[] = {
  7934. X#ifdef SUN386_ARCH
  7935. X    {  SUN386_ARCH,        "sun386" },
  7936. X#endif
  7937. X#ifdef SUN3_ARCH
  7938. X    {  SUN3_ARCH,        "sun3" },
  7939. X#endif
  7940. X#ifdef SUN3X_ARCH
  7941. X    {  SUN3X_ARCH,        "sun3x" },
  7942. X#endif
  7943. X#ifdef SUN4_ARCH
  7944. X    {  SUN4_ARCH,        "sun4" },
  7945. X#endif
  7946. X#ifdef SUN4C_ARCH
  7947. X    {  SUN4C_ARCH,        "sun4c" },
  7948. X#endif
  7949. X#ifdef SUN4M_ARCH
  7950. X    {  SUN4M_ARCH,        "sun4m" },
  7951. X#endif
  7952. X/*
  7953. X * Tadpole
  7954. X */
  7955. X#ifdef TAD_SPBK_ARCH
  7956. X    {  TAD_SPBK_ARCH,        "SPARCbook" },
  7957. X#endif
  7958. X/*
  7959. X * Solbourne
  7960. X */
  7961. X#ifdef CPU_TYPE_SERIES4
  7962. X    {  CPU_TYPE_SERIES4,    "Series4" },
  7963. X#endif
  7964. X#ifdef CPU_TYPE_SERIES5
  7965. X    {  CPU_TYPE_SERIES5,    "Series5" },
  7966. X#endif
  7967. X#ifdef CPU_TYPE_SERIES5E
  7968. X    {  CPU_TYPE_SERIES5E,    "Series5E" },
  7969. X#endif
  7970. X#ifdef CPU_TYPE_SERIES6
  7971. X    {  CPU_TYPE_SERIES6,    "Series6" },
  7972. X#endif
  7973. X#ifdef CPU_TYPE_KAP_M2
  7974. X    {  CPU_TYPE_KAP_M2,        "KAP_M2" },
  7975. X#endif
  7976. X    { 0 },
  7977. X};
  7978. X
  7979. X/*
  7980. X * Device Data Table
  7981. X *
  7982. X * Compares are done by the length of the string appearing in
  7983. X * the first columns.  Therefore, longer names must appear before
  7984. X * any shorter names that are not unique.  e.g. "lebuffer" needs to
  7985. X * be before "le".
  7986. X */
  7987. XDEVDATATAB DevDataTab[] = {
  7988. X    { "ie",        0,    "Intel 82586 LAN Co-Processor",    
  7989. X                  "10Mb/sec Ethernet",    ProbeNetif },
  7990. X    { "ei",        0,    "Solbourne IOASIC AMD Lance Am7990",    
  7991. X                  "10Mb/sec Ethernet",    ProbeNetif },
  7992. X    { "lebuffer",     DT_PSEUDO,    NULL,    NULL,    ProbeGeneric },
  7993. X    { "le",        0,    "AMD Lance Am7990",
  7994. X                  "10Mb/sec Ethernet",    ProbeNetif },
  7995. X    { "ne",        0,    "Interphase NC400",
  7996. X                  "10Mb/sec Ethernet",    ProbeNetif },
  7997. X    { "fddi",        0,    "Sun FDDI",
  7998. X                  "100Mb/sec FDDI",    ProbeNetif },
  7999. X    { "sd",        0,        NULL,    NULL,    ProbeDiskDrive },
  8000. X    { "xd",        0,        NULL,    NULL,    ProbeDiskDrive },
  8001. X    { "xy",        0,        NULL,    NULL,    ProbeDiskDrive },
  8002. X    { "id",        0,        NULL,    NULL,    ProbeDiskDrive },
  8003. X    { "sr",        0,        "CD-ROM",    NULL,    ProbeDiskDrive },
  8004. X    { "fd",        0,        "Floppy",    NULL,    ProbeDiskDrive },
  8005. X    { "bwone",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8006. X    { "bwtwo",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8007. X    { "cgone",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8008. X    { "cgtwo",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8009. X    { "cgthree",    0,        NULL,    NULL,    ProbeFrameBuffer },
  8010. X    { "cgfour",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8011. X    { "cgsix",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8012. X    { "cgeight",    0,        NULL,    NULL,    ProbeFrameBuffer },
  8013. X    { "cgnine",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8014. X    { "cgtwelve",    0,        NULL,    NULL,    ProbeFrameBuffer },
  8015. X    { "gpone",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8016. X    { "gt",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8017. X    { "taac",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8018. X    { "vx",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8019. X    { "Cypress,CY",    0,        NULL,    "CPU",    ProbeCPU },
  8020. X    { "sbus",        DT_BUS,        NULL,    NULL,    ProbeGeneric },
  8021. X    { "vme",        DT_BUS,        NULL,    NULL,    ProbeGeneric },
  8022. X    { "obio",        DT_BUS,        NULL,    "OnBoard I/O",    
  8023. X                            ProbeGeneric },
  8024. X    { "obmem",        DT_BUS,        NULL,    "OnBoard Memory",
  8025. X                              ProbeGeneric },
  8026. X    { "iommu",        DT_BUS,        NULL,    NULL,    ProbeGeneric },
  8027. X    { "dma",        DT_PSEUDO,    NULL,    NULL,    ProbeGeneric },
  8028. X    { "openprom",     DT_PSEUDO,    NULL,    NULL,    ProbeGeneric },
  8029. X    /* Old OpenPROMs say "Sun 4/60" instead of "SUNW,Sun 4/60" */
  8030. X    { "Sun ",         DT_PSEUDO,    NULL,    NULL,    ProbeGeneric },
  8031. X    { "SUNW,Sun",     DT_PSEUDO,    NULL,    NULL,    ProbeGeneric },
  8032. X    { "SUNW,pn",     DT_PSEUDO,    NULL,    NULL,    ProbeGeneric },
  8033. X    { "ipi3sc",     DT_GENERIC,    NULL,    NULL,    ProbeGeneric },
  8034. X    { "esp",        DT_DISKCTLR,    "Emulex SCSI interface",    
  8035. X      NULL,                        ProbeGeneric },
  8036. X    { "st",        DT_TAPEDRIVE,     "SCSI",
  8037. X    NULL,                        ProbeTapeDrive },
  8038. X    { "xtc",        DT_TAPECTLR,     "Xylogics 472",
  8039. X    "1/2 inch tape controller",             ProbeGeneric },
  8040. X    { "xt",        DT_TAPEDRIVE,     "Fujitsu M2444",
  8041. X    "1/2 inch tape drive",                ProbeTapeDrive },
  8042. X    { "audio",         DT_GENERIC,    "AM79C30A DSC",    
  8043. X      "telephone quality audio",            ProbeGeneric },
  8044. X    { "zs",         DT_GENERIC,    "Zilog 8530",    
  8045. X      "serial communications chip",            ProbeGeneric },
  8046. X    { "mti",         DT_GENERIC,    "ALM-1 (Systech MTI-1600)",    
  8047. X      "16-line terminal multiplexer",        ProbeGeneric },
  8048. X    { "mcp",         DT_GENERIC,    "ALM-2 (Sun MCP/ALM)",    
  8049. X      "16-line terminal multiplexer",        ProbeGeneric },
  8050. X    { "fpa",         DT_GENERIC,    "Wietek FPA",    
  8051. X      "floating point accelerator",            ProbeGeneric },
  8052. X    { "des",         DT_GENERIC,    "AmZ8068 Data Ciphering Processor",
  8053. X      "NBS Data Encryption Standard",        ProbeGeneric },
  8054. X    { "vpc",         DT_GENERIC,    "Systech VPC-2200",    
  8055. X      "Versatec & Centronics printer/plotter interface", ProbeGeneric },
  8056. X    { "pp",         DT_GENERIC,    "Parallel Port",
  8057. X      "Centronics-compatible parallel printer port", ProbeGeneric },
  8058. X    { "SUNW,bpp",    DT_GENERIC,    "SBus Printer Card",
  8059. X      "bidirectional parallel port",         ProbeGeneric },
  8060. X    { "SUNW,lpvi",    DT_GENERIC,    "SBus Printer Card",
  8061. X      "laser printer video interface",         ProbeGeneric },
  8062. X    { "db",        DT_GENERIC,    "Sun Dials Box",
  8063. X      NULL,     ProbeGeneric },
  8064. X    { "pr",         DT_GENERIC,    "PrestoServe",
  8065. X      "file system accelerator",             ProbeGeneric },
  8066. X    /* 
  8067. X     * Tadpole devices
  8068. X     */
  8069. X    { "nice",        0,    "NICE Ethernet Co-processor",
  8070. X                  "10Mb/sec Ethernet",    ProbeNetif },
  8071. X    { "par",         DT_GENERIC,    "Parallel Port",
  8072. X      "Centronics-compatible parallel printer port", ProbeGeneric },
  8073. X    { "modem",         DT_GENERIC,    NULL,
  8074. X      "Hayes compatible modem",             ProbeGeneric },
  8075. X    { "urt",         DT_GENERIC,    NULL,    
  8076. X      "serial communications chip",            ProbeGeneric },
  8077. X    { "vga",        0,        NULL,    NULL,    ProbeFrameBuffer },
  8078. X    { 0 },
  8079. X};
  8080. X
  8081. X/*
  8082. X * Table of known Sun Disk Controllers.
  8083. X */
  8084. XDKCTLRTAB DkCtlrTab[] = {
  8085. X#if defined(DKC_XY450) && defined(XY_READ)
  8086. X    {  DKC_XY450,    "Xylogics 450/451 SMD",        XY_READ },
  8087. X#endif
  8088. X#if defined(DKC_ACB4000) && defined(SC_READ)
  8089. X    {  DKC_ACB4000,    "Adaptec ACB4000 SCSI",        SC_READ },
  8090. X#endif
  8091. X#if defined(DKC_MD21) && defined(SC_READ)
  8092. X    {  DKC_MD21,    "Emulex MD21 SCSI",        SC_READ },
  8093. X#endif
  8094. X#if defined(DKC_NCRFLOPPY) && defined(SC_READ)
  8095. X    {  DKC_NCRFLOPPY,    "NCR Floppy SCSI",        SC_READ },
  8096. X#endif
  8097. X#if defined(DKC_XD7053) && defined(XD_READ)
  8098. X    {  DKC_XD7053,    "Xylogics 7053/753 SMD",    XD_READ },
  8099. X#endif
  8100. X#if defined(DKC_SMSFLOPPY) && defined(SC_READ)
  8101. X    {  DKC_SMSFLOPPY,    "SMS Floppy SCSI",        SC_READ },
  8102. X#endif
  8103. X#if defined(DKC_SCSI_CCS) && defined(SC_READ)
  8104. X    {  DKC_SCSI_CCS,    "SCSI CCS",            SC_READ },
  8105. X#endif
  8106. X#if defined(DKC_CCS) && defined(SC_READ)
  8107. X    {  DKC_CCS,        "CCS SCSI",            SC_READ },
  8108. X#endif
  8109. X#if defined(DKC_NEC765)
  8110. X    {  DKC_NEC765,    "NEC 765 Floppy",        -1 },
  8111. X#endif
  8112. X#if defined(DKC_INTEL82072)
  8113. X    {  DKC_INTEL82072,    "Intel 82072 Floppy",         -1 },
  8114. X#endif
  8115. X#if defined(DKC_PANTHER) && defined(IP_READ)
  8116. X    {  DKC_PANTHER,    "Sun ISP-80 (Panther) IPI-2",    IP_READ },
  8117. X#endif
  8118. X#if defined(DKC_XD753_IPI) && defined(XD_READ)
  8119. X/*
  8120. X * Solbourne
  8121. X */
  8122. X    {  DKC_XD753_IPI,    "Xylogics SV-{67}800 IPI",    XD_READ },
  8123. X#endif
  8124. X#if    defined(TADPOLE)
  8125. X/*
  8126. X * Tadpole
  8127. X */
  8128. X    { 19,        "PC IDE",            IDE_READ },
  8129. X#endif    /* TADPOLE */
  8130. X    { 0 },
  8131. X};
  8132. X
  8133. X/*
  8134. X * Table of known Sun Frame Buffers
  8135. X */
  8136. XNAMETAB FBTab[] = {
  8137. X#ifdef FBTYPE_SUN2BW
  8138. X    {  FBTYPE_SUN2BW,        "Black & White memory (bwtwo)" },
  8139. X#endif
  8140. X#ifdef FBTYPE_SUN2COLOR
  8141. X    {  FBTYPE_SUN2COLOR,    "Color Graphics w/rasterop (cgtwo)" },
  8142. X#endif
  8143. X#ifdef FBTYPE_SUN2GP
  8144. X    {  FBTYPE_SUN2GP,        "GS Graphics Processor (cgtwelve)" },
  8145. X#endif
  8146. X#ifdef FBTYPE_SUN5COLOR
  8147. X    {  FBTYPE_SUN5COLOR,    "Sun-386i Accelerated Color" },
  8148. X#endif
  8149. X#ifdef FBTYPE_SUN3COLOR
  8150. X    {  FBTYPE_SUN3COLOR,    "8-bit Color (cgthree)" },
  8151. X#endif
  8152. X#ifdef FBTYPE_MEMCOLOR
  8153. X    {  FBTYPE_MEMCOLOR,        "B&W memory overlay plane (bwtwo)" },
  8154. X#endif
  8155. X#ifdef FBTYPE_SUN4COLOR
  8156. X    {  FBTYPE_SUN4COLOR,    "Color memory w/overlay (cgfour)" },
  8157. X#endif
  8158. X#ifdef FBTYPE_SUNFAST_COLOR
  8159. X    {  FBTYPE_SUNFAST_COLOR,    "GX 8-bit Accelerated Color (cgsix)" },
  8160. X#endif
  8161. X#ifdef FBTYPE_SUNROP_COLOR
  8162. X    {  FBTYPE_SUNROP_COLOR,    "24-bit Color w/rasterop" },
  8163. X#endif
  8164. X#ifdef FBTYPE_SUNFB_VIDEO
  8165. X    {  FBTYPE_SUNFB_VIDEO,    "Video Mixing" },
  8166. X#endif
  8167. X#ifdef FBTYPE_SUNGIFB
  8168. X    {  FBTYPE_SUNGIFB,        "Medical Imaging" },
  8169. X#endif
  8170. X#ifdef FBTYPE_SUNGPLAS
  8171. X    {  FBTYPE_SUNGPLAS,        "Plasma Panel" },
  8172. X#endif
  8173. X#ifdef FBTYPE_SUNGP3
  8174. X    {  FBTYPE_SUNGP3,        "24-bit Accelerated GPSI Color" },
  8175. X#endif
  8176. X#ifdef FBTYPE_SUNGT
  8177. X    {  FBTYPE_SUNGT,        "24-bit Color Graphics Accelerator (gt)" },
  8178. X#endif
  8179. X/*
  8180. X * Tadpole frame buffer's
  8181. X */
  8182. X#if    defined(TADPOLE)
  8183. X#ifdef FBTYPE_NOTSUN1
  8184. X    {  FBTYPE_NOTSUN1,        "VGA Graphics Card" },
  8185. X#endif
  8186. X#endif    /* TADPOLE */
  8187. X    { 0 },
  8188. X};
  8189. X
  8190. X/*
  8191. X * Magnetic Tape Info.
  8192. X *
  8193. X * This info is based on <sys/mtio.h>.  It would be nice to just
  8194. X * use that info, but not all systems have MT_TAPE_INFO.
  8195. X */
  8196. XNAMETAB MtInfo[] = {
  8197. X#ifdef MT_ISCPC
  8198. X    {  MT_ISCPC,        "TapeMaster 1/2-inch" },
  8199. X#endif
  8200. X#ifdef MT_ISXY
  8201. X    {  MT_ISXY,            "Xylogics 472 1/2-inch" },
  8202. X#endif
  8203. X#ifdef MT_ISAR
  8204. X    {  MT_ISAR,            "Archive QIC-11" },
  8205. X#endif
  8206. X#ifdef MT_ISSYSGEN11
  8207. X    {  MT_ISSYSGEN11,        "Sysgen QIC-11" },
  8208. X#endif
  8209. X#ifdef MT_ISSYSGEN
  8210. X    {  MT_ISSYSGEN,        "Sysgen QIC-24" },
  8211. X#endif
  8212. X#ifdef MT_ISMT02
  8213. X    {  MT_ISMT02,        "Emulex MT-02 QIC-24" },
  8214. X#endif
  8215. X#ifdef MT_ISVIPER1
  8216. X    {  MT_ISVIPER1,        "Archive QIC-150" },
  8217. X#endif
  8218. X#ifdef MT_ISWANGTEK1
  8219. X    {  MT_ISWANGTEK1,        "Wangtek QIC-150" },
  8220. X#endif
  8221. X#ifdef MT_ISKENNEDY
  8222. X    {  MT_ISKENNEDY,        "Kennedy 9612 1/2-inch" },
  8223. X#endif
  8224. X#ifdef MT_ISHP
  8225. X    {  MT_ISHP,            "HP 88780 1/2-inch" },
  8226. X#endif
  8227. X#ifdef MT_ISEXABYTE
  8228. X    {  MT_ISEXABYTE,        "Exabyte EXB-8200 8mm" },
  8229. X#endif
  8230. X#ifdef MT_ISEXB8500
  8231. X    {  MT_ISEXB8500,        "Exabyte EXB-8500 8mm" },
  8232. X#endif
  8233. X    { 0 },
  8234. X};
  8235. END_OF_info-sunos.c
  8236. if test 16354 -ne `wc -c <info-sunos.c`; then
  8237.     echo shar: \"info-sunos.c\" unpacked with wrong size!
  8238. fi
  8239. # end of overwriting check
  8240. fi
  8241. if test -f os-ultrix.c -a "${1}" != "-c" ; then 
  8242.   echo shar: Will not over-write existing file \"os-ultrix.c\"
  8243. else
  8244. echo shar: Extracting \"os-ultrix.c\" \(19334 characters\)
  8245. sed "s/^X//" >os-ultrix.c <<'END_OF_os-ultrix.c'
  8246. X/*
  8247. X * Copyright (c) 1992 Michael A. Cooper.
  8248. X * This software may be freely distributed provided it is not sold for 
  8249. X * profit and the author is credited appropriately.
  8250. X */
  8251. X
  8252. X#ifndef lint
  8253. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/os-ultrix.c,v 1.14 1992/04/26 23:32:06 mcooper Exp $";
  8254. X#endif
  8255. X
  8256. X/*
  8257. X * $Log: os-ultrix.c,v $
  8258. X * Revision 1.14  1992/04/26  23:32:06  mcooper
  8259. X * Add Copyright notice
  8260. X *
  8261. X * Revision 1.13  1992/04/17  23:27:51  mcooper
  8262. X * Add support for ROM Version information (Sun only for now).
  8263. X *
  8264. X * Revision 1.12  1992/04/17  01:07:59  mcooper
  8265. X * More de-linting
  8266. X *
  8267. X * Revision 1.11  1992/04/16  19:56:24  mcooper
  8268. X * De-linting stuff.
  8269. X *
  8270. X * Revision 1.10  1992/04/15  02:04:16  mcooper
  8271. X * Change GetMemoryStr() to GetMemory().
  8272. X *
  8273. X * Revision 1.9  1992/03/31  02:22:03  mcooper
  8274. X * Fix failed return value from CheckNlist().
  8275. X *
  8276. X * Revision 1.8  1992/03/31  01:55:17  mcooper
  8277. X * Use new CheckNlist to check nlist success.
  8278. X *
  8279. X * Revision 1.7  1992/03/31  00:15:09  mcooper
  8280. X * Add error check for nlist.n_type.
  8281. X *
  8282. X * Revision 1.6  1992/03/22  00:20:10  mcooper
  8283. X * Major cleanup and re-org.
  8284. X *
  8285. X * Revision 1.5  1992/03/09  01:07:50  mcooper
  8286. X * Add support for determining system model type.
  8287. X *
  8288. X * Revision 1.4  1992/03/08  23:08:41  mcooper
  8289. X * - Add new set_macinfo_packetfilter().
  8290. X * - Remove unneeded get_bus().
  8291. X *
  8292. X * Revision 1.3  1992/03/08  04:57:09  mcooper
  8293. X * Set DT_TAPEDRIVE in probe_tapedrive().
  8294. X *
  8295. X * Revision 1.2  1992/03/08  01:11:39  mcooper
  8296. X * Add tape drive support.
  8297. X *
  8298. X * Revision 1.1  1992/03/06  18:35:40  mcooper
  8299. X * Initial revision
  8300. X *
  8301. X */
  8302. X
  8303. X/*
  8304. X * Ultrix specific functions
  8305. X */
  8306. X
  8307. X#include <stdio.h>
  8308. X#include "system.h"
  8309. X#include "defs.h"
  8310. X
  8311. X#include <fcntl.h>
  8312. X#include <nlist.h>
  8313. X#include <fstab.h>
  8314. X#include <sys/types.h>
  8315. X#include <sys/param.h>
  8316. X#include <sys/fs.h>
  8317. X#include <sys/ioctl.h>
  8318. X#include <sys/buf.h>
  8319. X#include <sys/stat.h>
  8320. X
  8321. X#include <machine/cpuconf.h>
  8322. X
  8323. X#include <sys/devio.h>
  8324. X#include <sys/mtio.h>
  8325. X
  8326. X#include "info-ultrix.h"
  8327. X
  8328. X#if    defined(HAVE_UBA)
  8329. X/*
  8330. X * UBA (UniBus Adapter) specific code
  8331. X */
  8332. X#include <io/uba/ubavar.h>
  8333. X
  8334. X/*
  8335. X * Probe specific structure
  8336. X */
  8337. Xstruct _probespec {
  8338. X    struct uba_device        *uba_device;
  8339. X};
  8340. Xtypedef struct _probespec PROBESPEC;
  8341. X
  8342. X#define DV_SIZE        (sizeof(struct uba_device))
  8343. X#define CR_SIZE        (sizeof(struct uba_ctlr))
  8344. X
  8345. X/*
  8346. X * Build a device tree by searching Unibus Adapters
  8347. X */
  8348. Xstatic int BuildUBA(TreePtr)
  8349. X    DEVICE               **TreePtr;
  8350. X{
  8351. X    extern struct nlist     UniBusNL[];
  8352. X    static struct uba_device     Device;
  8353. X    static struct uba_ctlr     Ctlr;
  8354. X    static char         CtlrName[BUFSIZ], DevName[BUFSIZ];
  8355. X    u_long             Addr, DeviceAddr;
  8356. X    static DEVDATA         DevData;
  8357. X    static PROBESPEC        ProbeSpec;
  8358. X    DEVICE                *dev;
  8359. X    kvm_t               *kd;
  8360. X    int             cnum;
  8361. X
  8362. X    /*
  8363. X     * Read table address from kernel
  8364. X     */
  8365. X    if (!(kd = KVM_open(UniBusNL))) {
  8366. X    if (Debug) Error("Cannot read unibus device table from kernel.");
  8367. X    return(-1);
  8368. X    }
  8369. X
  8370. X    /*
  8371. X     * See if we got a valid entry
  8372. X     */
  8373. X    if (CheckNlist(&UniBusNL[0]))
  8374. X    return(-1);
  8375. X
  8376. X    /*
  8377. X     * Read each device table entry.  A NULL device.ui_driver
  8378. X     * indicates that we're at the end of the table.
  8379. X     */
  8380. X    for (DeviceAddr = UniBusNL[0].n_value; DeviceAddr; 
  8381. X     DeviceAddr += DV_SIZE) {
  8382. X
  8383. X    /*
  8384. X     * Read this device
  8385. X     */
  8386. X    if (KVM_read(kd, DeviceAddr, (char *) &Device, DV_SIZE)) {
  8387. X        if (Debug) 
  8388. X        Error("Cannot read unibus device from address 0x%x.", 
  8389. X              DeviceAddr);
  8390. X        KVM_close(kd);
  8391. X        return(-1);
  8392. X    }
  8393. X
  8394. X    /*
  8395. X     * See if we're done.
  8396. X     */
  8397. X    if (!Device.ui_driver)
  8398. X        break;
  8399. X
  8400. X    /*
  8401. X     * Get the device name
  8402. X     */
  8403. X    DevName[0] = C_NULL;
  8404. X    if (Addr = (u_long) Device.ui_devname) {
  8405. X        if (KVM_read(kd, Addr, (char *) DevName, sizeof(DevName))) {
  8406. X        if (Debug)
  8407. X            Error("Cannot read device name from address 0x%x.", Addr);
  8408. X        continue;
  8409. X        }
  8410. X    }
  8411. X
  8412. X    /*
  8413. X     * Get the controller info
  8414. X     */
  8415. X    CtlrName[0] = C_NULL;
  8416. X    cnum = -1;
  8417. X    if (Addr = (u_long) Device.ui_mi) {
  8418. X        if (KVM_read(kd, Addr, (char *) &Ctlr, CR_SIZE)) {
  8419. X        if (Debug) 
  8420. X            Error("Cannot read controller from address 0x%x.", Addr);
  8421. X        } else {
  8422. X        /*
  8423. X         * Get the controller name
  8424. X         */
  8425. X        if (Addr = (u_long) Ctlr.um_ctlrname) {
  8426. X            if (KVM_read(kd, Addr, CtlrName, sizeof(CtlrName))) {
  8427. X            if (Debug)
  8428. X                Error(
  8429. X          "Cannot read controller name from driver address 0x%x.",
  8430. X                  Addr);
  8431. X            continue;
  8432. X            }
  8433. X        }
  8434. X        cnum = Ctlr.um_ctlr;
  8435. X        }
  8436. X    }
  8437. X
  8438. X    if (Debug)
  8439. X        printf("build_unibus(): Found '%s' on '%s'.\n", DevName, CtlrName);
  8440. X
  8441. X    /* Make sure devdata is clean */
  8442. X    bzero(&DevData, sizeof(DEVDATA));
  8443. X
  8444. X    /* Set what we know */
  8445. X    if (DevName[0]) {
  8446. X        DevData.dd_devname = strdup(DevName);
  8447. X        DevData.dd_devunit = Device.ui_unit;
  8448. X    }
  8449. X    if (CtlrName[0]) {
  8450. X        DevData.dd_ctlrname = strdup(CtlrName);
  8451. X        DevData.dd_ctlrunit = cnum;
  8452. X    }
  8453. X
  8454. X    /* 
  8455. X     * Unibus devices should always exist.
  8456. X     */
  8457. X    if (Device.ui_alive)
  8458. X        DevData.dd_flags |= DD_IS_ALIVE;
  8459. X
  8460. X    ProbeSpec.uba_device = &Device;
  8461. X
  8462. X    /* Probe and add device */
  8463. X    if (dev = (DEVICE *) ProbeDevice(&DevData, TreePtr, &ProbeSpec))
  8464. X        AddDevice(dev, TreePtr);
  8465. X    }
  8466. X
  8467. X    KVM_close(kd);
  8468. X
  8469. X    return(0);
  8470. X}
  8471. X#endif    /* HAVE_UBA */
  8472. X
  8473. X/*
  8474. X * Build list of Ultrix devices
  8475. X */
  8476. Xextern int BuildDevicesUltrix(TreePtr)
  8477. X    DEVICE               **TreePtr;
  8478. X{
  8479. X    int                Found = 1;
  8480. X
  8481. X#if    defined(HAVE_UBA)
  8482. X    if (BuildUBA(TreePtr) == 0)
  8483. X    Found = 0;
  8484. X#endif    /* HAVE_UBA */
  8485. X
  8486. X    return(Found);
  8487. X}
  8488. X
  8489. X/*
  8490. X * Get Device Info structure from device.
  8491. X */
  8492. Xstatic struct devget *GETdevget(File, FileD)
  8493. X    char               *File;
  8494. X    int             FileD;
  8495. X{
  8496. X    static struct devget     devget;
  8497. X
  8498. X    if (ioctl(FileD, DEVIOCGET, &devget) == SYSFAIL) {
  8499. X    if (Debug) Error("%s: ioctl DEVIOCGET failed: %s.", File, SYSERR);
  8500. X    return((struct devget *) NULL);
  8501. X    }
  8502. X
  8503. X    return(&devget);
  8504. X}
  8505. X
  8506. X/*
  8507. X * Get Device Geometry structure from device.
  8508. X */
  8509. Xstatic DEVGEOMST *GETdevgeom(File, FileD)
  8510. X    char               *File;
  8511. X    int             FileD;
  8512. X{
  8513. X    static DEVGEOMST         devgeom;
  8514. X
  8515. X    if (ioctl(FileD, DEVGETGEOM, &devgeom) == SYSFAIL) {
  8516. X    if (Debug) Error("%s: ioctl DEVGETGEOM failed: %s.", File, SYSERR);
  8517. X    return((DEVGEOMST *) NULL);
  8518. X    }
  8519. X
  8520. X    return(&devgeom);
  8521. X}
  8522. X
  8523. X/*
  8524. X * Lookup a category type.
  8525. X */
  8526. Xstatic char *GetCategory(val)
  8527. X    int                val;
  8528. X{
  8529. X    extern NAMETAB            Categorys[];
  8530. X    register int         i;
  8531. X
  8532. X    for (i = 0; Categorys[i].name; ++i)
  8533. X    if (val == Categorys[i].value)
  8534. X        return(Categorys[i].name);
  8535. X
  8536. X    return((char *) NULL);
  8537. X}
  8538. X
  8539. X/*
  8540. X * Convert a 'devget' to a 'device'.
  8541. X */
  8542. Xstatic DEVICE *devgetToDEVICE(DevGet, DevData, ProbeSpec)
  8543. X    struct devget           *DevGet;
  8544. X    DEVDATA               *DevData;
  8545. X    PROBESPEC               *ProbeSpec;
  8546. X{
  8547. X    DEVICE               *Device;
  8548. X
  8549. X    if (!(Device = NewDevice(NULL)))
  8550. X    return(Device);
  8551. X
  8552. X    Device->dv_name    = strdup(MkDevName(DevData->dd_devname,
  8553. X                       DevData->dd_devunit));
  8554. X    Device->dv_model    = strdup(DevGet->device);
  8555. X    Device->dv_desc    = GetCategory(DevGet->category);
  8556. X    Device->dv_unit    = DevGet->unit_num;
  8557. X
  8558. X    /*
  8559. X     * Set master/controller info
  8560. X     */
  8561. X    if (Device->dv_master = MkMasterFromDevData(DevData))
  8562. X    Device->dv_master->dv_model = strdup(DevGet->interface);
  8563. X
  8564. X    return(Device);
  8565. X}
  8566. X
  8567. X/*
  8568. X * Check a device by trying to perform a devget on it.
  8569. X */
  8570. Xstatic struct devget *CheckDevice(File)
  8571. X    char               *File;
  8572. X{
  8573. X    struct devget           *DevGet;
  8574. X    int                d;
  8575. X
  8576. X    if ((d = open(File, O_RDONLY|O_NDELAY)) < 0) {
  8577. X    if (Debug) Error("%s: Cannot open: %s.", File, SYSERR);
  8578. X    return((struct devget *) NULL);
  8579. X    }
  8580. X
  8581. X    /*
  8582. X     * Get generic device info
  8583. X     */
  8584. X    if (!(DevGet = GETdevget(File, d))) {
  8585. X    if (Debug) Error("%s: GETdevget failed.", File);
  8586. X    close(d);
  8587. X    return((struct devget *) NULL);
  8588. X    }
  8589. X
  8590. X    close(d);
  8591. X
  8592. X    return(DevGet);
  8593. X}
  8594. X
  8595. X/*
  8596. X * Retrieve disk partition information from a device file.
  8597. X */
  8598. Xstatic struct pt *ExtractDiskPart(File)
  8599. X    char               *File;
  8600. X{
  8601. X    static struct pt        pt;
  8602. X    int                d;
  8603. X
  8604. X    if ((d = open(File, O_RDONLY|O_NDELAY)) < 0) {
  8605. X    if (Debug) Error("%s: open failed: %s.", File, SYSERR);
  8606. X    return((struct pt *) NULL);
  8607. X    }
  8608. X
  8609. X    if (ioctl(d, DIOCGETPT, &pt) < 0) {
  8610. X    if (Debug) Error("%s: ioctl DIOCGETPT failed: %s.", File, SYSERR);
  8611. X    close(d);
  8612. X    return((struct pt *) NULL);
  8613. X    }
  8614. X
  8615. X    close(d);
  8616. X
  8617. X    return(&pt);
  8618. X}
  8619. X
  8620. X/*
  8621. X * Get the mount point for a filesystem.
  8622. X */
  8623. Xstatic char *GetMountInfo(Name, Part)
  8624. X    char               *Name;
  8625. X    char               *Part;
  8626. X{
  8627. X    char               *File;
  8628. X    struct fstab           *fstab;
  8629. X
  8630. X    File = GetCharFile(Name, Part);
  8631. X    if (fstab = getfsspec(File)) {
  8632. X    if (strcmp(fstab->fs_type, FSTAB_SW) == 0)
  8633. X        return("swap");
  8634. X    return(fstab->fs_file);
  8635. X    }
  8636. X
  8637. X    return((char *) NULL);
  8638. X}
  8639. X
  8640. X/*
  8641. X * Get the partition information for a disk device.
  8642. X */
  8643. Xstatic DISKPART *GetPartInfo(Name, Device)
  8644. X    char                *Name;
  8645. X    DEVICE               *Device;
  8646. X{
  8647. X    static DISKPART            diskpart;
  8648. X    static char            Buf[BUFSIZ], part[2];
  8649. X    register DISKPART           *pdp, *dp;
  8650. X    register char           *p;
  8651. X    DISKPART               *base = NULL;
  8652. X    struct pt               *pt;
  8653. X    register int        i;
  8654. X
  8655. X    /*
  8656. X     * First get the partition info.
  8657. X     */
  8658. X    (void) sprintf(Buf, "/dev/r%sa", Name);
  8659. X    if (!(pt = ExtractDiskPart(Buf)))
  8660. X    return((DISKPART *) NULL);
  8661. X
  8662. X    part[1] = C_NULL;
  8663. X
  8664. X    /*
  8665. X     * Now deal with each partition.
  8666. X     */
  8667. X    for (i = 0; i < MAX_DISK_PARTS; ++i) {
  8668. X    /* Ignore partitions that have no size */
  8669. X    if (!pt->pt_part[i].pi_nblocks)
  8670. X        continue;
  8671. X
  8672. X    part[0] = 'a' + i;
  8673. X
  8674. X    /* Make a clean slate */
  8675. X    bzero((char *) &diskpart, sizeof(DISKPART));
  8676. X
  8677. X    /* Fill in what we know */
  8678. X    diskpart.dp_name = strdup(part);
  8679. X    diskpart.dp_stsect = pt->pt_part[i].pi_blkoff;
  8680. X    diskpart.dp_nsect = pt->pt_part[i].pi_nblocks;
  8681. X
  8682. X    /* 
  8683. X     * Get the mount point name.
  8684. X     * If this is the "b" partition on the 
  8685. X     * root device, then assume it's swap 
  8686. X     */
  8687. X    if (p = GetMountInfo(Name, part))
  8688. X        diskpart.dp_mnt = strdup(p);
  8689. X    else if (Device->dv_unit == 0 && strcmp(part, "b") == 0)
  8690. X        diskpart.dp_mnt = "swap";
  8691. X
  8692. X    /*
  8693. X     * Add this partition to the linked list.
  8694. X     */
  8695. X    if (base) {
  8696. X        for (pdp = base; pdp && pdp->dp_nxt; pdp = pdp->dp_nxt);
  8697. X        pdp->dp_nxt = NewDiskPart(&diskpart);
  8698. X    } else {
  8699. X        base = NewDiskPart(&diskpart);
  8700. X    }
  8701. X    }
  8702. X
  8703. X    return(base);
  8704. X}
  8705. X
  8706. X/*
  8707. X * Probe a disk drive
  8708. X */
  8709. Xextern DEVICE *ProbeDiskDrive(Name, DevData, DevDataTab, ProbeSpec)
  8710. X    char               *Name;
  8711. X    DEVDATA               *DevData;
  8712. X    DEVDATATAB               *DevDataTab;
  8713. X    PROBESPEC               *ProbeSpec;
  8714. X{
  8715. X    DEVICE               *Device;
  8716. X    DISKDRIVE               *DiskDrive;
  8717. X    DEVGEOMST               *DevGeom;
  8718. X    struct devget           *DevGet;
  8719. X    char               *File;
  8720. X    int                Desc;
  8721. X
  8722. X    if (!Name)
  8723. X    return((DEVICE *) NULL);
  8724. X
  8725. X    File = GetRawFile(Name, "c");
  8726. X    if ((Desc = open(File, O_RDONLY|O_NDELAY)) < 0) {
  8727. X    if (Debug) Error("%s: open failed: %s.", File, SYSERR);
  8728. X    /*
  8729. X     * If we know for sure this drive is present and we
  8730. X     * know something about it, then create a minimal device.
  8731. X     */
  8732. X    if ((DevDataTab->ddt_model || DevDataTab->ddt_desc) &&
  8733. X        FLAGS_ON(DevData->dd_flags, DD_IS_ALIVE)) {
  8734. X        Device = NewDevice((DEVICE *) NULL);
  8735. X        Device->dv_name = strdup(Name);
  8736. X        Device->dv_unit = DevData->dd_devunit;
  8737. X        Device->dv_master = MkMasterFromDevData(DevData);
  8738. X        Device->dv_type = DT_DISKDRIVE;
  8739. X        Device->dv_model = DevDataTab->ddt_model;
  8740. X        Device->dv_desc = DevDataTab->ddt_desc;
  8741. X        return(Device);
  8742. X    } else
  8743. X        return((DEVICE *) NULL);
  8744. X    }
  8745. X
  8746. X    /*
  8747. X     * Get generic device info
  8748. X     */
  8749. X    if (!(DevGet = GETdevget(File, Desc))) {
  8750. X    if (Debug) Error("%s: GETdevget failed.", File);
  8751. X    close(Desc);
  8752. X    return((DEVICE *) NULL);
  8753. X    }
  8754. X
  8755. X    /*
  8756. X     * Get geometry of device
  8757. X     */
  8758. X    if (!(DevGeom = GETdevgeom(File, Desc))) {
  8759. X    if (Debug) Error("%s: get_geomst failed.", File);
  8760. X    }
  8761. X
  8762. X    close(Desc);
  8763. X
  8764. X    /*
  8765. X     * Convert devget info to a device struct
  8766. X     */
  8767. X    if (!(Device = devgetToDEVICE(DevGet, DevData, ProbeSpec))) {
  8768. X    if (Debug) Error("%s: Cannot convert devget to device.");
  8769. X    return((DEVICE *) NULL);
  8770. X    }
  8771. X
  8772. X    /*
  8773. X     * Disks should be on disk controllers.
  8774. X     */
  8775. X    if (Device->dv_master)
  8776. X    Device->dv_master->dv_type = DT_DISKCTLR;
  8777. X
  8778. X    /*
  8779. X     * Set the disk drive specific info
  8780. X     */
  8781. X
  8782. X    if ((DiskDrive = NewDiskDrive(NULL)) == NULL) {
  8783. X    Error("Cannot create new diskdrive entry.");
  8784. X    return((DEVICE *) NULL);
  8785. X    }
  8786. X
  8787. X    Device->dv_type         = DT_DISKDRIVE;
  8788. X    if (DevGet->device)
  8789. X    DiskDrive->dd_label     = strdup(DevGet->device);
  8790. X
  8791. X    /*
  8792. X     * Convert Geometry
  8793. X     */
  8794. X    if (DevGeom) {
  8795. X    /*
  8796. X     * If this is a removable device, indicate so.
  8797. X     */
  8798. X    if (FLAGS_ON(DevGeom->geom_info.attributes, DEVGEOM_REMOVE)) {
  8799. X        if (Device->dv_desc) {
  8800. X        char Buf[BUFSIZ];
  8801. X
  8802. X        (void) sprintf(Buf, "Removable %s", Device->dv_desc);
  8803. X        (void) free(Device->dv_desc);
  8804. X        Device->dv_desc = strdup(Buf);
  8805. X        } else {
  8806. X        Device->dv_desc = "Removable disk drive";
  8807. X        }
  8808. X    }
  8809. X
  8810. X    DiskDrive->dd_unit     = DevGet->unit_num;
  8811. X    DiskDrive->dd_slave     = DevGet->slave_num;
  8812. X    DiskDrive->dd_part     = GetPartInfo(Name, Device);
  8813. X    DiskDrive->dd_dcyl     = DevGeom->geom_info.ncylinders;
  8814. X    DiskDrive->dd_heads     = DevGeom->geom_info.ntracks;
  8815. X    DiskDrive->dd_sect     = DevGeom->geom_info.nsectors;
  8816. X    DiskDrive->dd_secsize     = SECSIZE;
  8817. X
  8818. X    if (DiskDrive->dd_dcyl && DiskDrive->dd_sect && DiskDrive->dd_heads) {
  8819. X        static char Buf[BUFSIZ];
  8820. X
  8821. X        DiskDrive->dd_size = nsect_to_bytes(DiskDrive->dd_dcyl * 
  8822. X                        DiskDrive->dd_sect * 
  8823. X                        DiskDrive->dd_heads, 
  8824. X                        DiskDrive->dd_secsize);
  8825. X
  8826. X        (void) sprintf(Buf, "%.2f MB capacity", 
  8827. X               (float) bytes_to_mbytes(DiskDrive->dd_size));
  8828. X        Device->dv_desc = strdup(Buf);
  8829. X    }
  8830. X    }
  8831. X    Device->dv_devspec = (caddr_t *) DiskDrive;
  8832. X
  8833. X    return(Device);
  8834. X}
  8835. X
  8836. X/*
  8837. X * Lookup info about a tape drive.
  8838. X */
  8839. Xstatic char *GetTapeInfo(Flag)
  8840. X    int                Flag;
  8841. X{
  8842. X    extern NAMETAB        TapeInfo[];
  8843. X    static char            Buf[BUFSIZ];
  8844. X    register int        i;
  8845. X
  8846. X    if (!Flag)
  8847. X    return((char *) NULL);
  8848. X
  8849. X    Buf[0] = C_NULL;
  8850. X
  8851. X    /*
  8852. X     * Values are flag bits and are appended together.
  8853. X     */
  8854. X    for (i = 0; TapeInfo[i].name; i++) {
  8855. X    if (Flag & TapeInfo[i].value) {
  8856. X        if (Buf[0]) {
  8857. X        (void) strcat(Buf, ", ");
  8858. X        (void) strcat(Buf, TapeInfo[i].name);
  8859. X        } else
  8860. X        (void) strcpy(Buf, TapeInfo[i].name);
  8861. X    }
  8862. X    }
  8863. X
  8864. X    return(Buf);
  8865. X}
  8866. X
  8867. X/*
  8868. X * Probe a tape drive
  8869. X */
  8870. Xextern DEVICE *ProbeTapeDrive(Name, DevData, DevDataTab, ProbeSpec)
  8871. X    char               *Name;
  8872. X    DEVDATA               *DevData;
  8873. X    DEVDATATAB               *DevDataTab;
  8874. X    PROBESPEC               *ProbeSpec;
  8875. X{
  8876. X    struct devget           *DevGet;
  8877. X    DEVICE               *Device;
  8878. X    char               *File;
  8879. X    char               *p;
  8880. X    char                Buf[BUFSIZ];
  8881. X    register int        i;
  8882. X
  8883. X    /*
  8884. X     * XXX Kludge Alert! ! !
  8885. X     *
  8886. X     * Ultrix tape device files are numbered independently of actual
  8887. X     * unit number.  Additionally, not all tape devices support the same
  8888. X     * set of minor devices types, so we can't look at the minor device 
  8889. X     * number.  
  8890. X     *
  8891. X     * The code below will open(), ioctl(), close() all tape
  8892. X     * devices between 0 and MAXTAPES until a matching unit number is found.
  8893. X     * This means that on systems with lots of tape drives, this can be 
  8894. X     * very slow.
  8895. X     */
  8896. X    for (i = 0; i < MAXTAPES; ++i) {
  8897. X    (void) sprintf(Buf, "/dev/nrmt%dh", i);
  8898. X    if ((DevGet = CheckDevice(Buf)) && 
  8899. X        (DevGet->unit_num == DevData->dd_devunit))
  8900. X        break;
  8901. X    }
  8902. X
  8903. X    if (!DevGet) {
  8904. X    if (Debug) Error("%s: Cannot find device file.", Name);
  8905. X    return((DEVICE *) NULL);
  8906. X    }
  8907. X
  8908. X    /*
  8909. X     * Convert devget info to a device struct
  8910. X     */
  8911. X    if (!(Device = devgetToDEVICE(DevGet, DevData, ProbeSpec))) {
  8912. X    if (Debug) Error("%s: Cannot convert devget to device.");
  8913. X    return((DEVICE *) NULL);
  8914. X    }
  8915. X
  8916. X    /*
  8917. X     * Set our device type
  8918. X     */
  8919. X    Device->dv_type = DT_TAPEDRIVE;
  8920. X
  8921. X    /*
  8922. X     * Get and add Tape Info
  8923. X     */
  8924. X    if (p = GetTapeInfo(DevGet->category_stat)) {
  8925. X    if (Device->dv_desc) {
  8926. X        (void) sprintf(Buf, "%s %s", p, Device->dv_desc);
  8927. X        free(Device->dv_desc);
  8928. X        Device->dv_desc = strdup(Buf);
  8929. X    } else {
  8930. X        Device->dv_desc = p;
  8931. X    }
  8932. X    }
  8933. X
  8934. X    /*
  8935. X     * Tapes should be on tape controllers.
  8936. X     */
  8937. X    if (Device->dv_master)
  8938. X    Device->dv_master->dv_type = DT_TAPECTLR;
  8939. X
  8940. X    return(Device);
  8941. X}
  8942. X
  8943. X/*
  8944. X * Get network type information
  8945. X */
  8946. Xstatic char *GetNetType(type)
  8947. X    int                type;
  8948. X{
  8949. X    extern NAMETAB        NetTypes[];
  8950. X    register int        i;
  8951. X
  8952. X    for (i = 0; NetTypes[i].name; i++)
  8953. X    if (NetTypes[i].value == type)
  8954. X        return(NetTypes[i].name);
  8955. X
  8956. X    return((char *) NULL);
  8957. X}
  8958. X
  8959. X
  8960. X#if    defined(HAVE_PACKETFILTER)
  8961. X
  8962. X#include <sys/time.h>
  8963. X#include <net/pfilt.h>
  8964. X
  8965. X#include <sys/socket.h>
  8966. X#include <net/if.h>
  8967. X#include <netinet/in.h>
  8968. X#include <netinet/if_ether.h>
  8969. X
  8970. X/*
  8971. X * Find and set the MAC info using the Packet Filter
  8972. X */
  8973. Xextern void SetMacInfoPacketFilter(DevName, Netif, Device)
  8974. X     char                *DevName;
  8975. X     NETIF                *Netif;
  8976. X     DEVICE               *Device;
  8977. X{
  8978. X    struct endevp        endevp;
  8979. X    struct ether_addr        ether_addr;
  8980. X    char                *ether_ntoa(), HostBuf[MAXHOSTNAMLEN+1];
  8981. X    char                *p;
  8982. X    int                 Desc;
  8983. X
  8984. X    if (!DevName || !Netif)
  8985. X    return;
  8986. X
  8987. X    /*
  8988. X     * Open this device using the packet filter
  8989. X     */
  8990. X    if ((Desc = pfopen(DevName, O_RDONLY)) < 0) {
  8991. X    if (Debug) Error("pfopen %s failed: %s.", DevName, SYSERR);
  8992. X    return;
  8993. X    }
  8994. X
  8995. X    /*
  8996. X     * Retrieve info
  8997. X     */
  8998. X    if (ioctl(Desc, EIOCDEVP, &endevp) < 0) {
  8999. X    if (Debug) Error("ioctl EIOCDEVP of %s failed: %s.", DevName, SYSERR);
  9000. X    return;
  9001. X    }
  9002. X
  9003. X    close(Desc);
  9004. X
  9005. X    /*
  9006. X     * Convert address into ethers(5) format
  9007. X     */
  9008. X    bcopy((char *) endevp.end_addr,
  9009. X      (char *) ether_addr.ether_addr_octet,
  9010. X      endevp.end_addr_len);
  9011. X
  9012. X    /*
  9013. X     * Set what we now know.
  9014. X     */
  9015. X    if (p = ether_ntoa(ðer_addr))
  9016. X    Netif->ni_macaddr = strdup(p);
  9017. X
  9018. X    if (ether_ntohost(HostBuf, ðer_addr) == 0)
  9019. X    Netif->ni_macname = strdup(HostBuf);
  9020. X
  9021. X    if (Device && (p = GetNetType(endevp.end_dev_type)))
  9022. X    Device->dv_desc = p;
  9023. X}
  9024. X#endif    /* HAVE_PACKETFILTER */
  9025. X
  9026. X/*
  9027. X * Get the system model name.  Ultrix keeps the system type
  9028. X * in a kernel structure called cpusw as cpusw.system_type.
  9029. X * The system types are defined in <machine/cpuconf.h>.
  9030. X */
  9031. Xextern char *GetModelName()
  9032. X{
  9033. X    extern NAMETAB        ModelTab[];
  9034. X    extern struct nlist        CpuSwNL[];
  9035. X    static struct cpusw            CpuSw;
  9036. X    register int        i;
  9037. X    kvm_t               *kd;
  9038. X
  9039. X    if (!(kd = KVM_open(CpuSwNL))) {
  9040. X    if (Debug) Error("Cannot find cpusw symbol in kernel.");
  9041. X    return((char *) NULL);
  9042. X    }
  9043. X
  9044. X    /*
  9045. X     * See if we got a valid entry
  9046. X     */
  9047. X    if (CheckNlist(&CpuSwNL[0]))
  9048. X    return((char *) NULL);
  9049. X
  9050. X    if (KVM_read(kd, (u_long) CpuSwNL[0].n_value, (char *) &CpuSw,
  9051. X         sizeof(struct cpusw))) {
  9052. X    if (Debug) Error("Cannot read cpusw from kernel.");
  9053. X    return((char *) NULL);
  9054. X    }
  9055. X
  9056. X    KVM_close(kd);
  9057. X
  9058. X    for (i = 0; ModelTab[i].name; ++i)
  9059. X    if (ModelTab[i].value == CpuSw.system_type)
  9060. X        return(ModelTab[i].name);
  9061. X
  9062. X    if (Debug)
  9063. X    printf("system model/type %d is unknown.\n", CpuSw.system_type);
  9064. X
  9065. X    return((char *) NULL);
  9066. X}
  9067. X
  9068. X/*
  9069. X * Get kernel version string from kernel symbol "version".
  9070. X */
  9071. Xextern char *GetKernelVersionStr()
  9072. X{
  9073. X    return(GetKernelVersionFromVersion());
  9074. X}
  9075. X
  9076. X/*
  9077. X * Get amount of physical memory using kernel symbol "physmem".
  9078. X */
  9079. Xextern char *GetMemory()
  9080. X{
  9081. X    return(GetMemoryFromPhysmem());
  9082. X}
  9083. X
  9084. X/*
  9085. X * Get system serial number
  9086. X */
  9087. Xextern char *GetSerialNoStr()
  9088. X{
  9089. X    /* No support */
  9090. X    return((char *) NULL);
  9091. X}
  9092. X
  9093. X/*
  9094. X * Get name of OS
  9095. X */
  9096. Xextern char *GetOSNameStr()
  9097. X{
  9098. X    return(GetOSNameFromUname());
  9099. X}
  9100. X
  9101. X/*
  9102. X * Get version of OS
  9103. X */
  9104. Xextern char *GetOSVersionStr()
  9105. X{
  9106. X    return(GetOSVersionFromUname());
  9107. X}
  9108. X
  9109. X/*
  9110. X * Get ROM Version
  9111. X */
  9112. Xextern char *GetRomVer()
  9113. X{
  9114. X    /* No support */
  9115. X    return((char *) NULL);
  9116. X}
  9117. END_OF_os-ultrix.c
  9118. if test 19334 -ne `wc -c <os-ultrix.c`; then
  9119.     echo shar: \"os-ultrix.c\" unpacked with wrong size!
  9120. fi
  9121. # end of overwriting check
  9122. fi
  9123. if test -f info-ultrix.c -a "${1}" != "-c" ; then 
  9124.   echo shar: Will not over-write existing file \"info-ultrix.c\"
  9125. else
  9126. echo shar: Extracting \"info-ultrix.c\" \(8452 characters\)
  9127. sed "s/^X//" >info-ultrix.c <<'END_OF_info-ultrix.c'
  9128. X/*
  9129. X * Copyright (c) 1992 Michael A. Cooper.
  9130. X * This software may be freely distributed provided it is not sold for 
  9131. X * profit and the author is credited appropriately.
  9132. X */
  9133. X
  9134. X#ifndef lint
  9135. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/info-ultrix.c,v 1.8 1992/04/26 23:32:06 mcooper Exp $";
  9136. X#endif
  9137. X
  9138. X/*
  9139. X * $Log: info-ultrix.c,v $
  9140. X * Revision 1.8  1992/04/26  23:32:06  mcooper
  9141. X * Add Copyright notice
  9142. X *
  9143. X * Revision 1.7  1992/04/17  01:10:11  mcooper
  9144. X * Moved DEVICE *() function declares to defs.h.
  9145. X *
  9146. X * Revision 1.6  1992/03/28  21:29:24  mcooper
  9147. X * Move NetifNL to netif.c.
  9148. X *
  9149. X * Revision 1.5  1992/03/22  00:20:10  mcooper
  9150. X * Major cleanup and re-org.
  9151. X *
  9152. X * Revision 1.4  1992/03/09  01:07:50  mcooper
  9153. X * Add support for determining system model type.
  9154. X *
  9155. X * Revision 1.3  1992/03/08  23:08:18  mcooper
  9156. X * Make things safe with #ifdef's.
  9157. X *
  9158. X * Revision 1.2  1992/03/08  04:56:52  mcooper
  9159. X * Add network interface devices.
  9160. X *
  9161. X * Revision 1.1  1992/03/06  18:35:31  mcooper
  9162. X * Initial revision
  9163. X *
  9164. X */
  9165. X
  9166. X/*
  9167. X * Ultrix related information
  9168. X */
  9169. X
  9170. X#include <stdio.h>
  9171. X#include "system.h"
  9172. X#include "defs.h"
  9173. X
  9174. X#include <machine/cpuconf.h>
  9175. X
  9176. X#if    defined(HAVE_PACKETFILTER)
  9177. X#include <sys/time.h>
  9178. X#include <net/pfilt.h>
  9179. X#endif    /* HAVE_PACKETFILTER */
  9180. X
  9181. X#include <nlist.h>
  9182. X#include <sys/devio.h>
  9183. X
  9184. X/*
  9185. X * CPU Switch symbol
  9186. X */
  9187. Xstruct nlist CpuSwNL[] = {
  9188. X#if    defined(COFF)
  9189. X    { "cpusw" },
  9190. X#else
  9191. X    { "_cpusw" },
  9192. X#endif    /* COFF */
  9193. X    { 0 },
  9194. X};
  9195. X
  9196. X#if    defined(HAVE_UBA)
  9197. X/*
  9198. X * UniBus name list
  9199. X */
  9200. Xstruct nlist UniBusNL[] = {
  9201. X#if    defined(COFF)
  9202. X    { "ubdinit" },
  9203. X#else
  9204. X    { "_ubdinit" },
  9205. X#endif    /* COFF */
  9206. X    { 0 },
  9207. X};
  9208. X#endif    /* HAVE_UBA */
  9209. X
  9210. X/*
  9211. X * Device Data Table
  9212. X *
  9213. X * Compares are done by the length of the string appearing in
  9214. X * the first columns.  Therefore, longer names must appear before
  9215. X * any shorter names that are not unique.  e.g. "lebuffer" needs to
  9216. X * be before "le".
  9217. X */
  9218. XDEVDATATAB DevDataTab[] = {
  9219. X    /*
  9220. X     * Disk Drives
  9221. X     */
  9222. X    { "fd",        0,        NULL,    NULL,    ProbeDiskDrive },
  9223. X    { "ra",        0,        NULL,    NULL,    ProbeDiskDrive },
  9224. X    { "rz",        0,        NULL,    NULL,    ProbeDiskDrive },
  9225. X    /*
  9226. X     * Tape Drives
  9227. X     */
  9228. X    { "mu",        0,        NULL,    NULL,    ProbeTapeDrive },
  9229. X    { "stc",        0,        NULL,    NULL,    ProbeTapeDrive },
  9230. X    { "tms",        0,        NULL,    NULL,    ProbeTapeDrive },
  9231. X    { "ts",        0,        NULL,    NULL,    ProbeTapeDrive },
  9232. X    { "tu",        0,        NULL,    NULL,    ProbeTapeDrive },
  9233. X    { "tz",        0,        NULL,    NULL,    ProbeTapeDrive },
  9234. X    /*
  9235. X     * Network Interfaces
  9236. X     */
  9237. X    { "ln",        0,          "LANCE Ethernet",
  9238. X                      "10Mb/sec Ethernet",    ProbeNetif },
  9239. X    { "de",        0,          "DEC Ethernet",
  9240. X                      "10Mb/sec Ethernet",    ProbeNetif },
  9241. X    { "ni",        0,          "DEC Ethernet",        
  9242. X                    "10Mb/sec Ethernet",    ProbeNetif },
  9243. X    { "qe",        0,          "DEQNA/DELQA Ethernet",    
  9244. X                    "10Mb/sec Ethernet",    ProbeNetif },
  9245. X    { "ne",        0,          "Second Generation Ethernet",    
  9246. X                    "10Mb/sec Ethernet",    ProbeNetif },
  9247. X    { "xna",        0,          "DEBNI/DEMNA Ethernet",
  9248. X                    "10Mb/sec Ethernet",    ProbeNetif },
  9249. X    { "fza",        0,          "DEFZA FDDI",
  9250. X                      "100Mb/sec FDDI",    ProbeNetif },
  9251. X    /*
  9252. X     * I don't know anything about Ultrix frame buffers
  9253. X     */
  9254. X    { "cfb",        0,          NULL,
  9255. X      "Color Frame Buffer",                ProbeGeneric },
  9256. X    { "pm",        0,          NULL,
  9257. X      "Graphics Device",                ProbeGeneric },
  9258. X    { "px",        0,          NULL,
  9259. X      "Graphics Device",                ProbeGeneric },
  9260. X    { "ga",        0,          NULL,
  9261. X      "Graphics Device",                ProbeGeneric },
  9262. X    { "gq",        0,          NULL,
  9263. X      "Graphics Device",                ProbeGeneric },
  9264. X    { "fb",        0,          NULL,
  9265. X      "Graphics Device",                ProbeGeneric },
  9266. X    /*
  9267. X     * PrestoServe card (untested).
  9268. X     */
  9269. X    { "presto",        DT_GENERIC,    
  9270. X      "PrestoServe",    
  9271. X      "NFS accelerator card",            ProbeGeneric },
  9272. X    /*
  9273. X     * Serial line controllers
  9274. X     */
  9275. X    { "dc",        DT_GENERIC,    
  9276. X      NULL,    
  9277. X      "4-port serial line controller",        ProbeGeneric },
  9278. X    { "mdc",        DT_GENERIC,    
  9279. X      "DS5100",    
  9280. X      "4-port serial line controller",        ProbeGeneric },
  9281. X    { "scc",        DT_GENERIC,    
  9282. X      "SCC",    
  9283. X      "2-port serial line controller",        ProbeGeneric },
  9284. X    { "cxa",        DT_GENERIC,    
  9285. X      "CXA16",    
  9286. X      "16-line serial communications interface",    ProbeGeneric },
  9287. X    { "cxy",        DT_GENERIC,    
  9288. X      "CXY08",    
  9289. X      "8-line serial communications interface",    ProbeGeneric },
  9290. X    { "dhv",        DT_GENERIC,    
  9291. X      "DHV11",    
  9292. X      "8-line serial communications interface",    ProbeGeneric },
  9293. X    { "dmb",        DT_GENERIC,    
  9294. X      "DMB32",    
  9295. X      "8-line serial communications interface",    ProbeGeneric },
  9296. X    { "dhq",        DT_GENERIC,    
  9297. X      "DHQ11",    
  9298. X      "8-line serial communications interface",    ProbeGeneric },
  9299. X    { 0 },
  9300. X};
  9301. X
  9302. X/*
  9303. X * Models of DEC machines as defined in <machine/cpuconf.h>
  9304. X */
  9305. XNAMETAB ModelTab[] = {
  9306. X#ifdef VAX_780
  9307. X    {  VAX_780,        "VAX-11/780" },
  9308. X#endif
  9309. X#ifdef VAX_750
  9310. X    {  VAX_750,        "VAX-11/750" },
  9311. X#endif
  9312. X#ifdef VAX_730
  9313. X    {  VAX_730,        "VAX-11/730" },
  9314. X#endif
  9315. X#ifdef VAX_8600
  9316. X    {  VAX_8600,    "VAX-8600" },
  9317. X#endif
  9318. X#ifdef VAX_8200
  9319. X    {  VAX_8200,    "VAX-8200" },
  9320. X#endif
  9321. X#ifdef VAX_8800
  9322. X    {  VAX_8800,    "VAX-8800" },
  9323. X#endif
  9324. X#ifdef MVAX_I
  9325. X    {  MVAX_I,        "MicroVAX-I" },
  9326. X#endif
  9327. X#ifdef MVAX_II
  9328. X    {  MVAX_II,        "MicroVAX-II" },
  9329. X#endif
  9330. X#ifdef V_VAX
  9331. X    {  V_VAX,        "Virtual VAX" },    /* This can't be real     */
  9332. X#endif
  9333. X#ifdef VAX_3600
  9334. X    {  VAX_3600,    "VAX-3600" },        /* Mayfair I        */
  9335. X#endif
  9336. X#ifdef VAX_6200
  9337. X    {  VAX_6200,    "VAX-6200" },        /* CVAX/Calypso        */
  9338. X#endif
  9339. X#ifdef VAX_3400
  9340. X    {  VAX_3400,    "VAX-3400" },        /* Mayfair II        */
  9341. X#endif
  9342. X#ifdef C_VAXSTAR
  9343. X    {  C_VAXSTAR,    "VAX-3100" },        /* PVAX            */
  9344. X#endif
  9345. X#ifdef VAX_60
  9346. X    {  VAX_60,        "VAX-60" },        /* Firefox        */
  9347. X#endif
  9348. X#ifdef VAX_3900
  9349. X    {  VAX_3900,    "VAX-3900" },        /* Mayfair III        */
  9350. X#endif
  9351. X#ifdef DS_3100
  9352. X    {  DS_3100,        "DECsystem-3100" },    /* PMAX            */
  9353. X#endif
  9354. X#ifdef VAX_8820
  9355. X    {  VAX_8820,    "VAX-8820" },        /* SID for Polarstar    */
  9356. X#endif
  9357. X#ifdef DS_5400
  9358. X    {  DS_5400,        "DECsystem-5400" },    /* MIPSfair        */
  9359. X#endif
  9360. X#ifdef DS_5800
  9361. X    {  DS_5800,        "DECsystem-5800" },    /* ISIS            */
  9362. X#endif
  9363. X#ifdef DS_5000
  9364. X    {  DS_5000,        "DECsystem-5000" },
  9365. X#endif
  9366. X#ifdef DS_CMAX
  9367. X    {  DS_CMAX,        "DECsystem-CMAX" },
  9368. X#endif
  9369. X#ifdef VAX_6400
  9370. X    {  VAX_6400,    "VAX-6400" },        /* RIGEL/Calypso    */
  9371. X#endif
  9372. X#ifdef VAXSTAR
  9373. X    {  VAXSTAR,        "VAXSTAR" },
  9374. X#endif
  9375. X#ifdef DS_5500
  9376. X    {  DS_5500,        "DECsystem-5500" },    /* MIPSFAIR-2        */
  9377. X#endif
  9378. X#ifdef DS_5100
  9379. X    {  DS_5100,        "DECsystem-5100" },    /* MIPSMATE        */
  9380. X#endif
  9381. X#ifdef VAX_9000
  9382. X    {  VAX_9000,    "VAX-9000" },        /* VAX9000        */
  9383. X#endif
  9384. X#ifdef DS_5000_100
  9385. X    {  DS_5000_100,    "DECsystem-5000/100" },    /* 3MIN            */
  9386. X#endif
  9387. X#ifdef DS_5000_300
  9388. X    {  DS_5000_300,    "DECsystem-5000/300" },    /* 3MAX+        */
  9389. X#endif
  9390. X#ifdef DS_MAXINE
  9391. X    {  DS_MAXINE,    "DECsystem-MAXINE" },    /* MAXine        */
  9392. X#endif
  9393. X    {  0 },
  9394. X};
  9395. X
  9396. X/*
  9397. X * Tape info as defined in <sys/devio.h>.
  9398. X */
  9399. XNAMETAB TapeInfo[] = {
  9400. X#ifdef DEV_800BPI
  9401. X    {  DEV_800BPI,    "800 bpi density" },
  9402. X#endif
  9403. X#ifdef DEV_1600BPI
  9404. X    {  DEV_1600BPI,    "1600 bpi density" },
  9405. X#endif
  9406. X#ifdef DEV_6250BPI
  9407. X    {  DEV_6250BPI,    "6250 bpi density" },
  9408. X#endif
  9409. X#ifdef DEV_6666BPI
  9410. X    {  DEV_6666BPI,    "6666 bpi density" },
  9411. X#endif
  9412. X#ifdef DEV_10240BPI
  9413. X    {  DEV_10240BPI,    "10240 bpi density" },
  9414. X#endif
  9415. X#ifdef DEV_38000BPI
  9416. X    {  DEV_38000BPI,    "38000 bpi density" },
  9417. X#endif
  9418. X#ifdef DEV_LOADER
  9419. X    {  DEV_LOADER,    "media loader present" },
  9420. X#endif
  9421. X#ifdef DEV_38000_CP
  9422. X    {  DEV_38000_CP,    "38000 bpi compacted density" },
  9423. X#endif
  9424. X#ifdef DEV_76000BPI
  9425. X    {  DEV_76000BPI,    "76000 bpi density" },
  9426. X#endif
  9427. X#ifdef DEV_76000_CP
  9428. X    {  DEV_76000_CP,    "76000 bpi compacted density" },
  9429. X#endif
  9430. X#ifdef DEV_8000_BPI
  9431. X    {  DEV_8000_BPI,    "QIC-24 9 track" },
  9432. X#endif
  9433. X#ifdef DEV_10000_BPI
  9434. X    {  DEV_10000_BPI,    "QIC-120 15trk and QIC-150 18trk" },
  9435. X#endif
  9436. X#ifdef DEV_16000_BPI
  9437. X    {  DEV_16000_BPI,    "QIC-320/525 26 track" },
  9438. X#endif
  9439. X#ifdef DEV_61000_BPI
  9440. X    {  DEV_61000_BPI,    "4mm tape cartridge" },
  9441. X#endif
  9442. X#ifdef DEV_54000_BPI
  9443. X    {  DEV_54000_BPI,    "8mm tape cartridge" },
  9444. X#endif
  9445. X    { 0 },
  9446. X};
  9447. X
  9448. X/*
  9449. X * Category types as defined in <sys/devio.h>
  9450. X */
  9451. XNAMETAB Categorys[] = {
  9452. X#ifdef DEV_TAPE
  9453. X    {  DEV_TAPE,    "Tape drive" },
  9454. X#endif
  9455. X#ifdef DEV_DISK
  9456. X    {  DEV_DISK,    "Disk drive" },
  9457. X#endif
  9458. X#ifdef DEV_TERMINAL
  9459. X    {  DEV_TERMINAL,    "Terminal" },
  9460. X#endif
  9461. X#ifdef DEV_PRINTER
  9462. X    {  DEV_PRINTER,    "Printer" },
  9463. X#endif
  9464. X#ifdef DEV_SPECIAL
  9465. X    {  DEV_SPECIAL,    "Special" },
  9466. X#endif
  9467. X    {  0 },
  9468. X};
  9469. X
  9470. X/*
  9471. X * Network types table as defined in <net/pfilt.h>
  9472. X */
  9473. XNAMETAB NetTypes[] = {
  9474. X#ifdef ENDT_3MB
  9475. X    {  ENDT_3MB,    "3Mb/sec Ethernet" },
  9476. X#endif
  9477. X#ifdef ENDT_BS3MB
  9478. X    {  ENDT_BS3MB,    "Byte Swapped 3Mb/sec Ethernet" },
  9479. X#endif
  9480. X#ifdef ENDT_10MB
  9481. X    {  ENDT_10MB,    "10Mb/sec Ethernet" },
  9482. X#endif
  9483. X#ifdef ENDT_FDDI
  9484. X    {  ENDT_FDDI,    "100Mb/sec FDDI" },
  9485. X#endif
  9486. X    {  0 },
  9487. X};
  9488. END_OF_info-ultrix.c
  9489. if test 8452 -ne `wc -c <info-ultrix.c`; then
  9490.     echo shar: \"info-ultrix.c\" unpacked with wrong size!
  9491. fi
  9492. # end of overwriting check
  9493. fi
  9494. if test -f info-ultrix.h -a "${1}" != "-c" ; then 
  9495.   echo shar: Will not over-write existing file \"info-ultrix.h\"
  9496. else
  9497. echo shar: Extracting \"info-ultrix.h\" \(759 characters\)
  9498. sed "s/^X//" >info-ultrix.h <<'END_OF_info-ultrix.h'
  9499. X/*
  9500. X * Copyright (c) 1992 Michael A. Cooper.
  9501. X * This software may be freely distributed provided it is not sold for 
  9502. X * profit and the author is credited appropriately.
  9503. X */
  9504. X
  9505. X/*
  9506. X * $Header: /src/common/usc/bin/sysinfo/RCS/info-ultrix.h,v 1.3 1992/04/26 23:32:06 mcooper Exp $
  9507. X *
  9508. X * $Log: info-ultrix.h,v $
  9509. X * Revision 1.3  1992/04/26  23:32:06  mcooper
  9510. X * Add Copyright notice
  9511. X *
  9512. X * Revision 1.2  1992/03/08  01:11:58  mcooper
  9513. X * Add MAX_DISK_PARTS.
  9514. X *
  9515. X * Revision 1.2  1992/03/08  01:11:58  mcooper
  9516. X * Add MAX_DISK_PARTS.
  9517. X *
  9518. X * Revision 1.1  1992/03/06  18:35:31  mcooper
  9519. X * Initial revision
  9520. X *
  9521. X */
  9522. X
  9523. X
  9524. X/*
  9525. X * Maximium number of tape drives that Ultrix supports
  9526. X */
  9527. X#define MAXTAPES        32
  9528. X
  9529. X/*
  9530. X * Maximium number of partitions per disk
  9531. X */
  9532. X#define MAX_DISK_PARTS        8
  9533. END_OF_info-ultrix.h
  9534. if test 759 -ne `wc -c <info-ultrix.h`; then
  9535.     echo shar: \"info-ultrix.h\" unpacked with wrong size!
  9536. fi
  9537. # end of overwriting check
  9538. fi
  9539. if test -f os-next.c -a "${1}" != "-c" ; then 
  9540.   echo shar: Will not over-write existing file \"os-next.c\"
  9541. else
  9542. echo shar: Extracting \"os-next.c\" \(12325 characters\)
  9543. sed "s/^X//" >os-next.c <<'END_OF_os-next.c'
  9544. X/*
  9545. X * Copyright (c) 1992 Michael A. Cooper.
  9546. X * This software may be freely distributed provided it is not sold for 
  9547. X * profit and the author is credited appropriately.
  9548. X */
  9549. X
  9550. X#ifndef lint
  9551. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/os-next.c,v 1.10 1992/04/26 23:32:06 mcooper Exp $";
  9552. X#endif
  9553. X
  9554. X/*
  9555. X * $Log: os-next.c,v $
  9556. X * Revision 1.10  1992/04/26  23:32:06  mcooper
  9557. X * Add Copyright notice
  9558. X *
  9559. X * Revision 1.9  1992/04/17  23:27:51  mcooper
  9560. X * Add support for ROM Version information (Sun only for now).
  9561. X *
  9562. X * Revision 1.8  1992/04/17  01:07:59  mcooper
  9563. X * More de-linting
  9564. X *
  9565. X * Revision 1.7  1992/04/15  02:04:16  mcooper
  9566. X * Change GetMemoryStr() to GetMemory().
  9567. X *
  9568. X * Revision 1.6  1992/03/31  02:22:03  mcooper
  9569. X * Fix failed return value from CheckNlist().
  9570. X *
  9571. X * Revision 1.5  1992/03/31  01:55:17  mcooper
  9572. X * Use new CheckNlist to check nlist success.
  9573. X *
  9574. X * Revision 1.4  1992/03/31  00:15:09  mcooper
  9575. X * Add error check for nlist.n_type.
  9576. X *
  9577. X * Revision 1.3  1992/03/28  21:59:28  mcooper
  9578. X * Implemented disk and netif device probing.
  9579. X *
  9580. X * Revision 1.2  1992/03/22  02:03:48  mcooper
  9581. X * Add Build*NeXT*() functions.
  9582. X *
  9583. X * Revision 1.1  1992/03/22  01:04:34  mcooper
  9584. X * Initial revision
  9585. X *
  9586. X */
  9587. X
  9588. X
  9589. X/*
  9590. X * NeXT specific functions
  9591. X */
  9592. X
  9593. X#include <stdio.h>
  9594. X#include "system.h"
  9595. X#include "defs.h"
  9596. X
  9597. X#include <nlist.h>
  9598. X#include <mntent.h>
  9599. X#include <nextdev/disk.h>
  9600. X#include <nextdev/busvar.h>
  9601. X
  9602. X#define DV_SIZE        (sizeof(struct bus_device))
  9603. X#define DR_SIZE        (sizeof(struct bus_driver))
  9604. X#define CR_SIZE        (sizeof(struct bus_ctrl))
  9605. X
  9606. X/*
  9607. X * Build a device tree by searching NeXTBus
  9608. X */
  9609. Xstatic int BuildNeXTBus(TreePtr)
  9610. X    DEVICE               **TreePtr;
  9611. X{
  9612. X    extern struct nlist     NeXTBusNL[];
  9613. X    static struct bus_device     Device;
  9614. X    static struct bus_driver     Driver;
  9615. X    static struct bus_ctrl     Ctlr;
  9616. X    static char         CtlrName[BUFSIZ], DevName[BUFSIZ];
  9617. X    u_long             Addr, DeviceAddr;
  9618. X    static DEVDATA         DevData;
  9619. X    DEVICE                *Dev;
  9620. X    kvm_t               *kd;
  9621. X
  9622. X    /*
  9623. X     * Read table address from kernel
  9624. X     */
  9625. X    if (!(kd = KVM_open(NeXTBusNL))) {
  9626. X    if (Debug) Error("Cannot read NeXTBus device table from kernel.");
  9627. X    return(-1);
  9628. X    }
  9629. X
  9630. X    /*
  9631. X     * See if we got a valid entry
  9632. X     */
  9633. X    if (CheckNlist(&NeXTBusNL[0]))
  9634. X    return(-1);
  9635. X
  9636. X    /*
  9637. X     * Read each device table entry.  A NULL device.bd_driver
  9638. X     * indicates that we're at the end of the table.
  9639. X     */
  9640. X    for (DeviceAddr = NeXTBusNL[0].n_value; DeviceAddr; 
  9641. X     DeviceAddr += DV_SIZE) {
  9642. X
  9643. X    /*
  9644. X     * Read this device
  9645. X     */
  9646. X    if (KVM_read(kd, DeviceAddr, (char *) &Device, DV_SIZE)) {
  9647. X        if (Debug) 
  9648. X        Error("Cannot read NeXTbus device from address 0x%x.", 
  9649. X              DeviceAddr);
  9650. X        KVM_close(kd);
  9651. X        return(-1);
  9652. X    }
  9653. X
  9654. X    /*
  9655. X     * See if we're done.
  9656. X     */
  9657. X    if (!Device.bd_driver)
  9658. X        break;
  9659. X
  9660. X    /*
  9661. X     * Get the device name
  9662. X     */
  9663. X    DevName[0] = C_NULL;
  9664. X    if (Addr = (u_long) Device.bd_name) {
  9665. X        if (KVM_read(kd, Addr, (char *) DevName, sizeof(DevName))) {
  9666. X        if (Debug)
  9667. X            Error("Cannot read device name from address 0x%x.", Addr);
  9668. X        continue;
  9669. X        }
  9670. X    }
  9671. X
  9672. X    /*
  9673. X     * Get the controller info
  9674. X     */
  9675. X    CtlrName[0] = C_NULL;
  9676. X    /*
  9677. X     * First read the controller structure in
  9678. X     */
  9679. X    if (Addr = (u_long) Device.bd_bc) {
  9680. X        if (KVM_read(kd, Addr, (char *) &Ctlr, CR_SIZE)) {
  9681. X        if (Debug) 
  9682. X            Error("Cannot read controller from address 0x%x.", Addr);
  9683. X        } else if (Addr = (u_long) Ctlr.bc_driver) {
  9684. X        /*
  9685. X         * Get the controller driver
  9686. X         */
  9687. X        if (KVM_read(kd, Addr, (char *) &Driver, DR_SIZE)) {
  9688. X            if (Debug)
  9689. X            Error(
  9690. X                "Cannot read controller driver from address 0x%x.",
  9691. X                  Addr);
  9692. X            continue;
  9693. X        }
  9694. X        /*
  9695. X         * Read the name of the controller from the driver
  9696. X         */
  9697. X        if (!(Addr = (u_long) Driver.br_cname)) {
  9698. X            if (Debug)
  9699. X            Error("No name for controller at address 0x%x.",
  9700. X                  Ctlr.bc_driver);
  9701. X            continue;
  9702. X        }
  9703. X        if (KVM_read(kd, Addr, CtlrName, sizeof(CtlrName))) {
  9704. X            if (Debug)
  9705. X            Error("Read controller name failed (address 0x%x).",
  9706. X                  Addr);
  9707. X            continue;
  9708. X        }
  9709. X        }
  9710. X    }
  9711. X
  9712. X    if (Debug)
  9713. X        printf("NeXTbus: Found '%s' on '%s'.\n", DevName, CtlrName);
  9714. X
  9715. X    /* Make sure devdata is clean */
  9716. X    bzero(&DevData, sizeof(DEVDATA));
  9717. X
  9718. X    /* Set what we know */
  9719. X    if (DevName[0]) {
  9720. X        DevData.dd_devname = strdup(DevName);
  9721. X        DevData.dd_devunit = Device.bd_unit;
  9722. X        DevData.dd_slave = Device.bd_slave;
  9723. X    }
  9724. X    if (CtlrName[0]) {
  9725. X        DevData.dd_ctlrname = strdup(CtlrName);
  9726. X        DevData.dd_ctlrunit = Ctlr.bc_ctrl;
  9727. X    }
  9728. X
  9729. X    /* 
  9730. X     * NeXTbus devices should always exist.
  9731. X     */
  9732. X    if (Device.bd_alive)
  9733. X        DevData.dd_flags |= DD_IS_ALIVE;
  9734. X
  9735. X    /* Probe and add device */
  9736. X    if (Dev = (DEVICE *) ProbeDevice(&DevData, TreePtr, NULL))
  9737. X        AddDevice(Dev, TreePtr);
  9738. X    }
  9739. X
  9740. X    KVM_close(kd);
  9741. X
  9742. X    return(0);
  9743. X}
  9744. X
  9745. X/*
  9746. X * Build list of NeXT devices
  9747. X */
  9748. Xextern int BuildDevicesNeXT(TreePtr)
  9749. X    DEVICE               **TreePtr;
  9750. X{
  9751. X    int                Found = 1;
  9752. X
  9753. X    if (BuildNeXTBus(TreePtr) == 0)
  9754. X    Found = 0;
  9755. X
  9756. X    return(Found);
  9757. X}
  9758. X
  9759. X/*
  9760. X * Get the system model name.  NeXT keeps the system type
  9761. X * in a kernel variable called machine_type.
  9762. X * The system types are defined in <next/scr.h>.
  9763. X */
  9764. Xextern char *GetModelName()
  9765. X{
  9766. X    extern NAMETAB        ModelTab[];
  9767. X    extern struct nlist        MachineTypeNL[];
  9768. X    u_char            MachineType;
  9769. X    register int        i;
  9770. X    kvm_t               *kd;
  9771. X
  9772. X    if (!(kd = KVM_open(MachineTypeNL))) {
  9773. X    if (Debug) Error("Cannot find machine_type symbol in kernel.");
  9774. X    return((char *) NULL);
  9775. X    }
  9776. X
  9777. X    /*
  9778. X     * See if we got a valid entry
  9779. X     */
  9780. X    if (CheckNlist(&MachineTypeNL[0]))
  9781. X    return((char *) NULL);
  9782. X
  9783. X    if (KVM_read(kd, (u_long) MachineTypeNL[0].n_value, 
  9784. X         (char *) &MachineType, sizeof(MachineType))) {
  9785. X    if (Debug) Error("Cannot read \"%s\" from kernel.", 
  9786. X             GetNlName(MachineTypeNL[0]));
  9787. X    return((char *) NULL);
  9788. X    }
  9789. X
  9790. X    KVM_close(kd);
  9791. X
  9792. X    for (i = 0; ModelTab[i].name; ++i)
  9793. X    if (ModelTab[i].value == MachineType)
  9794. X        return(ModelTab[i].name);
  9795. X
  9796. X    if (Debug)
  9797. X    printf("system model/type %d is unknown.\n", MachineType);
  9798. X
  9799. X    return((char *) NULL);
  9800. X}
  9801. X
  9802. X/*
  9803. X * Get kernel version string using Mach HostInfo method
  9804. X */
  9805. Xextern char *GetKernelVersionStr()
  9806. X{
  9807. X    return(GetKernelVersionFromHostInfo());
  9808. X}
  9809. X
  9810. X/*
  9811. X * Get amount of physical memory using Mach HostInfo method
  9812. X */
  9813. Xextern char *GetMemory()
  9814. X{
  9815. X    return(GetMemoryFromHostInfo());
  9816. X}
  9817. X
  9818. X/*
  9819. X * Get application architecture name using Mach HostInfo method.
  9820. X */
  9821. Xextern char *GetAppArchName()
  9822. X{
  9823. X    return(GetAppArchFromHostInfo());
  9824. X}
  9825. X
  9826. X/*
  9827. X * Get kernel architecture name using Mach HostInfo method.
  9828. X */
  9829. Xextern char *GetKernArchName()
  9830. X{
  9831. X    return(GetKernArchFromHostInfo());
  9832. X}
  9833. X
  9834. X/*
  9835. X * Get system serial number
  9836. X */
  9837. Xextern char *GetSerialNoStr()
  9838. X{
  9839. X    /* No support */
  9840. X    return((char *) NULL);
  9841. X}
  9842. X
  9843. X/*
  9844. X * Get OS version using Mach HostInfo method.
  9845. X */
  9846. Xextern char *GetOSVersionStr()
  9847. X{
  9848. X    return(GetOSVersionFromHostInfo());
  9849. X}
  9850. X
  9851. X/*
  9852. X * Get filesystem mount info for a partition.
  9853. X */
  9854. Xstatic char *GetMountInfo(Name, Part)
  9855. X    char                *Name;
  9856. X    char                *Part;
  9857. X{
  9858. X    FILE                *mf;
  9859. X    struct mntent            *mntent;
  9860. X    char                *file;
  9861. X
  9862. X    if (!Name)
  9863. X    return((char *) NULL);
  9864. X
  9865. X    file = GetCharFile(Name, Part);
  9866. X
  9867. X    if ((mf = setmntent(MNTTAB, "r")) == NULL) {
  9868. X    Error("%s: Cannot open for reading: %s.", MNTTAB, SYSERR);
  9869. X    return(NULL);
  9870. X    }
  9871. X
  9872. X    while (mntent = getmntent(mf)) {
  9873. X    if (strcmp(mntent->mnt_fsname, file) == 0)
  9874. X        break;
  9875. X    }
  9876. X
  9877. X    endmntent(mf);
  9878. X
  9879. X    return((mntent) ? mntent->mnt_dir : (char *) NULL);
  9880. X}
  9881. X
  9882. X/*
  9883. X * Get disk partition information
  9884. X */
  9885. Xstatic DISKPART *GetDiskPart(Name, DiskLabel)
  9886. X    char               *Name;
  9887. X    struct disk_label           *DiskLabel;
  9888. X{
  9889. X    register int        i;
  9890. X    register DISKPART           *Ptr;
  9891. X    DISKPART               *Base = NULL;
  9892. X    DISKPART            DiskPart;
  9893. X    static char            Part[2];
  9894. X    register char           *p;
  9895. X
  9896. X    Part[1] = C_NULL;
  9897. X
  9898. X    /*
  9899. X     * Now handle each partition
  9900. X     */
  9901. X    for (i = 0; i < NPART; i++) {
  9902. X    /* Ingore partitins that have no size */
  9903. X    if (DiskLabel->dl_dt.d_partitions[i].p_size <= 0)
  9904. X        continue;
  9905. X
  9906. X    Part[0] = 'a' + i;
  9907. X
  9908. X    /* Make a clean slate */
  9909. X    bzero((char *) &DiskPart, sizeof(DISKPART));
  9910. X
  9911. X    /* Fill in the blanks */
  9912. X    DiskPart.dp_name = strdup(Part);
  9913. X    DiskPart.dp_stsect = DiskLabel->dl_dt.d_partitions[i].p_base;
  9914. X    DiskPart.dp_nsect = DiskLabel->dl_dt.d_partitions[i].p_size;
  9915. X
  9916. X    /* 
  9917. X     * Get the mount point name.
  9918. X     */
  9919. X    if (p = GetMountInfo(Name, Part))
  9920. X        DiskPart.dp_mnt = strdup(p);
  9921. X
  9922. X    /*
  9923. X     * Add this partition to the linked list.
  9924. X     */
  9925. X    if (Base) {
  9926. X        for (Ptr = Base; Ptr && Ptr->dp_nxt; Ptr = Ptr->dp_nxt);
  9927. X        Ptr->dp_nxt = NewDiskPart(&DiskPart);
  9928. X    } else {
  9929. X        Base = NewDiskPart(&DiskPart);
  9930. X    }
  9931. X    }
  9932. X
  9933. X    return(Base);
  9934. X}
  9935. X
  9936. X/*
  9937. X * Convert disk info into a DEVICE entry.
  9938. X */
  9939. Xstatic DEVICE *diskToDiskDrive(Name, DevData, DevDataTab, DiskLabel, DriveInfo)
  9940. X    char               *Name;
  9941. X    DEVDATA               *DevData;
  9942. X    DEVDATATAB               *DevDataTab;
  9943. X    struct disk_label           *DiskLabel;
  9944. X    struct drive_info           *DriveInfo;
  9945. X{
  9946. X    DEVICE               *Device;
  9947. X    DISKDRIVE               *DiskDrive;
  9948. X    static char         Buf[BUFSIZ];
  9949. X
  9950. X    if ((Device = NewDevice(NULL)) == NULL) {
  9951. X    Error("Cannot create new device entry.");
  9952. X    return((DEVICE *) NULL);
  9953. X    }
  9954. X
  9955. X    if ((DiskDrive = NewDiskDrive(NULL)) == NULL) {
  9956. X    Error("Cannot create new diskdrive entry.");
  9957. X    return((DEVICE *) NULL);
  9958. X    }
  9959. X
  9960. X    Device->dv_name         = strdup(Name);
  9961. X    Device->dv_type         = DT_DISKDRIVE;
  9962. X    DiskDrive->dd_label     = strdup(DriveInfo->di_name);
  9963. X    Device->dv_model         = DiskDrive->dd_label;
  9964. X    DiskDrive->dd_unit         = DevData->dd_devunit;
  9965. X    DiskDrive->dd_slave     = DevData->dd_slave;
  9966. X    DiskDrive->dd_dcyl         = DiskLabel->dl_ncyl;
  9967. X    DiskDrive->dd_heads     = DiskLabel->dl_ntrack;
  9968. X    DiskDrive->dd_sect         = DiskLabel->dl_nsect;
  9969. X    DiskDrive->dd_apc         = DiskLabel->dl_ngroups;
  9970. X    DiskDrive->dd_rpm         = DiskLabel->dl_rpm;
  9971. X    DiskDrive->dd_secsize     = DiskLabel->dl_secsize;
  9972. X    /*
  9973. X     * Only get partition info we we're going to print it later.
  9974. X     */
  9975. X    if (VL_ALL)
  9976. X    DiskDrive->dd_part     = GetDiskPart(Name, DiskLabel);
  9977. X
  9978. X    /*
  9979. X     * Determine size (capacity) of media
  9980. X     */
  9981. X    if (DiskDrive->dd_dcyl && DiskDrive->dd_sect && DiskDrive->dd_heads)
  9982. X    DiskDrive->dd_size = nsect_to_bytes(DiskDrive->dd_dcyl * 
  9983. X                        DiskDrive->dd_sect * 
  9984. X                        DiskDrive->dd_heads, 
  9985. X                        DiskDrive->dd_secsize);
  9986. X
  9987. X    /*
  9988. X     * Create the description
  9989. X     */
  9990. X    if (DiskDrive->dd_size > 0) {
  9991. X    (void) sprintf(Buf, "%.2f MB capacity", 
  9992. X               (float) bytes_to_mbytes(DiskDrive->dd_size));
  9993. X    Device->dv_desc = strdup(Buf);
  9994. X    }
  9995. X
  9996. X    Device->dv_devspec = (caddr_t *) DiskDrive;
  9997. X    Device->dv_master = MkMasterFromDevData(DevData);
  9998. X
  9999. X    return(Device);
  10000. X}
  10001. X
  10002. X/*
  10003. X * Query and learn about a disk.
  10004. X */
  10005. Xextern DEVICE *ProbeDiskDrive(Name, DevData, DevDataTab)
  10006. X    /*ARGSUSED*/
  10007. X    char                *Name;
  10008. X    DEVDATA                *DevData;
  10009. X    DEVDATATAB                     *DevDataTab;
  10010. X{
  10011. X    static struct disk_label    DiskLabel;
  10012. X    static struct drive_info     DriveInfo;
  10013. X    int                Desc;
  10014. X    char               *File;
  10015. X    DEVICE               *Device;
  10016. X
  10017. X    File = GetRawFile(Name, "a");
  10018. X
  10019. X    if ((Desc = open(File, O_RDONLY|O_NDELAY)) < 0) {
  10020. X    if (Debug) Error("%s: Cannot open for read: %s.\n", File, SYSERR);
  10021. X    /*
  10022. X     * If we know for sure this drive is present and we
  10023. X     * know something about it, then create a minimal device.
  10024. X     */
  10025. X    if ((DevDataTab->ddt_model || DevDataTab->ddt_desc) &&
  10026. X        FLAGS_ON(DevData->dd_flags, DD_IS_ALIVE)) {
  10027. X        Device = NewDevice((DEVICE *) NULL);
  10028. X        Device->dv_name = strdup(Name);
  10029. X        Device->dv_unit = DevData->dd_devunit;
  10030. X        Device->dv_master = MkMasterFromDevData(DevData);
  10031. X        Device->dv_type = DT_DISKDRIVE;
  10032. X        Device->dv_model = DevDataTab->ddt_model;
  10033. X        Device->dv_desc = DevDataTab->ddt_desc;
  10034. X        return(Device);
  10035. X    } else
  10036. X        return((DEVICE *) NULL);
  10037. X    }
  10038. X
  10039. X    /*
  10040. X     * Read disk label
  10041. X     */
  10042. X    if (ioctl(Desc, DKIOCGLABEL, &DiskLabel) < 0) {
  10043. X    if (Debug) Error("%s: DKIOCGLABEL: %s.", File, SYSERR);
  10044. X    return((DEVICE *) NULL);
  10045. X    }
  10046. X
  10047. X    /*
  10048. X     * Read drive info
  10049. X     */
  10050. X    if (ioctl(Desc, DKIOCINFO, &DriveInfo) < 0) {
  10051. X    if (Debug) Error("%s: DKIOCINFO: %s.", File, SYSERR);
  10052. X    return((DEVICE *) NULL);
  10053. X    }
  10054. X
  10055. X    close(Desc);
  10056. X
  10057. X    if (!(Device = diskToDiskDrive(Name, DevData, DevDataTab, 
  10058. X                   &DiskLabel, &DriveInfo))) {
  10059. X    Error("%s: Cannot convert diskdrive info.", Name);
  10060. X    return((DEVICE *) NULL);
  10061. X    }
  10062. X
  10063. X    return(Device);
  10064. X}
  10065. X
  10066. X/*
  10067. X * Get ROM Version
  10068. X */
  10069. Xextern char *GetRomVer()
  10070. X{
  10071. X    /* No support */
  10072. X    return((char *) NULL);
  10073. X}
  10074. END_OF_os-next.c
  10075. if test 12325 -ne `wc -c <os-next.c`; then
  10076.     echo shar: \"os-next.c\" unpacked with wrong size!
  10077. fi
  10078. # end of overwriting check
  10079. fi
  10080. if test -f info-next.c -a "${1}" != "-c" ; then 
  10081.   echo shar: Will not over-write existing file \"info-next.c\"
  10082. else
  10083. echo shar: Extracting \"info-next.c\" \(2289 characters\)
  10084. sed "s/^X//" >info-next.c <<'END_OF_info-next.c'
  10085. X/*
  10086. X * Copyright (c) 1992 Michael A. Cooper.
  10087. X * This software may be freely distributed provided it is not sold for 
  10088. X * profit and the author is credited appropriately.
  10089. X */
  10090. X
  10091. X#ifndef lint
  10092. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/info-next.c,v 1.5 1992/04/26 23:32:06 mcooper Exp $";
  10093. X#endif
  10094. X
  10095. X/*
  10096. X * $Log: info-next.c,v $
  10097. X * Revision 1.5  1992/04/26  23:32:06  mcooper
  10098. X * Add Copyright notice
  10099. X *
  10100. X * Revision 1.4  1992/04/17  01:10:11  mcooper
  10101. X * Moved DEVICE *() function declares to defs.h.
  10102. X *
  10103. X * Revision 1.3  1992/03/28  21:59:28  mcooper
  10104. X * Implemented disk and netif device probing.
  10105. X *
  10106. X * Revision 1.2  1992/03/22  02:02:26  mcooper
  10107. X * Add NeXTBusNL nlist.
  10108. X *
  10109. X * Revision 1.1  1992/03/22  01:04:34  mcooper
  10110. X * Initial revision
  10111. X *
  10112. X */
  10113. X
  10114. X
  10115. X/*
  10116. X * NeXT related information
  10117. X */
  10118. X
  10119. X#include <stdio.h>
  10120. X#include "system.h"
  10121. X#include "defs.h"
  10122. X
  10123. X#include <nlist.h>
  10124. X
  10125. X/*
  10126. X * Kernel variable containing model number.
  10127. X */
  10128. Xstruct nlist MachineTypeNL[] = {
  10129. X#if    !defined(COFF)
  10130. X    { "_machine_type" },
  10131. X#else
  10132. X    { "machine_type" },
  10133. X#endif    /* COFF */
  10134. X    { 0 },
  10135. X};
  10136. X
  10137. X/*
  10138. X * Kernel symbol for the device table
  10139. X */
  10140. Xstruct nlist NeXTBusNL[] = {
  10141. X#if    !defined(COFF)
  10142. X    { "_bus_dinit" },
  10143. X#else
  10144. X    { "bus_dinit" },
  10145. X#endif    /* COFF */
  10146. X    { 0 },
  10147. X};
  10148. X
  10149. X/*
  10150. X * Models of NeXT machines as defined in <next/scr.h>
  10151. X */
  10152. X#include <next/scr.h>
  10153. XNAMETAB ModelTab[] = {
  10154. X#ifdef NeXT_CUBE
  10155. X    {  NeXT_CUBE,     "NeXTCube (MC68030)" },
  10156. X#endif
  10157. X#ifdef NeXT_WARP9
  10158. X    {  NeXT_WARP9,    "NeXTStation" },
  10159. X#endif
  10160. X#ifdef NeXT_X15
  10161. X    {  NeXT_X15,    "NeXTCube (MC68040)" },
  10162. X#endif
  10163. X#ifdef NeXT_WARP9C
  10164. X    {  NeXT_WARP9C,    "NeXTWarp9C" },
  10165. X#endif
  10166. X    {  0 },
  10167. X};
  10168. X
  10169. X/*
  10170. X * Device Data Table
  10171. X *
  10172. X * Compares are done by the length of the string appearing in
  10173. X * the first columns.  Therefore, longer names must appear before
  10174. X * any shorter names that are not unique.  e.g. "lebuffer" needs to
  10175. X * be before "le".
  10176. X */
  10177. XDEVDATATAB DevDataTab[] = {
  10178. X    { "sc",        0,    NULL,    "SCSI Controller",         NULL },
  10179. X    { "odc",        0,    NULL,    "Optical Disk Controller",     NULL },
  10180. X    { "fdc",        0,    NULL,    "Floppy Disk Controller",     NULL },
  10181. X    { "sd",        0,    NULL,    NULL,        ProbeDiskDrive },
  10182. X    { "od",        0,    NULL,    NULL,        ProbeDiskDrive },
  10183. X    { "fd",        0,    NULL,    NULL,        ProbeDiskDrive },
  10184. X    { "en",        0,    
  10185. X      "EtherNet Interface",    "10Mb/sec Ethernet",    ProbeNetif },
  10186. X    {  0 },
  10187. X};
  10188. END_OF_info-next.c
  10189. if test 2289 -ne `wc -c <info-next.c`; then
  10190.     echo shar: \"info-next.c\" unpacked with wrong size!
  10191. fi
  10192. # end of overwriting check
  10193. fi
  10194. if test -f os-alliant.c -a "${1}" != "-c" ; then 
  10195.   echo shar: Will not over-write existing file \"os-alliant.c\"
  10196. else
  10197. echo shar: Extracting \"os-alliant.c\" \(4553 characters\)
  10198. sed "s/^X//" >os-alliant.c <<'END_OF_os-alliant.c'
  10199. X/*
  10200. X * Copyright (c) 1992 Michael A. Cooper.
  10201. X * This software may be freely distributed provided it is not sold for 
  10202. X * profit and the author is credited appropriately.
  10203. X */
  10204. X
  10205. X#ifndef lint
  10206. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/os-alliant.c,v 1.9 1992/04/26 23:32:06 mcooper Exp $";
  10207. X#endif
  10208. X
  10209. X/*
  10210. X * $Log: os-alliant.c,v $
  10211. X * Revision 1.9  1992/04/26  23:32:06  mcooper
  10212. X * Add Copyright notice
  10213. X *
  10214. X * Revision 1.8  1992/04/17  23:27:51  mcooper
  10215. X * Add support for ROM Version information (Sun only for now).
  10216. X *
  10217. X * Revision 1.7  1992/04/17  01:07:59  mcooper
  10218. X * More de-linting
  10219. X *
  10220. X * Revision 1.6  1992/04/15  02:04:16  mcooper
  10221. X * Change GetMemoryStr() to GetMemory().
  10222. X *
  10223. X * Revision 1.5  1992/03/31  19:00:15  mcooper
  10224. X * A working version.
  10225. X *
  10226. X * Revision 1.4  1992/03/31  02:22:03  mcooper
  10227. X * Fix failed return value from CheckNlist().
  10228. X *
  10229. X * Revision 1.3  1992/03/31  01:55:17  mcooper
  10230. X * Use new CheckNlist to check nlist success.
  10231. X *
  10232. X * Revision 1.2  1992/03/31  00:15:09  mcooper
  10233. X * Add error check for nlist.n_type.
  10234. X *
  10235. X * Revision 1.1  1992/03/01  23:28:16  mcooper
  10236. X * Initial revision
  10237. X *
  10238. X */
  10239. X
  10240. X/*
  10241. X * Alliant specific functions
  10242. X */
  10243. X#include <stdio.h>
  10244. X#include "system.h"
  10245. X#include "defs.h"
  10246. X
  10247. X#include <fcntl.h>
  10248. X#include <nlist.h>
  10249. X
  10250. X/*
  10251. X * All the wonderful global extern declarations
  10252. X */
  10253. X#if    defined(HAVE_USERETC)
  10254. Xstruct bpb                *useretc = (struct bpb *)USERETC;
  10255. X#endif    /* HAVE_USERETC */
  10256. X#if    defined(HAVE_MODELNUM)
  10257. Xextern int            modelnum;
  10258. X#endif    /* HAVE_MODELNUM */
  10259. X#if    defined(HAVE_MEMORYSIZE)
  10260. Xextern int            memorysize;
  10261. X#endif    /* HAVE_MEMORYSIZE */
  10262. X#if    defined(HAVE_SERIALNUM)
  10263. Xextern int            serialnum;
  10264. X#endif    /* HAVE_SERIALNUM */
  10265. X
  10266. X/*
  10267. X * Lookup a model value (val) and returns it's name.
  10268. X */
  10269. Xextern char *GetModelName()
  10270. X{
  10271. X    register int         i;
  10272. X    register int        Num = -1;
  10273. X    extern NAMETAB         ModelTab[];
  10274. X
  10275. X#if    defined(HAVE_MODELNUM)
  10276. X    /*
  10277. X     * Alliant 2800's have an external variable
  10278. X     * called "modelnum".
  10279. X     */
  10280. X    Num = modelnum;
  10281. X#endif    /* HAVE_MODELNUM */
  10282. X#if    defined(HAVE_USERETC)
  10283. X    /*
  10284. X     * Alliant FX/80's have an external variable
  10285. X     * called "useretc".
  10286. X     */
  10287. X    Num = useretc->bp_model;
  10288. X#endif    /* HAVE_USERETC */
  10289. X
  10290. X    for (i = 0; ModelTab[i].name; ++i) {
  10291. X    if (ModelTab[i].value == Num)
  10292. X        return(ModelTab[i].name);
  10293. X    }
  10294. X
  10295. X    return((char *) NULL);
  10296. X}
  10297. X
  10298. X/*
  10299. X * Get amount of memory.
  10300. X */
  10301. Xextern char *GetMemory()
  10302. X{
  10303. X    static char            Buf[BUFSIZ];
  10304. X    int                Amount = -1;
  10305. X#if    defined(HAVE_LIB_SYSCFG)
  10306. X    int             mem, ip, ce, det, att;
  10307. X
  10308. X    lib_syscfg(&mem, &ip, &ce, &det, &att);
  10309. X    Amount = mem;
  10310. X#endif    /* HAVE_LIB_SYSCFG */
  10311. X#if    defined(HAVE_MEMORYSIZE)
  10312. X    Amount = memorysize;
  10313. X#endif    /* HAVE_MEMORYSIZE */
  10314. X
  10315. X    if (Amount > 0) {
  10316. X    (void) sprintf(Buf, "%d MB", Amount);
  10317. X    return(Buf);
  10318. X    } else
  10319. X    return((char *) NULL);
  10320. X}
  10321. X
  10322. X/*
  10323. X * Get kernel version string from kernel.
  10324. X */
  10325. Xextern char *GetKernelVersionStr()
  10326. X{
  10327. X    extern struct nlist        VersionInfoNL[];
  10328. X    static char            Version[BUFSIZ];
  10329. X    static char            VerName[BUFSIZ], VerDate[BUFSIZ];
  10330. X    register char           *p;
  10331. X    kvm_t               *kd;
  10332. X
  10333. X    Version[0] = C_NULL;
  10334. X
  10335. X    if (!(kd = KVM_open(VersionInfoNL))) {
  10336. X    if (Debug) Error("GetKernelVersionStr() KVM_open failed.");
  10337. X    return((char *) NULL);
  10338. X    }
  10339. X
  10340. X    /*
  10341. X     * See if we got a valid entry
  10342. X     */
  10343. X    if (CheckNlist(&VersionInfoNL[0]) || CheckNlist(&VersionInfoNL[1]))
  10344. X    return((char *) NULL);
  10345. X
  10346. X    if (KVM_read(kd, VersionInfoNL[0].n_value, (char *) VerName, 
  10347. X         sizeof(VerName))) {
  10348. X    if (Debug) Error("GetKernelVersionStr() KVM_read versionname failed.");
  10349. X    return((char *) NULL);
  10350. X    }
  10351. X
  10352. X    if (KVM_read(kd, VersionInfoNL[1].n_value, (char *) VerDate, 
  10353. X          sizeof(VerDate))) {
  10354. X    if (Debug) Error("GetKernelVersionStr() KVM_read versiondate failed.");
  10355. X    return((char *) NULL);
  10356. X    }
  10357. X
  10358. X    if (kd)
  10359. X    KVM_close(kd);
  10360. X
  10361. X    /*
  10362. X     * Zap trailing white space
  10363. X     */
  10364. X    p = VerName;
  10365. X    p = p + strlen(VerName) - 1;
  10366. X    while (*p == ' ') {
  10367. X    *p = C_NULL;
  10368. X    *--p;
  10369. X    }
  10370. X
  10371. X    (void) sprintf(Version, "%s: %s", VerName, VerDate);
  10372. X
  10373. X    return(Version);
  10374. X}
  10375. X
  10376. X/*
  10377. X * Get system serial number.
  10378. X */
  10379. Xextern char *GetSerialNoStr()
  10380. X{
  10381. X#if    defined(HAVE_SERIALNUM)
  10382. X    /*
  10383. X     * Use global variable "serialnum"
  10384. X     */
  10385. X    return(itoa(serialnum));
  10386. X#endif    /* HAVE_SERIALNUM */
  10387. X#if    defined(HAVE_USERETC)
  10388. X    /*
  10389. X     * Use global variable "useretc"
  10390. X     */
  10391. X    return(itoa(useretc->bp_serialnum));
  10392. X#endif     /* HAVE_USERETC */
  10393. X}
  10394. X
  10395. X/*
  10396. X * Get OS Version string
  10397. X */
  10398. Xextern char *GetOSVersionStr()
  10399. X{
  10400. X    return(GetOSVersionFromKernVer());
  10401. X}
  10402. X
  10403. X/*
  10404. X * Get ROM Version
  10405. X */
  10406. Xextern char *GetRomVer()
  10407. X{
  10408. X    /* No support */
  10409. X    return((char *) NULL);
  10410. X}
  10411. END_OF_os-alliant.c
  10412. if test 4553 -ne `wc -c <os-alliant.c`; then
  10413.     echo shar: \"os-alliant.c\" unpacked with wrong size!
  10414. fi
  10415. # end of overwriting check
  10416. fi
  10417. if test -f info-alliant.c -a "${1}" != "-c" ; then 
  10418.   echo shar: Will not over-write existing file \"info-alliant.c\"
  10419. else
  10420. echo shar: Extracting \"info-alliant.c\" \(1404 characters\)
  10421. sed "s/^X//" >info-alliant.c <<'END_OF_info-alliant.c'
  10422. X/*
  10423. X * Copyright (c) 1992 Michael A. Cooper.
  10424. X * This software may be freely distributed provided it is not sold for 
  10425. X * profit and the author is credited appropriately.
  10426. X */
  10427. X
  10428. X#ifndef lint
  10429. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/info-alliant.c,v 1.3 1992/04/26 23:32:06 mcooper Exp $";
  10430. X#endif
  10431. X
  10432. X/*
  10433. X * $Log: info-alliant.c,v $
  10434. X * Revision 1.3  1992/04/26  23:32:06  mcooper
  10435. X * Add Copyright notice
  10436. X *
  10437. X * Revision 1.2  1992/03/31  19:00:15  mcooper
  10438. X * A working version.
  10439. X *
  10440. X * Revision 1.2  1992/03/31  19:00:15  mcooper
  10441. X * A working version.
  10442. X *
  10443. X * Revision 1.1  1992/03/01  23:28:16  mcooper
  10444. X * Initial revision
  10445. X *
  10446. X */
  10447. X
  10448. X/*
  10449. X * Alliant specific information
  10450. X */
  10451. X#include <stdio.h>
  10452. X#include "system.h"
  10453. X#include "defs.h"
  10454. X
  10455. X#include <nlist.h>
  10456. X
  10457. X/*
  10458. X * Kernel version symbols
  10459. X */
  10460. Xstruct nlist VersionInfoNL[] = {
  10461. X    { "_versionname" },
  10462. X    { "_versiondate" },
  10463. X    { 0 },
  10464. X};
  10465. X
  10466. X/*
  10467. X * Table of Alliant system models
  10468. X */ 
  10469. XNAMETAB ModelTab[] = {
  10470. X#ifdef MODELNUM_FX2800
  10471. X    {  MODELNUM_FX2800,        "FX2800" },
  10472. X#endif
  10473. X#ifdef MODELNUM_FX800
  10474. X    {  MODELNUM_FX800,        "FX800" },
  10475. X#endif
  10476. X#ifdef BPB_FX1
  10477. X    {  BPB_FX1,            "FX1" },
  10478. X#endif
  10479. X#ifdef BPB_FX4
  10480. X    {  BPB_FX4,            "FX4" },
  10481. X#endif
  10482. X#ifdef BPB_FX40
  10483. X    {  BPB_FX40,        "FX40" },
  10484. X#endif
  10485. X#ifdef BPB_FX8
  10486. X    {  BPB_FX8,            "FX80" },
  10487. X#endif
  10488. X#ifdef BPB_FX80
  10489. X    {  BPB_FX80,        "FX80" },
  10490. X#endif
  10491. X};
  10492. X
  10493. X/*
  10494. X * No device support
  10495. X */
  10496. XDEVDATATAB DevDataTab[] = {
  10497. X    { 0 },
  10498. X};
  10499. END_OF_info-alliant.c
  10500. if test 1404 -ne `wc -c <info-alliant.c`; then
  10501.     echo shar: \"info-alliant.c\" unpacked with wrong size!
  10502. fi
  10503. # end of overwriting check
  10504. fi
  10505. if test -f os-bsd43.c -a "${1}" != "-c" ; then 
  10506.   echo shar: Will not over-write existing file \"os-bsd43.c\"
  10507. else
  10508. echo shar: Extracting \"os-bsd43.c\" \(2474 characters\)
  10509. sed "s/^X//" >os-bsd43.c <<'END_OF_os-bsd43.c'
  10510. X/*
  10511. X * Copyright (c) 1992 Michael A. Cooper.
  10512. X * This software may be freely distributed provided it is not sold for 
  10513. X * profit and the author is credited appropriately.
  10514. X */
  10515. X
  10516. X#ifndef lint
  10517. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/os-bsd43.c,v 1.6 1992/04/26 23:32:06 mcooper Exp $";
  10518. X#endif
  10519. X
  10520. X/*
  10521. X * $Log: os-bsd43.c,v $
  10522. X * Revision 1.6  1992/04/26  23:32:06  mcooper
  10523. X * Add Copyright notice
  10524. X *
  10525. X * Revision 1.5  1992/04/17  23:27:51  mcooper
  10526. X * Add support for ROM Version information (Sun only for now).
  10527. X *
  10528. X * Revision 1.4  1992/04/17  01:07:59  mcooper
  10529. X * More de-linting
  10530. X *
  10531. X * Revision 1.3  1992/04/16  19:58:12  mcooper
  10532. X * De-linting stuff.
  10533. X *
  10534. X * Revision 1.2  1992/04/15  02:04:16  mcooper
  10535. X * Change GetMemoryStr() to GetMemory().
  10536. X *
  10537. X * Revision 1.1  1992/03/31  02:39:03  mcooper
  10538. X * Initial revision
  10539. X *
  10540. X */
  10541. X
  10542. X
  10543. X/*
  10544. X * 4.3BSD specific functions
  10545. X */
  10546. X
  10547. X#include <stdio.h>
  10548. X#include "system.h"
  10549. X#include "defs.h"
  10550. X
  10551. X#include <sys/types.h>
  10552. X#include <nlist.h>
  10553. X
  10554. X/*
  10555. X * Get the system model name.  
  10556. X * 4.3BSD (MtXinu) keeps a kernel variable "machineid" which
  10557. X * is the type of machine as defined in <machine/cpu.h>.
  10558. X */
  10559. Xextern char *GetModelName()
  10560. X{
  10561. X    extern NAMETAB        ModelTab[];
  10562. X    extern struct nlist        MachineIDNL[];
  10563. X    static int            machineid;
  10564. X    register int        i;
  10565. X    kvm_t               *kd;
  10566. X
  10567. X    if (!(kd = KVM_open(MachineIDNL))) {
  10568. X    if (Debug) Error("Cannot find MachineID symbol in kernel.");
  10569. X    return((char *) NULL);
  10570. X    }
  10571. X
  10572. X    /*
  10573. X     * See if we got a valid entry
  10574. X     */
  10575. X    if (CheckNlist(&MachineIDNL[0]))
  10576. X    return((char *) NULL);
  10577. X
  10578. X    if (KVM_read(kd, (u_long) MachineIDNL[0].n_value, (char *) &machineid,
  10579. X         sizeof(machineid))) {
  10580. X    if (Debug) Error("Cannot read machineid from kernel.");
  10581. X    return((char *) NULL);
  10582. X    }
  10583. X
  10584. X    KVM_close(kd);
  10585. X
  10586. X    for (i = 0; ModelTab[i].name; ++i)
  10587. X    if (ModelTab[i].value == machineid)
  10588. X        return(ModelTab[i].name);
  10589. X
  10590. X    if (Debug)
  10591. X    printf("system model/type %d is unknown.\n", machineid);
  10592. X
  10593. X    return((char *) NULL);
  10594. X}
  10595. X
  10596. X/*
  10597. X * Get kernel version string from kernel symbol "version".
  10598. X */
  10599. Xextern char *GetKernelVersionStr()
  10600. X{
  10601. X    return(GetKernelVersionFromVersion());
  10602. X}
  10603. X
  10604. X/*
  10605. X * Get amount of physical memory using kernel symbol "physmem".
  10606. X */
  10607. Xextern char *GetMemory()
  10608. X{
  10609. X    return(GetMemoryFromPhysmem());
  10610. X}
  10611. X
  10612. X/*
  10613. X * Get system serial number
  10614. X */
  10615. Xextern char *GetSerialNoStr()
  10616. X{
  10617. X    /* No support */
  10618. X    return((char *) NULL);
  10619. X}
  10620. X
  10621. X/*
  10622. X * Get ROM Version
  10623. X */
  10624. Xextern char *GetRomVer()
  10625. X{
  10626. X    /* No support */
  10627. X    return((char *) NULL);
  10628. X}
  10629. END_OF_os-bsd43.c
  10630. if test 2474 -ne `wc -c <os-bsd43.c`; then
  10631.     echo shar: \"os-bsd43.c\" unpacked with wrong size!
  10632. fi
  10633. # end of overwriting check
  10634. fi
  10635. if test -f info-bsd43.c -a "${1}" != "-c" ; then 
  10636.   echo shar: Will not over-write existing file \"info-bsd43.c\"
  10637. else
  10638. echo shar: Extracting \"info-bsd43.c\" \(1379 characters\)
  10639. sed "s/^X//" >info-bsd43.c <<'END_OF_info-bsd43.c'
  10640. X/*
  10641. X * Copyright (c) 1992 Michael A. Cooper.
  10642. X * This software may be freely distributed provided it is not sold for 
  10643. X * profit and the author is credited appropriately.
  10644. X */
  10645. X
  10646. X#ifndef lint
  10647. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/info-bsd43.c,v 1.2 1992/04/26 23:32:06 mcooper Exp $";
  10648. X#endif
  10649. X
  10650. X/*
  10651. X * $Log: info-bsd43.c,v $
  10652. X * Revision 1.2  1992/04/26  23:32:06  mcooper
  10653. X * Add Copyright notice
  10654. X *
  10655. X * Revision 1.1  1992/03/31  02:39:03  mcooper
  10656. X * Initial revision
  10657. X *
  10658. X * Revision 1.1  1992/03/31  02:39:03  mcooper
  10659. X * Initial revision
  10660. X *
  10661. X */
  10662. X
  10663. X
  10664. X/*
  10665. X * 4.3BSD specific info
  10666. X */
  10667. X
  10668. X#include "system.h"
  10669. X#include "defs.h"
  10670. X
  10671. X#include <sys/types.h>
  10672. X#include <machine/cpu.h>
  10673. X#include <nlist.h>
  10674. X
  10675. X/*
  10676. X * No device support
  10677. X */
  10678. XDEVDATATAB DevDataTab[] = {
  10679. X    { 0 },
  10680. X};
  10681. X
  10682. X/*
  10683. X * MachineID symbol
  10684. X */
  10685. Xstruct nlist MachineIDNL[] = {
  10686. X#if    defined(COFF)
  10687. X    { "machineid" },
  10688. X#else
  10689. X    { "_machineid" },
  10690. X#endif    /* COFF */
  10691. X    { 0 },
  10692. X};
  10693. X
  10694. X/*
  10695. X * Model's as found in kernel variable "machineid" and
  10696. X * defined in <machine/cpu.h>.
  10697. X */
  10698. XNAMETAB ModelTab[] = {
  10699. X#ifdef HP_320
  10700. X    {  HP_320,        "HP9000/320" },
  10701. X#endif
  10702. X#ifdef HP_330
  10703. X    {  HP_330,        "HP9000/330" },
  10704. X#endif
  10705. X#ifdef HP_340
  10706. X    {  HP_340,        "HP9000/340" },
  10707. X#endif
  10708. X#ifdef HP_350
  10709. X    {  HP_350,        "HP9000/350" },
  10710. X#endif
  10711. X#ifdef HP_360
  10712. X    {  HP_360,        "HP9000/360" },
  10713. X#endif
  10714. X#ifdef HP_370
  10715. X    {  HP_370,        "HP9000/370" },
  10716. X#endif
  10717. X    {  0 },
  10718. X};
  10719. X
  10720. END_OF_info-bsd43.c
  10721. if test 1379 -ne `wc -c <info-bsd43.c`; then
  10722.     echo shar: \"info-bsd43.c\" unpacked with wrong size!
  10723. fi
  10724. # end of overwriting check
  10725. fi
  10726. if test -f os-aix.c -a "${1}" != "-c" ; then 
  10727.   echo shar: Will not over-write existing file \"os-aix.c\"
  10728. else
  10729. echo shar: Extracting \"os-aix.c\" \(2552 characters\)
  10730. sed "s/^X//" >os-aix.c <<'END_OF_os-aix.c'
  10731. X/*
  10732. X * Copyright (c) 1992 Michael A. Cooper.
  10733. X * This software may be freely distributed provided it is not sold for 
  10734. X * profit and the author is credited appropriately.
  10735. X */
  10736. X
  10737. X#ifndef lint
  10738. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/os-aix.c,v 1.5 1992/04/26 23:32:06 mcooper Exp $";
  10739. X#endif
  10740. X
  10741. X/*
  10742. X * $Log: os-aix.c,v $
  10743. X * Revision 1.5  1992/04/26  23:32:06  mcooper
  10744. X * Add Copyright notice
  10745. X *
  10746. X * Revision 1.4  1992/04/17  23:27:51  mcooper
  10747. X * Add support for ROM Version information (Sun only for now).
  10748. X *
  10749. X * Revision 1.3  1992/04/17  01:07:59  mcooper
  10750. X * More de-linting
  10751. X *
  10752. X * Revision 1.2  1992/04/15  02:04:16  mcooper
  10753. X * Change GetMemoryStr() to GetMemory().
  10754. X *
  10755. X * Revision 1.1  1992/03/28  23:57:38  mcooper
  10756. X * Initial revision
  10757. X *
  10758. X */
  10759. X
  10760. X
  10761. X/*
  10762. X * AIX specific functions
  10763. X */
  10764. X
  10765. X#include <stdio.h>
  10766. X#include "system.h"
  10767. X#include "defs.h"
  10768. X
  10769. X#include <sys/utsname.h>
  10770. X
  10771. X/*
  10772. X * Get the system model name.
  10773. X */
  10774. Xextern char *GetModelName()
  10775. X{
  10776. X    extern NAMETAB        ModelTab[];
  10777. X    struct utsname        utsname;
  10778. X    register int        i, type;
  10779. X    register char           *p;
  10780. X
  10781. X    if (uname(&utsname) == SYSFAIL) {
  10782. X    if (Debug) Error("uname() failed: %s.", SYSERR);
  10783. X    return((char *) NULL);
  10784. X    }
  10785. X
  10786. X    /*
  10787. X     * XXX HARDCODED value
  10788. X     *
  10789. X     * The following assumes that utsname.machine is of format
  10790. X     *
  10791. X     *    xxyyyyyyMMss
  10792. X     *
  10793. X     *        xx      = 00 (always)
  10794. X     *        yyyyyy    = unique CPU ID
  10795. X     *        MM    = model number
  10796. X     *        ss    = 00 (always)
  10797. X     */
  10798. X    if (strlen(utsname.machine) != 12) {
  10799. X    if (Debug) Error("The format of utsname.machine has changed!");
  10800. X    return((char *) NULL);
  10801. X    }
  10802. X    p = utsname.machine;
  10803. X    p += 8;
  10804. X    if (strlen(p) > 2)
  10805. X    *(p+2) = (char)NULL;
  10806. X
  10807. X    for (i = 0; ModelTab[i].name; ++i)
  10808. X    if (EQ(p, ModelTab[i].valuestr))
  10809. X        return(ModelTab[i].name);
  10810. X
  10811. X    if (Debug)
  10812. X    Error("system model/type %s is unknown.\n", p);
  10813. X
  10814. X    return((char *) NULL);
  10815. X}
  10816. X
  10817. X/*
  10818. X * Get kernel version string from kernel symbol "version".
  10819. X */
  10820. Xextern char *GetKernelVersionStr()
  10821. X{
  10822. X    return(GetKernelVersionFromVersion());
  10823. X}
  10824. X
  10825. X/*
  10826. X * Get amount of physical memory using kernel symbol "physmem".
  10827. X */
  10828. Xextern char *GetMemory()
  10829. X{
  10830. X    return(GetMemoryFromPhysmem());
  10831. X}
  10832. X
  10833. X/*
  10834. X * Get system serial number
  10835. X */
  10836. Xextern char *GetSerialNoStr()
  10837. X{
  10838. X    /* No support */
  10839. X    return((char *) NULL);
  10840. X}
  10841. X
  10842. X/*
  10843. X * Get name of OS
  10844. X */
  10845. Xextern char *GetOSNameStr()
  10846. X{
  10847. X    return(GetOSNameFromUname());
  10848. X}
  10849. X
  10850. X/*
  10851. X * Get version of OS
  10852. X */
  10853. Xextern char *GetOSVersionStr()
  10854. X{
  10855. X    return(GetOSVersionFromUname());
  10856. X}
  10857. X
  10858. X/*
  10859. X * Get ROM Version
  10860. X */
  10861. Xextern char *GetRomVer()
  10862. X{
  10863. X    /* No support */
  10864. X    return((char *) NULL);
  10865. X}
  10866. END_OF_os-aix.c
  10867. if test 2552 -ne `wc -c <os-aix.c`; then
  10868.     echo shar: \"os-aix.c\" unpacked with wrong size!
  10869. fi
  10870. # end of overwriting check
  10871. fi
  10872. if test -f info-aix.c -a "${1}" != "-c" ; then 
  10873.   echo shar: Will not over-write existing file \"info-aix.c\"
  10874. else
  10875. echo shar: Extracting \"info-aix.c\" \(1088 characters\)
  10876. sed "s/^X//" >info-aix.c <<'END_OF_info-aix.c'
  10877. X/*
  10878. X * Copyright (c) 1992 Michael A. Cooper.
  10879. X * This software may be freely distributed provided it is not sold for 
  10880. X * profit and the author is credited appropriately.
  10881. X */
  10882. X
  10883. X#ifndef lint
  10884. Xstatic char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/info-aix.c,v 1.2 1992/04/26 23:32:06 mcooper Exp $";
  10885. X#endif
  10886. X
  10887. X/*
  10888. X * $Log: info-aix.c,v $
  10889. X * Revision 1.2  1992/04/26  23:32:06  mcooper
  10890. X * Add Copyright notice
  10891. X *
  10892. X * Revision 1.1  1992/03/28  23:57:38  mcooper
  10893. X * Initial revision
  10894. X *
  10895. X */
  10896. X
  10897. X
  10898. X/*
  10899. X * AIX related information
  10900. X */
  10901. X
  10902. X#include <stdio.h>
  10903. X#include "system.h"
  10904. X#include "defs.h"
  10905. X
  10906. X/*
  10907. X * These values were gleamed from a copy of the
  10908. X * AIXpert magazine.
  10909. X */
  10910. XNAMETAB ModelTab[] = {
  10911. X    { 0, "RS6000/320",            "31" },
  10912. X    { 0, "RS6000/320H",            "35" },
  10913. X    { 0, "RS6000/520",            "30" },
  10914. X    { 0, "RS6000/[57]30",        "10" },
  10915. X    { 0, "RS6000/530H",            "18" },
  10916. X    { 0, "RS6000/540",            "14" },
  10917. X    { 0, "RS6000/550",            "1C" },
  10918. X    { 0, "RS6000/930",            "20" },
  10919. X    { 0, "RS6000/950",            "2E" },
  10920. X    { 0 },
  10921. X};
  10922. X
  10923. X/*
  10924. X * Device Data Table (Not implemented yet)
  10925. X */
  10926. XDEVDATATAB DevDataTab[] = {
  10927. X    {  0 },
  10928. X};
  10929. END_OF_info-aix.c
  10930. if test 1088 -ne `wc -c <info-aix.c`; then
  10931.     echo shar: \"info-aix.c\" unpacked with wrong size!
  10932. fi
  10933. # end of overwriting check
  10934. fi
  10935. if test -f options.3 -a "${1}" != "-c" ; then 
  10936.   echo shar: Will not over-write existing file \"options.3\"
  10937. else
  10938. echo shar: Extracting \"options.3\" \(7383 characters\)
  10939. sed "s/^X//" >options.3 <<'END_OF_options.3'
  10940. X.\"
  10941. X.\" Copyright (c) 1990 Michael A. Cooper.
  10942. X.\" This software may be freely distributed provided it is not sold for 
  10943. X.\" profit and the author is credited appropriately.
  10944. X.\"
  10945. X.\" $Header: /src/common/usc/lib/libgen/RCS/options.3,v 1.4 1991/02/22 02:30:06 mcooper Exp $
  10946. X.\"
  10947. X.TH PARSEOPTIONS 3 "30 October 1990"
  10948. X.ds ]W USC-UCS
  10949. X.SH NAME
  10950. XParseOptions, UsageOptions, HelpOptions, Num_Opts \- Parse command line options
  10951. X.SH SYNOPSIS
  10952. X.LP
  10953. X.nf
  10954. X.ft B
  10955. X#include "/usr/usc/include/options.h"
  10956. X.ft
  10957. X.fi
  10958. X.LP
  10959. X.nf
  10960. X.ft B
  10961. Xint ParseOptions(options, num_options, argc, argv)
  10962. XOptionDescRec *options;
  10963. Xint num_options;
  10964. Xint argc;
  10965. Xchar **argv;
  10966. X.ft
  10967. X.fi
  10968. X.LP
  10969. X.nf
  10970. X.ft B
  10971. Xvoid UsageOptions(options, num_options, badoption)
  10972. XOptionDescRec *options;
  10973. Xint num_options;
  10974. Xchar *badoption;
  10975. X.ft
  10976. X.fi
  10977. X.LP
  10978. X.nf
  10979. X.ft B
  10980. Xvoid HelpOptions(options, num_options, message)
  10981. XOptionDescRec *options;
  10982. Xint num_options;
  10983. Xchar **message;
  10984. X.ft
  10985. X.fi
  10986. X.LP
  10987. X.nf
  10988. X.ft B
  10989. Xint Num_Opts(options)
  10990. XOptionDescRec *options;
  10991. X.ft
  10992. X.fi
  10993. X.LP
  10994. X.nf
  10995. X.ft B
  10996. Xextern char *OptionChars;
  10997. Xextern char *ProgramName;
  10998. X.ft
  10999. X.fi
  11000. X.SH DESCRIPTION
  11001. X.LP
  11002. X.BR ParseOptions(\|)
  11003. Xparses a given set of options found in
  11004. X.B argv.
  11005. XThe
  11006. X.B argc
  11007. Xparameter is the count of the number of string pointers
  11008. Xin 
  11009. X.B argv.
  11010. XBoth 
  11011. X.B argc
  11012. Xand
  11013. X.B argv
  11014. Xare typically passed directly from a
  11015. X.B main(\|)
  11016. Xfunction.
  11017. XThe
  11018. X.B argv
  11019. Xparameter should contain an array of strings that
  11020. Xneed to be parsed.
  11021. X.B ParseOptions(\|)
  11022. Xreturns the number of entries in
  11023. X.B argv
  11024. Xthat were successfully parsed or -1 upon error.
  11025. X.LP
  11026. XThe
  11027. X.B options
  11028. Xstructure should contain a valid description list of options.
  11029. XThe type
  11030. X.B OptionDescRec
  11031. Xis defined as the following in the
  11032. X.B "options.h"
  11033. Xheader file:
  11034. X.RS
  11035. X.LP
  11036. X.nf
  11037. X.ft B
  11038. Xtypedef struct {
  11039. X    char      *option;     /* Option string in argv */
  11040. X    int       flags;       /* Flag bits */
  11041. X    int       (*cvtarg)(); /* Function to convert argument */
  11042. X    caddr_t   valp;        /* Variable to set */
  11043. X    caddr_t   value;       /* Default value to provide */
  11044. X    char      *usage;      /* Usage message */
  11045. X    char      *desc;       /* Description message */
  11046. X} OptionDescRec, *OptionDescList;
  11047. X.ft R
  11048. X.fi
  11049. X.RE
  11050. X.LP
  11051. XThe order of
  11052. X.I options
  11053. Xis important because
  11054. Xthe first partial match found in
  11055. X.I options 
  11056. Xis used.
  11057. XThis allows abbreviations (except if the option is a
  11058. X.I StickArg
  11059. X[see below]).
  11060. XFor instance, a user may specify only "\-n" for "\-number" provided
  11061. Xthat "\-n" is unique to
  11062. X.I options
  11063. Xor that "\-number" is placed before any other "\-n*" options in
  11064. X.I options.
  11065. X.LP
  11066. XThe
  11067. X.I option
  11068. Xmember of
  11069. X.B OptionDescRec
  11070. Xis the string name of the option.
  11071. XThis is typically something like
  11072. X.RS
  11073. X.ft B
  11074. X.nf
  11075. X.sp
  11076. X"\-c"
  11077. X"+c"
  11078. X"\-file"
  11079. X.fi
  11080. X.sp
  11081. X.ft
  11082. X.RE
  11083. XThe first character of 
  11084. X.I option
  11085. Xis special.  It must be one of the characters know to be the
  11086. Xstart of an option.
  11087. XThe default list of starting option characters is "\-+".
  11088. XThis indicates that an option can start with either a "\-" or
  11089. Xa "+".  This list of characters may be changed by setting
  11090. Xthe variable
  11091. X.B OptionChars
  11092. Xto point to a string of custom starting option characters.
  11093. X.LP
  11094. XThe
  11095. X.I flags
  11096. Xmember is used to set bits to describe how an option
  11097. Xis to be interpreted.
  11098. XValid flags are defined in the
  11099. X.I "options.h"
  11100. Xheader file:
  11101. X.RS
  11102. X.IP NoArg
  11103. XNo argument for this option.  
  11104. XUse the value in 
  11105. X.I OptionDescRec.value 
  11106. Xto set the value in the
  11107. X.I valp
  11108. Xmember of 
  11109. X.B OptionDescRec.
  11110. X.IP IsArg
  11111. XValue is the option string itself.
  11112. X.IP SepArg
  11113. XValue is in next argument in argv.
  11114. X.IP StickyArg
  11115. XValue is the characters immediately following 
  11116. Xthe option.
  11117. X.IP SkipArg
  11118. XIgnore this option and the next argument in argv.
  11119. X.IP SkipLine
  11120. XIgnore this option and the rest of argv.
  11121. X.IP SkipNArgs
  11122. XIgnore this option and the next 
  11123. X.I OptionDescRes.value 
  11124. Xarguments in argv.
  11125. X.IP ArgHidden
  11126. XDon't show this option in usage or help messages.
  11127. X.RE
  11128. X.LP
  11129. XThe next member of
  11130. X.B OptionDescRec
  11131. Xis
  11132. X.I cvtarg.
  11133. XThis should be a pointer to a function that knows how to
  11134. Xconvert the given argument into the correct type.
  11135. XThe predefined functions are as follows:
  11136. X.RS
  11137. X.IP OptBool
  11138. XConverts a boolean.
  11139. X.IP OptInt
  11140. XConverts an integer.
  11141. X.IP OptShort
  11142. XConverts a short.
  11143. X.IP OptLong
  11144. XConverts a long.
  11145. X.IP OptStr
  11146. XConverts a string.
  11147. X.RE
  11148. X.LP
  11149. XThe
  11150. X.I valp
  11151. Xmember should be a pointer
  11152. Xto the variable that needs to be set.
  11153. X.I valp
  11154. Xshould accept whatever type
  11155. X.I cvtarg
  11156. Xis expected to return.
  11157. X.LP
  11158. XThe
  11159. X.I value
  11160. Xmember should contain a default value to
  11161. Xbe used if no value is given for an option or
  11162. Xthis type of option does not require an argument
  11163. X(according to the 
  11164. X.I flags
  11165. Xbits).
  11166. XIf 
  11167. X.I value 
  11168. Xis
  11169. X.B NULL
  11170. Xthen an argument for this option
  11171. Xis optional.
  11172. X.LP
  11173. X.I usage
  11174. Xis used to build usage and help messages.
  11175. XIt should be a string containing a description of any arguments
  11176. Xthat may be used for this option.
  11177. XThe option string itself should not be a part of 
  11178. X.I usage.
  11179. XThe 
  11180. X.B UsageOptions(\|)
  11181. Xand 
  11182. X.B HelpOptions(\|)
  11183. Xfunctions combine the
  11184. X.I option
  11185. Xfield with
  11186. X.I usage
  11187. Xand interpret the
  11188. X.I flags
  11189. Xbits to build a usage string.
  11190. XIf this field is 
  11191. X.B NULL,
  11192. Xthen just the
  11193. X.I option
  11194. Xfield itself is used for usage and help messages.
  11195. X.LP
  11196. XThe
  11197. X.I desc
  11198. Xmember is used to build a help message for this option.
  11199. XThis should be a string containing a brief description on what this
  11200. Xoption does.
  11201. X.LP
  11202. XThe
  11203. X.B num_options
  11204. Xparameter should be the number of 
  11205. X.B OptionDescRec's
  11206. Xfound in 
  11207. X.B options.
  11208. XThe function
  11209. X.BR Num_Opts(\|)
  11210. Xwill return the number of 
  11211. X.B OptionDescRec's.
  11212. X.LP
  11213. XThe
  11214. X.B UsageOptions(\|)
  11215. Xfunction
  11216. Xprints a usage message.
  11217. XIf
  11218. X.I badoption
  11219. Xis not 
  11220. X.B NULL, 
  11221. Xthen an initial message is displayed indicating that 
  11222. X.I badoption
  11223. Xis not a valid option.
  11224. X.LP
  11225. XThe
  11226. X.B HelpOptions(\|)
  11227. Xfunction
  11228. Xprints a nicely formatted message describing all options.
  11229. XIf
  11230. X.I message
  11231. Xis not 
  11232. X.B NULL
  11233. Xit is taken to be a message that is displayed in the output of
  11234. Xa "\-help" option.
  11235. X.SH EXAMPLE
  11236. X.LP
  11237. XHere is an example program:
  11238. X.nf
  11239. X.sp
  11240. X.ft B
  11241. X#include "options.h"
  11242. X
  11243. Xchar *filename = NULL;
  11244. Xint number = \-1;
  11245. Xint foo = \-1;
  11246. Xint I = \-1;
  11247. Xlong L = \-1;
  11248. Xshort S = \-1;
  11249. X
  11250. XOptionDescRec opts[] = {
  11251. X    {"\-foo",    NoArg,        OptBool, (caddr_t) &foo,    "0",
  11252. X     (char *)NULL,    "Disable foo bar"},
  11253. X    {"+foo",    NoArg,        OptBool, (caddr_t) &foo,           "1",
  11254. X     (char *)NULL,    "Enable foo bar"},
  11255. X    {"\-I",    StickyArg,    OptInt, (caddr_t) &I,        (caddr_t) NULL,
  11256. X     (char *)NULL,    "Set value of I"},
  11257. X    {"\-L",    StickyArg,    OptLong, (caddr_t) &L,        (caddr_t) NULL,
  11258. X     (char *)NULL,    "Set value of L"},
  11259. X    {"\-S",    SepArg,        OptShort, (caddr_t) &S,        (caddr_t) NULL,
  11260. X     (char *)NULL,    "Set value of S"},
  11261. X    {"\-C",    StickyArg,    OptStr, (caddr_t) &filename,    (caddr_t) NULL,
  11262. X     (char *)NULL,    "Alternate file to use"},
  11263. X    {"\-number",    SepArg,     OptInt, (caddr_t) &number,    "66",
  11264. X     "interval",    NULL},
  11265. X    {"\-file",    SepArg,     OptStr, (caddr_t) &filename,    (caddr_t) NULL,
  11266. X     "filename",    "Specify alternate file to use"},
  11267. X};
  11268. X
  11269. Xmain(argc, argv)
  11270. X     int argc;
  11271. X     char **argv;
  11272. X{
  11273. X    int c;
  11274. X
  11275. X    c = ParseOptions(opts, Num_Opts(opts), argc, argv);
  11276. X    printf("Count = %d of %d\n", c, argc);
  11277. X}
  11278. X.ft
  11279. X.fi
  11280. X.SH "RETURN VALUES"
  11281. X.B ParseOptions(\|)
  11282. Xreturns the number of arguments parsed or -1 upon error.
  11283. X.SH NOTES
  11284. X.LP
  11285. XThe
  11286. X.I \-help
  11287. Xoption is automatically built into 
  11288. X.B ParseOptions(\|).
  11289. X.LP
  11290. XAll error messages are sent to 
  11291. X.B stderr.
  11292. X.LP
  11293. XAn option may be both 
  11294. X.I StickyArg
  11295. Xand
  11296. X.I SepArg.
  11297. XIf both are set for one option, preference is given to
  11298. X.I SepArg
  11299. Xparsing.
  11300. XAlso, no appreviations are allowed.
  11301. X.SH AUTHOR
  11302. XMichael A. Cooper, 
  11303. X.br
  11304. XUniversity Computing Services, 
  11305. X.br
  11306. XUniversity of Southern California.
  11307. END_OF_options.3
  11308. if test 7383 -ne `wc -c <options.3`; then
  11309.     echo shar: \"options.3\" unpacked with wrong size!
  11310. fi
  11311. # end of overwriting check
  11312. fi
  11313. if test -f Mkfile.cpp -a "${1}" != "-c" ; then 
  11314.   echo shar: Will not over-write existing file \"Mkfile.cpp\"
  11315. else
  11316. echo shar: Extracting \"Mkfile.cpp\" \(3024 characters\)
  11317. sed "s/^X//" >Mkfile.cpp <<'END_OF_Mkfile.cpp'
  11318. X#
  11319. X# $Header: /src/common/usc/bin/sysinfo/RCS/Mkfile.cpp,v 1.24 1992/06/01 22:38:55 mcooper Exp $
  11320. X#
  11321. X
  11322. X#define USE_KARCH
  11323. X#include "/usr/usc/include/mk/all.h"
  11324. X
  11325. XKVM        = /usr/kvm/lsd
  11326. XBIN         = /usr/lsd/bin
  11327. XMAN         = /usr/usc/man/man1
  11328. X
  11329. X#if defined(sun)
  11330. XLIBKVM        = -lkvm
  11331. X#else
  11332. XLIBKVM        =
  11333. X#endif
  11334. X
  11335. X#if defined(sun) && defined(OSVERSION) && OSVERSION == 40
  11336. XCC        = /usr/5bin/cc
  11337. XLIBS         = /usr/5lib/libc.a -L/usr/usc/lib -lgen $LIBKVM
  11338. X#else
  11339. XLIBS         = -L/usr/usc/lib -lgen $LIBKVM
  11340. X#endif
  11341. X#if defined(alliant)
  11342. XCC        = cc
  11343. XLIBS         = /usr/usc/lib/libgen.a -lcommon $LIBKVM
  11344. X#endif
  11345. X#if defined(NeXT)
  11346. XCC        = gcc
  11347. X#endif
  11348. X
  11349. XNETIFOBJS    = ${O}netif.o ${O}info-netif.o
  11350. XMACHOBJS    = ${O}os-"mach".o ${O}info-"mach".o
  11351. X#ifdef sun
  11352. XOSFILES        = ${O}os-"sunos".o ${O}info-"sunos".o $NETIFOBJS
  11353. XOSDEFS        = -D`/bin/arch -k`
  11354. X#endif
  11355. X#ifdef ultrix
  11356. XOSFILES        = ${O}os-"ultrix".o ${O}info-"ultrix".o $NETIFOBJS
  11357. X#endif
  11358. X#ifdef NeXT
  11359. XOSFILES        = ${O}os-"next".o ${O}info-"next".o $MACHOBJS $NETIFOBJS
  11360. X#endif
  11361. X#ifdef alliant
  11362. XOSFILES        = ${O}os-"alliant.o" ${O}info-"alliant".o
  11363. X#endif
  11364. X#ifdef _AIX
  11365. XOSFILES        = ${O}os-"aix.o" ${O}info-"aix".o
  11366. X#endif
  11367. X/* Should use something besides hp300 */
  11368. X#ifdef hp300
  11369. XOSFILES        = ${O}os-"bsd43.o" ${O}info-"bsd43".o
  11370. X#endif
  11371. X
  11372. XOPT        = -g
  11373. X#ifdef sun
  11374. XINCLUDES    = -I/usr/usc/include
  11375. X#else
  11376. XINCLUDES    = -I/usr/usc/include -I.
  11377. X#endif
  11378. XDEFINES        = -DOPTION_COMPAT $OSDEFS
  11379. XCFLAGS         = $OPT $INCLUDES $DEFINES
  11380. X
  11381. X
  11382. XNPROC         = 4
  11383. XBASE         = sysinfo
  11384. XPROG         = ${O}sysinfo
  11385. XOBJS         = ${O}sysinfo.o ${O}devices.o ${O}memory.o ${O}kernel.o \
  11386. X            ${O}run.o ${O}KVM.o ${O}kvm.o ${O}strdup.o $OSFILES
  11387. XSRCS        = "`echo $OBJS | sed -e "s;$O;;g" -e 's;\.o;.c;g'`"
  11388. XALLSRCS        = sysinfo.c devices.c memory.c kernel.c\
  11389. X            run.c KVM.c kvm.c kvm.h patchlevel.h \
  11390. X            strcasecmp.c strdup.c strerror.c \
  11391. X            options.c options.h \
  11392. X            system.h defs.h \
  11393. X            netif.c info-netif.c \
  11394. X            os-mach.c info-mach.c \
  11395. X            os-sunos.c info-sunos.c \
  11396. X            os-ultrix.c info-ultrix.c info-ultrix.h \
  11397. X            os-next.c info-next.c \
  11398. X            os-alliant.c info-alliant.c \
  11399. X            os-bsd43.c info-bsd43.c \
  11400. X            os-aix.c info-aix.c
  11401. X
  11402. Xall: $PROG
  11403. X
  11404. X$PROG: $OBJS $LIBS
  11405. X    $CC $CFLAGS -o ${target} $OBJS $LIBS
  11406. X
  11407. X#if    defined(sun)
  11408. Xinstall: ${PROG}
  11409. X    install -c -m 4555 -o root -g wheel $PROG $KVM/$BASE
  11410. X    (cd $BIN && rm -f $BASE && ln -s $KVM/$BASE $BASE)
  11411. X#else
  11412. Xinstall: ${PROG}
  11413. X    install -c -m 4555 -o root -g wheel $PROG $BIN/$BASE
  11414. X#endif    /* sun */
  11415. X
  11416. Xinstall.man: ${BASE}.man
  11417. X    install -c -m 444 -o bin -g bin ${BASE}.man $MAN/$BASE.1
  11418. X
  11419. Xinstall.compat:
  11420. X    install -c -m 555 -o bin -g bin cpumodel.sh /usr/lsd/etc/cpumodel
  11421. X    rm -f $MAN/${BASE}.8 $MAN/cpumodel.1
  11422. X    (cd /usr/usc/bin; rm -f sysinfo; ln -s ${BIN}/sysinfo)
  11423. X
  11424. X#
  11425. X# Centerline stuff
  11426. X#
  11427. X#ifdef sun /* Some platforms don't like the #load below */
  11428. Xcc_src:
  11429. X    #load $CFLAGS $SRCS $LIBS $LIBKVM
  11430. X
  11431. Xcc_obj:
  11432. X    #load $CFLAGS $OBJS $LIBS $LIBKVM
  11433. X#endif
  11434. X
  11435. Xclean:
  11436. X    rm -f ${PROG} *~ *% \#* core a.out ${O}*.o
  11437. X
  11438. X$OBJS: system.h defs.h
  11439. X
  11440. XDISTFILES = README sysinfo.man Makefile $ALLSRCS options.3 Mkfile.cpp
  11441. X
  11442. Xsysinfo.tar: $DISTFILES
  11443. X    rm -f $target
  11444. X    tar chf $target $DISTFILES
  11445. X
  11446. Xsysinfo.shar: $DISTFILES
  11447. X    rm -f $target
  11448. X    shar $DISTFILES > $target
  11449. END_OF_Mkfile.cpp
  11450. if test 3024 -ne `wc -c <Mkfile.cpp`; then
  11451.     echo shar: \"Mkfile.cpp\" unpacked with wrong size!
  11452. fi
  11453. # end of overwriting check
  11454. fi
  11455. echo shar: End of shell archive.
  11456. exit 0
  11457.