DEVFS_CDEVPRIV(9)
π DEVFS_CDEVPRIV π
okay so this is a page from the Kernel Developer's Manual β section 9, kernel land, bestie. we're talking devfs_set_cdevpriv, devfs_get_cdevpriv, devfs_clear_cdevpriv, and devfs_foreach_cdevpriv β the whole little squad that manages per-open filedescriptor data for devices. it's giving β¨ device driver bookkeeping β¨ and honestly? kind of iconic.
π NAME π
devfs_set_cdevpriv, devfs_get_cdevpriv, devfs_clear_cdevpriv, devfs_foreach_cdevpriv β these four besties literally manage per-open filedescriptor data for devices. that's the whole vibe. no notes. π
πΈ 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);
like, just look at it. the d_priv_dtor_t typedef is a void function taking void *data. she's a destructor. she's a whole vibe. π¦
π DESCRIPTION π
so the devfs_xxx_cdevpriv() family lets your cdev driver methods associate some driver-specific data with each user process open(2) of the device special file. one open = one lil data bundle. that's the entire concept, no cap. π«Ά
lowkey important though: currently, functioning of these functions is restricted to the context of the cdevsw switch method calls performed as devfs(4) operations in response to system calls that use filedescriptors. so like... you can't just call these wherever. vibe check first, okay? π
β¨ what each one does β¨
devfs_set_cdevpriv()β associates data pointed by priv with the current calling context (the filedescriptor). slay. πdevfs_get_cdevpriv()β retrieves that data later, possibly from another call performed on this filedescriptor. she remembers. πdevfs_clear_cdevpriv()β disassociates previously attached data from context. immediately afterdevfs_clear_cdevpriv()finishes operating, the dtr callback is called, with the private data supplied as the data argument. and bestie βdevfs_clear_cdevpriv()will also be called if the open callback function returns an error code. π it's got your back like that.- on the last filedescriptor close, the system automatically arranges a
devfs_clear_cdevpriv()call. no manual cleanup needed. periodt. β¨
π return values π
if successful, the functions return 0. iconic.
devfs_set_cdevpriv() returns these on error:
[ENOENT]β the current call is not associated with some filedescriptor. π[EBUSY]β the private driver data is already associated with the current filedescriptor. girl, it's taken. π
devfs_get_cdevpriv() returns these on error:
[EBADF]β the current call is not associated with some filedescriptor. π[ENOENT]β the private driver data was not associated with the current filedescriptor, ordevfs_clear_cdevpriv()was called. she's gone, babes. π
π devfs_foreach_cdevpriv() π
this one 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 a non-zero value, the iteration stops on that element β like, she's done, thank you. π
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. π
β οΈ real talk warning: the current implementation of the iterator makes it impossible to use any blockable locking inside the callback cb. not "discouraged", not "kinda sketchy" β impossible. do not try it. deadass. π
π¦ SEE ALSO π¦
go read them, iykyk πβ¨
πΈ HISTORY πΈ
the devfs_cdevpriv() family of functions first appeared in FreeBSD 7.1. a vintage. an icon. a legend. π
okay that's the whole page bestie, you're officially educated πβ¨ππ¦ β this masterpiece of a manpage came from the Debian crew, dated March 23, 2024, and it's filed under DEVFS_CDEVPRIV(9). mwah. π
π·
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 2008 Konstantin Belousov
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms