KVM_DISKS(3) BSD Programmer's Manual KVM_DISKS(3)NAME
kvm_disks, kvm_dknames - disk drive statistics
SYNOPSIS
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/diskstats.h>
#include <kvm.h>
#include <kvm_stat.h>
int
kvm_disks(kvm_t *kd, struct diskstats *dkp, int ndisks);
char **
kvm_dknames(kvm_t *kd, int *ndisksp);
DESCRIPTION
The kvm_dknames() function returns a vector of disk name strings. The
number of elements in the vector is returned in the variable referenced
by ndisksp. The returned vector and strings are only valid until the next
call to kvm_dknames() or kvm_close(3).
The kvm_disks() function obtains the disk statistics from the kernel in-
dicated by kd. The disk statistics are returned as a table of struct
diskstats structures with a one-to-one correspondence with the disk names
in the vector returned by kvm_dknames(). Memory for these structures
should be obtained via malloc(3) and should be released via free(3). It
is recommended that ndisks be specified at least one greater than the
number of disks returned by kvm_dknames() in order to determine if the
number of disks on the system has increased.
RETURN VALUES
The kvm_disks() function returns the number of disks for which statistics
have been provided. If this value is different from the value returned
by kvm_dknames(), then one or more disks have been added or removed. On
failure, -1 is returned.
The kvm_dknames() function returns a vector disk names. On failure, NULL
is returned.
EXAMPLE
struct diskstats *dkp;
char **names;
int count, n;
do {
if ((names = kvm_dknames(kd, &count)) == NULL)
errx(1, "%s", kvm_geterr(kd));
if ((dkp = malloc((count + 1) * sizeof(*dkp))) == NULL)
errx(1, "out of memory");
n = kvm_disks(kd, dkp, count + 1);
if (n == -1)
errx(1, "%s", kvm_geterr(kd));
while (n != count);
SEE ALSOkvm(3), kvm_open(3), kvm_openfiles(3), kvm_close(3), kvm_read(3),
kvm_write(3), kvm_nlist(3), kvm_geterr(3)BUGS
The kvm_dknames() and kvm_disks() routines currently only work on live
kernels.