From owner-freebsd-hackers@FreeBSD.ORG Wed Aug 13 17:14:14 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 59AC9AEB for ; Wed, 13 Aug 2014 17:14:14 +0000 (UTC) Received: from mho-02-ewr.mailhop.org (mho-02-ewr.mailhop.org [204.13.248.72]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2F2FF245E for ; Wed, 13 Aug 2014 17:14:13 +0000 (UTC) Received: from [73.34.117.227] (helo=ilsoft.org) by mho-02-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1XHc7j-0006l1-8s; Wed, 13 Aug 2014 17:14:07 +0000 Received: from [172.22.42.240] (revolution.hippie.lan [172.22.42.240]) by ilsoft.org (8.14.9/8.14.9) with ESMTP id s7DHE6pW035287; Wed, 13 Aug 2014 11:14:06 -0600 (MDT) (envelope-from ian@FreeBSD.org) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 73.34.117.227 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX1/4mOcJcQnNUcOkFwKFUsNi X-Authentication-Warning: paranoia.hippie.lan: Host revolution.hippie.lan [172.22.42.240] claimed to be [172.22.42.240] Subject: Re: sysctl(3) question From: Ian Lepore To: "Sam Fourman Jr." In-Reply-To: References: Content-Type: text/plain; charset="us-ascii" Date: Wed, 13 Aug 2014 11:14:06 -0600 Message-ID: <1407950046.56408.513.camel@revolution.hippie.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit 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 17:14:14 -0000 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 to work > > > #include > #include > #include > #include > #include > > 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