Date: Wed, 13 Aug 2014 20:29:21 +0200 From: Lars Engels <lme@freebsd.org> To: "Sam Fourman Jr." <sfourman@gmail.com> Cc: hackers@freebsd.org Subject: Re: sysctl(3) question Message-ID: <20140813182921.GG98029@e-new.0x20.net> 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
--zGQnqpIoxlsbsOfg Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Aug 13, 2014 at 12:00:32PM -0500, Sam Fourman Jr. wrote: > Hello Hackers, >=20 > the following command gives me the disks in a system > sysctl kern.disks > kern.disks: cd0 ada0 >=20 >=20 > my question is, what paramaters and values do I have to pass sysctl(3) to > give me those disks? >=20 >=20 >=20 > I have tried and I cant get HW_DISKNAMES from <sys/sysctl.h> to work >=20 >=20 > #include <stdio.h> > #include <stdlib.h> > #include <sys/param.h> > #include <sys/sysctl.h> > #include <err.h> >=20 > int main(void) { >=20 > int mib[2]; > size_t len; > char *p; >=20 > mib[0] =3D CTL_HW; > mib[1] =3D HW_DISKNAMES; >=20 > /* Determine how much space to allocate. */ > if (sysctl(mib, 2, NULL, &len, NULL, 0) =3D=3D -1) > err(1, "sysctl"); >=20 > if ((p =3D (char *)malloc(len)) =3D=3D NULL) > err(1, NULL); >=20 > /* Populate the allocated area with the string returned > * * by sysctl. > * */ > if (sysctl(mib, 2, p, &len, NULL, 0) =3D=3D -1) > err(1, "sysctl"); >=20 > printf("%s\n", p); >=20 > return 0; > } Try sysctlbyname(): #include <stdio.h> #include <stdlib.h> #include <sys/param.h> #include <sys/sysctl.h> #include <err.h> int main(void) { size_t len; char *p; /* Determine how much space to allocate. */ if (sysctlbyname("kern.disks", NULL, &len, NULL, 0) =3D=3D -1) err(1, "sysctl"); if ((p =3D (char *)malloc(len)) =3D=3D NULL) err(1, NULL); if (sysctlbyname("kern.disks", p, &len, NULL, 0) =3D=3D -1) err(1, "sysctl"); printf("%s\n", p); return 0; } --zGQnqpIoxlsbsOfg Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQF8BAEBCgBmBQJT666AXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQ4RjQwMDE3RTRERjUzMTI1N0FGRTUxNDlF NTRDQjM3RDNBMDg5RDZEAAoJEOVMs306CJ1t480H/AojYkkRGlYGimypyiyz1yYs 2BCM2dM9uw1jmtEV6I6lryQGg7If2qgqwK7DNKud9b4cpIJ4dBnz4O9I+K+gYRkn +UfWDE8v8s7T/dSs/jIcNnztZzvFDxAzQsJAGs5CUWq6oIErDR5EzcM2tARQ9PVc s1yD7x/7oh1YrS+Ekg76S8I44PWwpSMt9AktwaZGDdZfVJIFPqytck1Bztbk5SOv f4vL/usotSbYVl1DHTdfA8RlxR2hA58hnhTf9YO1q2i6rnO0k8RgwujP7AONPOIy r/Pdu6uRfLgh4rTmo5qi+KQ4Mluut9dc0CJw5H21gwlvVxsskKj7iqV9BXinhjY= =ovRq -----END PGP SIGNATURE----- --zGQnqpIoxlsbsOfg--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140813182921.GG98029>