#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/disklabel.h> 
#include <sys/sysctl.h> 
#include <unistd.h>

static void diocturtest(const char *name);

int
main(void)
{                       
        static const char mib_name[] = "hw.disknames";
        size_t len;
        char *disknames;
        char *last;
        char *name;     
                                    
        if (sysctlbyname(mib_name, NULL, &len, NULL, 0) == -1)
                err(1, "sysctlbyname");
        if ((disknames = malloc(len + 2)) == 0)
                err(1, "malloc");
                                        
        (void)sysctlbyname(mib_name, disknames, &len, NULL, 0);
        for ((name = strtok_r(disknames, " ", &last)); name;
            (name = strtok_r(NULL, " ", &last))) { 
		    diocturtest(name);
	    }
        free(disknames);                 
	return 1;
}

static void
diocturtest(const char *name)
{
	char dname[16];
	int fd;
	int error;
	int ready;

	sprintf(dname, "/dev/r%s%c", name, 'a'+RAW_PART);
	printf("%s:", dname);
	fd = open(dname, O_RDONLY, 0);
	if (fd == -1) {
		puts(" open failed");
		return;
	}
	error = ioctl(fd, DIOCTUR, &ready);
	printf(" ready %d error:%d\n", ready, error);
	close(fd);
	return;
}