Date: Wed, 13 Aug 2014 11:14:06 -0600 From: Ian Lepore <ian@FreeBSD.org> To: "Sam Fourman Jr." <sfourman@gmail.com> Cc: hackers@freebsd.org Subject: Re: sysctl(3) question Message-ID: <1407950046.56408.513.camel@revolution.hippie.lan> In-Reply-To: <CAOFF%2BZ2y3W7d1EL0PcEQCy28i1oOXDTDhW8z4UyfBUiHgkk6Jg@mail.gmail.com> References: <CAOFF%2BZ2y3W7d1EL0PcEQCy28i1oOXDTDhW8z4UyfBUiHgkk6Jg@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 2014-08-13 at 12:00 -0500, Sam Fourman Jr. wrote: > 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. It looks like the HW_DISKNAMES oid is obsolete and the docs and header file never got updated to reflect that. The new disks list uses OID_AUTO rather than a fixed number, so use sysctlbyname(3) to access it. -- Ian
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1407950046.56408.513.camel>