sysctl(3) question
Sam Fourman Jr.
sfourman at gmail.com
Wed Aug 13 17:00:33 UTC 2014
Hello Hackers,
the following command gives me the disks in a system
sysctl kern.disks
kern.disks: cd0 ada0
my question is, what paramaters and values do I have to pass sysctl(3) to
give me those disks?
I have tried and I cant get HW_DISKNAMES from <sys/sysctl.h> to work
#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <err.h>
int main(void) {
int mib[2];
size_t len;
char *p;
mib[0] = CTL_HW;
mib[1] = HW_DISKNAMES;
/* Determine how much space to allocate. */
if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1)
err(1, "sysctl");
if ((p = (char *)malloc(len)) == NULL)
err(1, NULL);
/* Populate the allocated area with the string returned
* * by sysctl.
* */
if (sysctl(mib, 2, p, &len, NULL, 0) == -1)
err(1, "sysctl");
printf("%s\n", p);
return 0;
}
Sam Fourman Jr.
More information about the freebsd-hackers
mailing list