From owner-freebsd-hackers@FreeBSD.ORG Wed Aug 13 18:29:25 2014 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A5E53950 for ; Wed, 13 Aug 2014 18:29:25 +0000 (UTC) Received: from mail.0x20.net (mail.0x20.net [IPv6:2001:aa8:fffb:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 61AC52B97 for ; Wed, 13 Aug 2014 18:29:25 +0000 (UTC) Received: from e-new.0x20.net (mail.0x20.net [IPv6:2001:aa8:fffb:1::3]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.0x20.net (Postfix) with ESMTPS id 940816A6005; Wed, 13 Aug 2014 20:29:21 +0200 (CEST) Received: from e-new.0x20.net (localhost [127.0.0.1]) by e-new.0x20.net (8.14.7/8.14.7) with ESMTP id s7DITLgo025748; Wed, 13 Aug 2014 20:29:21 +0200 (CEST) (envelope-from lars@e-new.0x20.net) Received: (from lars@localhost) by e-new.0x20.net (8.14.7/8.14.7/Submit) id s7DITLbq024690; Wed, 13 Aug 2014 20:29:21 +0200 (CEST) (envelope-from lars) Date: Wed, 13 Aug 2014 20:29:21 +0200 From: Lars Engels To: "Sam Fourman Jr." Subject: Re: sysctl(3) question Message-ID: <20140813182921.GG98029@e-new.0x20.net> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="zGQnqpIoxlsbsOfg" Content-Disposition: inline In-Reply-To: X-Editor: VIM - Vi IMproved 7.4 X-Operation-System: FreeBSD 8.4-RELEASE-p4 User-Agent: Mutt/1.5.23 (2014-03-12) Cc: hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Aug 2014 18:29:25 -0000 --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 to work >=20 >=20 > #include > #include > #include > #include > #include >=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 #include #include #include #include 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--