DEVFS_SET_CDEVPRIV(9)

NAME
devfs_set_cdevpriv, devfs_get_cdevpriv, devfs_clear_cdevpriv - manage per-open filedescriptor data for devices

SYNOPSIS
#include <sys/devfs.h>

    typedef	void d_priv_dtor_t(void *data);

int
devfs_set_cdevpriv(struct file *fp, void *priv, d_priv_dtor_t *dtr);
int
devfs_get_cdevpriv(struct file *fp, void **datap);
void
devfs_clear_cdevpriv(struct file *fp);

DESCRIPTION
The devfs_xxx_cdevpriv() family of functions allows the device driver methods to associate some driver-specific data with each user process open(2) of the device special file. Currently, functioning of these functions is restricted to the context of the dev_ops switch method calls performed as devfs(5) operations in response to system calls that use file descriptors.

The devfs_set_cdevpriv() function associates a data pointed by priv with the calling context (file descriptor) specified by fp. The data may be retrieved later by devfs_get_cdevpriv(), possibly from another call performed on this file descriptor.

The devfs_clear_cdevpriv() function disassociates the previously attached data from the context specified by fp. At the end of devfs_clear_cdevpriv() operation, the previously associated dtr callback is called, with private data supplied its data argument. The devfs_clear_cdevpriv() function will be automatically called upon the close(2) of the file descriptor.

RETURN VALUES
If successful, the functions return 0.

The function devfs_set_cdevpriv() returns the following values on error:

[ENOENT]
    The passed fp argument is NULL.

[EBUSY]
    The private driver data is already associated with the given fp.

The function devfs_get_cdevpriv() returns the following values on error:

[EBADF]
    The passed fp argument is NULL.

[ENOENT]
    The private driver data was not associated with the given fp, or devfs_clear_cdevpriv() was called.

SEE ALSO
close(2), open(2), devfs(5)

HISTORY
The devfs_xxx_cdevpriv() family of functions first appeared in FreeBSD 7.1, and was implemented in DragonFly 3.8.