How to find swap space in SunOS 4

Jeff Clark jclark at src.honeywell.com
Tue Dec 26 13:25:21 AEST 1989


I'm trying to port a program from SunOS/3 to SunOS/4.  This program runs
as root an noses around in /dev/kmem to find certain statistics (e.g.,
averrun vector and number of available swap blocks).

This worked just fine in SunOS 3, but won't even compile under SunOS 4.
The problem stems from missing definitions of the kernel structure
"swdevt" which, under OS/3 was defined in <sys/conf.h> but has been
removed in OS/4.

Here's the relevant excerpts from my code:

#include    <sys/param.h>
#include    <sys/stat.h>
#include    <sys/conf.h>
#include    <sys/map.h>
#include    <nlist.h>
#include    <sys/file.h>
#include    <stdio.h>

#define NSWAPMAP  	0
#define NSWDEV		1
#define SWAPMAP		2
#define SWDEVT		3
#define AVENRUN		4

static struct nlist kAddrs[] = {
	{	"_nswapmap"	},   	/* Number of swap resource maps */
	{	"_nswdev" 	},   	/* Number of swap devices   	*/
	{	"_swapmap"	},   	/* The swap resource maps   	*/
	{	"_swdevt" 	},   	/* The swap devices 	    	*/
	{	"_avenrun"	},   	/* Load averages    	    	*/
	{	""  	  	}
};

static int  	  kmem;		    	/* Descriptor to /dev/kmem */
int	    	  numSwapDevices;
	.
	.
	.
if (nlist ("/vmunix", kAddrs) < 0) {
  printf ("/vmunix: could not read symbol table\n");
} else if ((kmem = open ("/dev/kmem", O_RDONLY, 0)) < 0) {
  printf ("Could not open /dev/kmem\n");
} else {
  /*
   * Find the total number of swap blocks available to the machine
   * by summing the amounts in the swdevt descriptors
   */
  lseek (kmem, (off_t)kAddrs[NSWDEV].n_value, L_SET);
  read (kmem, (char *)&numSwapDevices, sizeof (numSwapDevices));
  swapDevices = (struct swdevt *)malloc(numSwapDevices*sizeof(struct swdevt));
  lseek (kmem, (off_t)kAddrs[SWDEVT].n_value, L_SET);
  read (kmem, (char *)swapDevices, numSwapDevices*sizeof(struct swdevt));
  for (swblocks = 0, sw = swapDevices;
       numSwapDevices != 0;
       sw++, numSwapDevices--)
  {
    if (sw->sw_freed) {
    swblocks += sw->sw_nblks;
    }
  }
	.
	.
	.

Can some kind soul take pity on me and tell me how to do something equivalent
under SunOS/4?  I don't have SunOS sources, and I'm not particuarly
knowledgeable about Unix kernel hacking, so don't worry about insulting my
intelligence by "talking down" to me --- go right ahead and be insulting :-)

Thanks for any help.

Jeff Clark	Honeywell Systems and Research Center	Minneapolis, MN
inet: jclark at src.honeywell.com		tel: 612-782-7347
uucp: jclark at srcsip.UUCP		fax: 612-782-7438
DISCLAIMER: If you think I speak for my employer, you need serious help ...



More information about the Comp.sys.sun mailing list