Using the HP-UX libIO Library
/* initialize libIO operations */
if (io_init(O_RDONLY)!=IO_SUCCESS) {
io_error("ERROR:io_init");
exit(1);
}
/* get an existing legacy disk I/O node */
if ((node = io_search ((io_token_t)NULL, S_IOTREE, Q_SW,
"driver_name", "sdisk", "class", "disk", NULL))
==(io_token_t)NULL) {
io_error("ERROR:io_search:class:disk");
exit(1);
}
/* ascertain the type of device */
if (io_query(node, S_IOTREE, "is_char", &is_char)
== IO_SUCCESS) {
dev_type=D_CHR
} else if (io_query(node, S_IOTREE, "is_block",
&is_block)== IO_SUCCESS) dev_type=D_BLK;
/* try out io_mkdev() */
if (io_mkdev(node, dev_type, "s0", &dev) != IO_SUCCESS) {
io_error("ERROR:io_mkdev:options:s0");
exit(1);
}
if( io_legacy_to_new_dev(dev, dev_type, &new_dev)
==IO_ERROR) {
io_error("ERROR io_legacy_to_new_dev");
exit(1);
}
printf("major number of agile dev is %d\n",
major(new_dev));
/*get an exiting agile disk I/O node */
if ((node=io_search((io_token_t)NULL, S_IOTREE_EXT,
Q_SW, "class", "disk", NULL)) == (io_token_t)NULL) {
io_error("ERROR:io_search:class:disk");
exit(1);
}
/* ascertain the type of device */
if (io_query(node, S_IOTREE_EXT, "is_char", &is_char)
== IO_SUCCESS) {
dev_type = D_CHR;
} else if (io_query(node, S_IOTREE_EXT, "is_block",
&is_block)==IO_SUCCESS) dev_type = D_BLK;