1630f2c3bSKonstantin Belousov.\" Copyright (c) 2008 Konstantin Belousov 2630f2c3bSKonstantin Belousov.\" All rights reserved. 3630f2c3bSKonstantin Belousov.\" 4630f2c3bSKonstantin Belousov.\" Redistribution and use in source and binary forms, with or without 5630f2c3bSKonstantin Belousov.\" modification, are permitted provided that the following conditions 6630f2c3bSKonstantin Belousov.\" are met: 7630f2c3bSKonstantin Belousov.\" 1. Redistributions of source code must retain the above copyright 8630f2c3bSKonstantin Belousov.\" notice, this list of conditions and the following disclaimer. 9630f2c3bSKonstantin Belousov.\" 2. Redistributions in binary form must reproduce the above copyright 10630f2c3bSKonstantin Belousov.\" notice, this list of conditions and the following disclaimer in the 11630f2c3bSKonstantin Belousov.\" documentation and/or other materials provided with the distribution. 12630f2c3bSKonstantin Belousov.\" 13630f2c3bSKonstantin Belousov.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14630f2c3bSKonstantin Belousov.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15630f2c3bSKonstantin Belousov.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16630f2c3bSKonstantin Belousov.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17630f2c3bSKonstantin Belousov.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18630f2c3bSKonstantin Belousov.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19630f2c3bSKonstantin Belousov.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20630f2c3bSKonstantin Belousov.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21630f2c3bSKonstantin Belousov.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22630f2c3bSKonstantin Belousov.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23630f2c3bSKonstantin Belousov.\" SUCH DAMAGE. 24630f2c3bSKonstantin Belousov.\" 2588f2c58dSKonstantin Belousov.Dd March 23, 2024 26a6d11f71SRuslan Ermilov.Dt DEVFS_CDEVPRIV 9 27aa12cea2SUlrich Spörlein.Os 28630f2c3bSKonstantin Belousov.Sh NAME 29630f2c3bSKonstantin Belousov.Nm devfs_set_cdevpriv , 30630f2c3bSKonstantin Belousov.Nm devfs_get_cdevpriv , 3188f2c58dSKonstantin Belousov.Nm devfs_clear_cdevpriv , 3288f2c58dSKonstantin Belousov.Nm devfs_foreach_cdevpriv 33630f2c3bSKonstantin Belousov.Nd manage per-open filedescriptor data for devices 34630f2c3bSKonstantin Belousov.Sh SYNOPSIS 35630f2c3bSKonstantin Belousov.In sys/param.h 36630f2c3bSKonstantin Belousov.In sys/conf.h 37630f2c3bSKonstantin Belousov.Bd -literal 388d7e0f58SJohn Baldwintypedef void d_priv_dtor_t(void *data); 39630f2c3bSKonstantin Belousov.Ed 40630f2c3bSKonstantin Belousov.Ft int 416da593a2SEd Schouten.Fn devfs_get_cdevpriv "void **datap" 42630f2c3bSKonstantin Belousov.Ft int 438d7e0f58SJohn Baldwin.Fn devfs_set_cdevpriv "void *priv" "d_priv_dtor_t *dtr" 44630f2c3bSKonstantin Belousov.Ft void 45630f2c3bSKonstantin Belousov.Fn devfs_clear_cdevpriv "void" 4688f2c58dSKonstantin Belousov.Ft int 4788f2c58dSKonstantin Belousov.Fo devfs_foreach_cdevpriv 4888f2c58dSKonstantin Belousov.Fa "struct cdev *dev" 4988f2c58dSKonstantin Belousov.Fa "int (*cb)(void *data, void *arg)" 5088f2c58dSKonstantin Belousov.Fa "void *arg" 5188f2c58dSKonstantin Belousov.Fc 52630f2c3bSKonstantin Belousov.Sh DESCRIPTION 53630f2c3bSKonstantin BelousovThe 54630f2c3bSKonstantin Belousov.Fn devfs_xxx_cdevpriv 55630f2c3bSKonstantin Belousovfamily of functions allows the 56630f2c3bSKonstantin Belousov.Fa cdev 57630f2c3bSKonstantin Belousovdriver methods to associate some driver-specific data with each 58630f2c3bSKonstantin Belousovuser process 59630f2c3bSKonstantin Belousov.Xr open 2 60630f2c3bSKonstantin Belousovof the device special file. 61630f2c3bSKonstantin BelousovCurrently, functioning of these functions is restricted to the context 62630f2c3bSKonstantin Belousovof the 63630f2c3bSKonstantin Belousov.Fa cdevsw 64630f2c3bSKonstantin Belousovswitch method calls performed as 65*1a720cbeSAlexander Ziaee.Xr devfs 4 66630f2c3bSKonstantin Belousovoperations in response to system calls that use filedescriptors. 67630f2c3bSKonstantin Belousov.Pp 68630f2c3bSKonstantin BelousovThe 69630f2c3bSKonstantin Belousov.Fn devfs_set_cdevpriv 70630f2c3bSKonstantin Belousovfunction associates a data pointed by 71630f2c3bSKonstantin Belousov.Va priv 72630f2c3bSKonstantin Belousovwith current calling context (filedescriptor). 73630f2c3bSKonstantin BelousovThe data may be retrieved later, possibly from another call 74630f2c3bSKonstantin Belousovperformed on this filedescriptor, by the 75630f2c3bSKonstantin Belousov.Fn devfs_get_cdevpriv 76630f2c3bSKonstantin Belousovfunction. 77630f2c3bSKonstantin BelousovThe 78630f2c3bSKonstantin Belousov.Fn devfs_clear_cdevpriv 79630f2c3bSKonstantin Belousovdisassociates previously attached data from context. 80630f2c3bSKonstantin BelousovImmediately after 81630f2c3bSKonstantin Belousov.Fn devfs_clear_cdevpriv 82630f2c3bSKonstantin Belousovfinished operating, the 83630f2c3bSKonstantin Belousov.Va dtr 84630f2c3bSKonstantin Belousovcallback is called, with private data supplied 85630f2c3bSKonstantin Belousov.Va data 86630f2c3bSKonstantin Belousovargument. 8707da61a6SHans Petter SelaskyThe 8807da61a6SHans Petter Selasky.Fn devfs_clear_cdevpriv 8907da61a6SHans Petter Selaskyfunction will be also be called if the open callback 9007da61a6SHans Petter Selaskyfunction returns an error code. 91630f2c3bSKonstantin Belousov.Pp 92630f2c3bSKonstantin BelousovOn the last filedescriptor close, system automatically arranges 93630f2c3bSKonstantin Belousov.Fn devfs_clear_cdevpriv 94630f2c3bSKonstantin Belousovcall. 95630f2c3bSKonstantin Belousov.Pp 96630f2c3bSKonstantin BelousovIf successful, the functions return 0. 97630f2c3bSKonstantin Belousov.Pp 98630f2c3bSKonstantin BelousovThe function 99630f2c3bSKonstantin Belousov.Fn devfs_set_cdevpriv 100630f2c3bSKonstantin Belousovreturns the following values on error: 101630f2c3bSKonstantin Belousov.Bl -tag -width Er 102630f2c3bSKonstantin Belousov.It Bq Er ENOENT 103630f2c3bSKonstantin BelousovThe current call is not associated with some filedescriptor. 104630f2c3bSKonstantin Belousov.It Bq Er EBUSY 105630f2c3bSKonstantin BelousovThe private driver data is already associated with current 106630f2c3bSKonstantin Belousovfiledescriptor. 107630f2c3bSKonstantin Belousov.El 108630f2c3bSKonstantin Belousov.Pp 109630f2c3bSKonstantin BelousovThe function 110630f2c3bSKonstantin Belousov.Fn devfs_get_cdevpriv 111630f2c3bSKonstantin Belousovreturns the following values on error: 112630f2c3bSKonstantin Belousov.Bl -tag -width Er 113630f2c3bSKonstantin Belousov.It Bq Er EBADF 114630f2c3bSKonstantin BelousovThe current call is not associated with some filedescriptor. 115630f2c3bSKonstantin Belousov.It Bq Er ENOENT 116630f2c3bSKonstantin BelousovThe private driver data was not associated with current 117630f2c3bSKonstantin Belousovfiledescriptor, or 118630f2c3bSKonstantin Belousov.Fn devfs_clear_cdevpriv 119630f2c3bSKonstantin Belousovwas called. 1200a431e07SXin LI.El 12188f2c58dSKonstantin Belousov.Pp 12288f2c58dSKonstantin BelousovThe function 12388f2c58dSKonstantin Belousov.Fn devfs_foreach_cdevpriv 12488f2c58dSKonstantin Belousovsequentially calls the function 12588f2c58dSKonstantin Belousov.Fa cb 12688f2c58dSKonstantin Belousovfor each 12788f2c58dSKonstantin Belousov.Nm cdevpriv 12888f2c58dSKonstantin Belousovstructure, currently associated with the 12988f2c58dSKonstantin Belousov.Fa cdev 13088f2c58dSKonstantin Belousovdevice. 13188f2c58dSKonstantin BelousovThe iterated 13288f2c58dSKonstantin Belousov.Nm cdevpriv 13388f2c58dSKonstantin Belousovdata pointer and the user-supplied context 13488f2c58dSKonstantin Belousov.Fa arg 13588f2c58dSKonstantin Belousovare passed to the function 13688f2c58dSKonstantin Belousov.Fa cb . 13788f2c58dSKonstantin BelousovIf 13888f2c58dSKonstantin Belousov.Fa cb 13988f2c58dSKonstantin Belousovreturns non-zero value, the iteration stops on that element. 14088f2c58dSKonstantin BelousovThe 14188f2c58dSKonstantin Belousov.Fn devfs_foreach_cdevpriv 14288f2c58dSKonstantin Belousovreturns the return value from the last call to 14388f2c58dSKonstantin Belousov.Fa cb , 14488f2c58dSKonstantin Belousovor zero if no 14588f2c58dSKonstantin Belousov.Nm cdevpriv 14688f2c58dSKonstantin Belousovdata is currently associated with the device. 14788f2c58dSKonstantin Belousov.Pp 14888f2c58dSKonstantin BelousovCurrent implementation of the iterator makes it impossible to use 14988f2c58dSKonstantin Belousovany blockable locking inside the callback 15088f2c58dSKonstantin Belousov.Fa cb . 151630f2c3bSKonstantin Belousov.Sh SEE ALSO 152630f2c3bSKonstantin Belousov.Xr close 2 , 1531e9469d1SChristian Brueffer.Xr open 2 , 154*1a720cbeSAlexander Ziaee.Xr devfs 4 155630f2c3bSKonstantin Belousov.Sh HISTORY 156630f2c3bSKonstantin BelousovThe 157630f2c3bSKonstantin Belousov.Fn devfs_cdevpriv 158630f2c3bSKonstantin Belousovfamily of functions first appeared in 159630f2c3bSKonstantin Belousov.Fx 7.1 . 160