GETDEVPATH(3)

NAME
getdevpath - retrieve device path given name or label

LIBRARY
libc

SYNOPSIS
#include <sys/types.h>
#include <fstab.h>
char *
getdevpath(const char *devname, int flags);

DESCRIPTION
getdevpath() takes a device name such as “da0”, a device identifier such as “V21JYQ0G”, a device path beginning with “/” or “~”., or a device label from one of the devtab files, and returns an allocated path which may be used to open the device.

Device names prefixed with “/” or “~”. are assumed to be device paths and an exact allocated copy is simply returned. However, flags may modify the operation.

Device names specified with a type prefix, such as “serno:V21JYQ0G” are assumed to be typed device identifiers and are directly translated to the appropriate path in /dev, for example “/dev/serno/V21JYQ0G”.

Device labels are directly checked against /dev first, using lstat(), and if not found will be searched for in one of the devtab files.

The following flags may be passed to getdevpath():

GETDEVPATH_RAWDEV
    Normally, getdevpath() returns a high level devfs path which often winds up being a softlink in devfs. If this flag is specified and the device path represents a softlink, getdevpath() will do a readlink(2) and return the actual raw device path instead. If the device path cannot be lstat()'d this option will return NULL.

RETURN VALUES
getdevpath() returns a pointer to a malloc()'d path on success and NULL on failure. If a failure occurs errno will be set appropriately.

Note that a malloc()'d path may be returned even if it does not exist in the filesystem. Callers should not assume that the device is accessible unless they can also open the device.

SEE ALSO
devfs(5), devtab(5), fstab(5)

HISTORY
The getdevpath function appeared in DragonFly 2.3.