mt.7 (2010 09)

m
mt(7) mt(7)
mt_get_newdev_options()
and mt_check_newdev_options()
are utility functions used by
the code snippets below.
uint64_t
mt_get_newdev_options(dev_t dev, int dev_type) {
uint64_t options;
int err;
err = io_dev_to_options(dev, dev_type, &options);
if (err == IO_ERROR)
return 0;
return (options);
}
uint64_t
mt_check_newdev_options(dev_t dev, int dev_type, uint64_t bitmask) {
uint64_t options;
int err;
err = io_dev_to_options(dev, dev_type, &options);
if (err == IO_ERROR)
return 0;
return (options & bitmask);
}
For example, the macro
M_BERKELEY_AGILE
given below decodes the device options of both legacy and
persistent (agile) DSFs. This macro returns true if the device ID is that of a device special file supporting
Berkeley style of access.
Example
File test.c :
#include <stdlib.h>
#include <sys/libIO.h>
#include <sys/_inttypes.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <fcntl.h>
#include <sys/mtio.h>
#define MT_IS_LEGACY_DEV 1
#define M_BERKELEY_AGILE(dev) \
((io_is_legacy_dev(dev, D_CHR) == MT_IS_LEGACY_DEV) ? \
(dev & MT_BSD_MASK) : \
(mt_check_newdev_options(dev, D_CHR, MT_BSD_MASK)))
/*
* It is assumed that definitions of mt_get_newdev_options() and
* mt_check_newdev_options() are defined by the application and
* available. Omitted here for the sake of simplicity.
*/
int
main(int argc, char *argv[]) {
struct stat stbuf;
dev_t dev;
/* Device special file is passed as argv[1] */
if (stat(argv[1], &stbuf) < 0)
{
perror("stat(): ");
exit (1);
4 Hewlett-Packard Company 4 HP-UX 11i Version 3: September 2010