Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Aug 2014 12:00:32 -0500
From:      "Sam Fourman Jr." <sfourman@gmail.com>
To:        hackers@freebsd.org
Subject:   sysctl(3) question
Message-ID:  <CAOFF%2BZ2y3W7d1EL0PcEQCy28i1oOXDTDhW8z4UyfBUiHgkk6Jg@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOFF%2BZ2y3W7d1EL0PcEQCy28i1oOXDTDhW8z4UyfBUiHgkk6Jg>