---
name: "devfs_clear_cdevpriv"
section: "9"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/devfs_clear_cdevpriv"
---

# devfs\_clear\_cdevpriv(9)

manage per-open filedescriptor data for devices

## NAME

**devfs\_set\_cdevpriv**, **devfs\_get\_cdevpriv**, **devfs\_clear\_cdevpriv**, **devfs\_foreach\_cdevpriv** – manage per-open filedescriptor data for devices

## SYNOPSIS

**#include \<sys/param.h\>**

**#include \<sys/conf.h\>**

```
typedef	void d_priv_dtor_t(void *data);
```

*int*\

**devfs\_get\_cdevpriv**(*void \*\*datap*);

*int*\

**devfs\_set\_cdevpriv**(*void \*priv*, *d\_priv\_dtor\_t \*dtr*);

*void*\

**devfs\_clear\_cdevpriv**(*void*);

*int*\

**devfs\_foreach\_cdevpriv**(*struct cdev \*dev*, *int (\*cb)(void \*data, void \*arg)*, *void \*arg*);

## DESCRIPTION

The **devfs\_xxx\_cdevpriv**() family of functions allows the *cdev* driver methods to associate some driver-specific data with each user process [open(2)](/open/2.md) of the device special file. Currently, functioning of these functions is restricted to the context of the *cdevsw* switch method calls performed as [devfs(4)](/devfs/4.md) operations in response to system calls that use filedescriptors.

The **devfs\_set\_cdevpriv**() function associates a data pointed by *priv* with current calling context (filedescriptor). The data may be retrieved later, possibly from another call performed on this filedescriptor, by the **devfs\_get\_cdevpriv**() function. The **devfs\_clear\_cdevpriv**() disassociates previously attached data from context. Immediately after **devfs\_clear\_cdevpriv**() finished operating, the *dtr* callback is called, with private data supplied *data* argument. The **devfs\_clear\_cdevpriv**() function will be also be called if the open callback function returns an error code.

On the last filedescriptor close, system automatically arranges **devfs\_clear\_cdevpriv**() call.

If successful, the functions return 0.

The function **devfs\_set\_cdevpriv**() returns the following values on error:

- \[ENOENT\]

  The current call is not associated with some filedescriptor.

- \[EBUSY\]

  The private driver data is already associated with current filedescriptor.

The function **devfs\_get\_cdevpriv**() returns the following values on error:

- \[EBADF\]

  The current call is not associated with some filedescriptor.

- \[ENOENT\]

  The private driver data was not associated with current filedescriptor, or **devfs\_clear\_cdevpriv**() was called.

The function **devfs\_foreach\_cdevpriv**() sequentially calls the function *cb* for each **cdevpriv** structure, currently associated with the *cdev* device. The iterated **cdevpriv** data pointer and the user-supplied context *arg* are passed to the function *cb*. If *cb* returns non-zero value, the iteration stops on that element. The **devfs\_foreach\_cdevpriv**() returns the return value from the last call to *cb*, or zero if no **cdevpriv** data is currently associated with the device.

Current implementation of the iterator makes it impossible to use any blockable locking inside the callback *cb*.

## SEE ALSO

[close(2)](/close/2.md), [open(2)](/open/2.md), [devfs(4)](/devfs/4.md)

## HISTORY

The **devfs\_cdevpriv**() family of functions first appeared in FreeBSD 7.1.
