View Single Post
  #2   (View Single Post)  
Old 11th July 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Default

Wow that's strange terminology you use.

If you read sysctl(3), you'll find HW_DISKNAMES in the CTL_HW section.

You can view the currently detected devices via sysctl(8):
$ sysctl hw.disknames

It's quite trivial to write a program which prints the results as well.
Code:
#include <stdio.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;
}
EDIT: Doh! It would appear you're a FreeBSD user, somehow I didn't catch that in your first reply.. unfortunately it would seem FreeBSD has no equivalent sysctl member.

Last edited by BSDfan666; 11th July 2008 at 11:44 PM.
Reply With Quote