DEVFS_CDEVPRIV(9)
π DEVFS_CDEVPRIV β the devfs_cdevpriv trilogy π
okay bestie, so this is DEVFS_CDEVPRIV(9) from the Kernel Developer's Manual, and it's literally about giving each open file descriptor of a device its own lil personal stash of data. no cap. let's get into it π«Ά
β¨ NAME β¨
devfs_set_cdevpriv, devfs_get_cdevpriv, devfs_clear_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);
π¦ DESCRIPTION π¦
so the devfs_xxx_cdevpriv() family of functions lets a cdev driver's methods attach some driver-specific data to each user open(2) of the device special file. like, one blob of vibes per open, yk? π
rn, these functions only work in the context of thecdevswswitch method calls that get performed asdevfs(5)operations, in response to system calls that use filedescriptors. that's the vibe check. if you're not in that context, it's not giving.
devfs_set_cdevpriv() associates the data pointed to by priv with the current calling context (the filedescriptor). you can grab that data back later with devfs_get_cdevpriv() β possibly from a totally different call made on that same filedescriptor. obsessed with the continuity fr fr β¨
devfs_clear_cdevpriv() disassociates previously attached data from the context. and the moment devfs_clear_cdevpriv() finishes operating, the dtr callback gets called, with the private data passed in as its data argument. also!! devfs_clear_cdevpriv() gets called if the open callback function returns an error code. so like, automatic cleanup, iconic behavior π
and on the last filedescriptor close, the system automatically arranges a devfs_clear_cdevpriv() call. it just handles it. main character energy tbh π
if successful, the functions return 0.
π errors from devfs_set_cdevpriv()
[ENOENT]β the current call is not associated with some filedescriptor. π[EBUSY]β the private driver data is already associated with the current filedescriptor. like girl it's taken!!
π errors from devfs_get_cdevpriv()
[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. gone. vanished. not in the group chat anymore.
π SEE ALSO π
β HISTORY β
the devfs_cdevpriv() family of functions first appeared in FreeBSD 7.1. vintage but make it slay π
π bestie that's the whole page, no notes. this Debian-flavored rendering is dated December 2, 2015, and it lives in the DEVFS_CDEVPRIV(9) section of the Kernel Developer's Manual. mwah πβ¨πΈπ¦π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2008 Konstantin Belousov
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms