How does knlist() work on AIX3.1/RS6000?

Varun Mehta varun at nerdy.Eng.Sun.COM
Tue Aug 14 15:39:43 AEST 1990


I'm trying to read disk info from the kernel using the knlist command
and it keeps returning with an Invalid argument error.  I've read the man
page and I think I got everything right except maybe the Size argument.
i.e:
int knlist(NList, NumberOfElements, Size)
  struct nlist *NList;
  int NumberOfElements;
  int Size;

    Parameters
  
      NList     Points to an array of nlist structures.
  
      NumberOfElements  Specifies the number of structures in the ar-
  ray of nlist structures.
  
      Size      Specifies the size of each structure.
                                      ^^^^^^^^^^^^^^
How does one pass the size of each structure in one int??

I'm also uncertain how to follow the iostat.dkstatp pointer in /dev/mem.
I'm including the program below.  I'd appreciate any help with it,
Thanks,
Varun Mehta
Sun Microsystems, Inc.

#include <stdio.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <nlist.h>
#include <sys/iostat.h>
#include <fcntl.h>

struct nlist nl[] = {
#define X_DKSTAT	0
	{ "iostat" },
};
#define NUM_ELEMENTS	1
struct stats {
	struct iostat iostat;
	struct dkstat dkstat;
} s1, s2;

main()
{
	int fd, i;
	fd = open("/dev/mem", O_RDONLY);
	i = knlist(nl, NUM_ELEMENTS, sizeof(struct iostat));
	if( i == -1) {
		perror("knlist error");
		exit(1);
	}
	for(i = 0; i < NUM_ELEMENTS; i++) {
		if(nl[i].n_value == 0) {
			printf("%s not found\n", nl[i]._n._n_name);
			exit(2);
		}
	}
	lseek(fd, nl[X_DKSTAT].n_value, SEEK_SET);
	read(fd, &(s1.iostat), sizeof(struct iostat));
	lseek(fd, s1.iostat.dkstatp, SEEK_SET);
	read(fd, &(s1.dkstat), sizeof(struct dkstat));
	printf("Disk name %32c\n", s1.dkstat.diskname);
	printf("Disk busy time %d\n", s1.dkstat.dk_time);
}



More information about the Comp.unix.aix mailing list