#include <stdio.h>
#include <libdevinfo.h>
#define DISK_DRIVER "sd" /* driver name */
// cc [ flag... ] file... -ldevinfo [ library... ]
// #include <libdevinfo.h>
//
void
prt_diskinfo(di_node_t node)
{
int instance;
char *phys_path;
/*
* If the device node exports no minor nodes,
* there is no physical disk.
*/
if (di_minor_next(node, DI_MINOR_NIL) == DI_MINOR_NIL) {
return;
}
instance = di_instance(node);
phys_path = di_devfs_path(node);
printf("%s%d: %s\n", DISK_DRIVER, instance, phys_path);
di_devfs_path_free(phys_path);
}
void
walk_disknodes(di_node_t node)
{
node = di_drv_first_node(DISK_DRIVER, node);
while (node != DI_NODE_NIL) {
prt_diskinfo(node);
node = di_drv_next_node(node);
}
}
main()
{
di_node_t root_node;
if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
fprintf(stderr, "di_init() failed\n");
exit(1);
}
walk_disknodes(root_node);
di_fini(root_node);
}