1*c470a9c0SAaron LI.\" Copyright (c) 2008 Konstantin Belousov 2*c470a9c0SAaron LI.\" All rights reserved. 3*c470a9c0SAaron LI.\" 4*c470a9c0SAaron LI.\" Redistribution and use in source and binary forms, with or without 5*c470a9c0SAaron LI.\" modification, are permitted provided that the following conditions 6*c470a9c0SAaron LI.\" are met: 7*c470a9c0SAaron LI.\" 1. Redistributions of source code must retain the above copyright 8*c470a9c0SAaron LI.\" notice, this list of conditions and the following disclaimer. 9*c470a9c0SAaron LI.\" 2. Redistributions in binary form must reproduce the above copyright 10*c470a9c0SAaron LI.\" notice, this list of conditions and the following disclaimer in the 11*c470a9c0SAaron LI.\" documentation and/or other materials provided with the distribution. 12*c470a9c0SAaron LI.\" 13*c470a9c0SAaron LI.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14*c470a9c0SAaron LI.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*c470a9c0SAaron LI.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*c470a9c0SAaron LI.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17*c470a9c0SAaron LI.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*c470a9c0SAaron LI.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*c470a9c0SAaron LI.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*c470a9c0SAaron LI.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*c470a9c0SAaron LI.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*c470a9c0SAaron LI.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*c470a9c0SAaron LI.\" SUCH DAMAGE. 24*c470a9c0SAaron LI.\" 25*c470a9c0SAaron LI.\" $FreeBSD: head/share/man/man9/devfs_set_cdevpriv.9 291653 2015-12-02 18:27:30Z jhb $ 26*c470a9c0SAaron LI.\" 27*c470a9c0SAaron LI.Dd May 25, 2021 28*c470a9c0SAaron LI.Dt DEVFS_SET_CDEVPRIV 9 29*c470a9c0SAaron LI.Os 30*c470a9c0SAaron LI.Sh NAME 31*c470a9c0SAaron LI.Nm devfs_set_cdevpriv , 32*c470a9c0SAaron LI.Nm devfs_get_cdevpriv , 33*c470a9c0SAaron LI.Nm devfs_clear_cdevpriv 34*c470a9c0SAaron LI.Nd manage per-open filedescriptor data for devices 35*c470a9c0SAaron LI.Sh SYNOPSIS 36*c470a9c0SAaron LI.In sys/devfs.h 37*c470a9c0SAaron LI.Bd -literal 38*c470a9c0SAaron LItypedef void d_priv_dtor_t(void *data); 39*c470a9c0SAaron LI.Ed 40*c470a9c0SAaron LI.Ft int 41*c470a9c0SAaron LI.Fn devfs_set_cdevpriv "struct file *fp" "void *priv" "d_priv_dtor_t *dtr" 42*c470a9c0SAaron LI.Ft int 43*c470a9c0SAaron LI.Fn devfs_get_cdevpriv "struct file *fp" "void **datap" 44*c470a9c0SAaron LI.Ft void 45*c470a9c0SAaron LI.Fn devfs_clear_cdevpriv "struct file *fp" 46*c470a9c0SAaron LI.Sh DESCRIPTION 47*c470a9c0SAaron LIThe 48*c470a9c0SAaron LI.Fn devfs_xxx_cdevpriv 49*c470a9c0SAaron LIfamily of functions allows the device driver methods to associate some 50*c470a9c0SAaron LIdriver-specific data with each user process 51*c470a9c0SAaron LI.Xr open 2 52*c470a9c0SAaron LIof the device special file. 53*c470a9c0SAaron LICurrently, functioning of these functions is restricted to the context 54*c470a9c0SAaron LIof the 55*c470a9c0SAaron LI.Vt dev_ops 56*c470a9c0SAaron LIswitch method calls performed as 57*c470a9c0SAaron LI.Xr devfs 5 58*c470a9c0SAaron LIoperations in response to system calls that use file descriptors. 59*c470a9c0SAaron LI.Pp 60*c470a9c0SAaron LIThe 61*c470a9c0SAaron LI.Fn devfs_set_cdevpriv 62*c470a9c0SAaron LIfunction associates a data pointed by 63*c470a9c0SAaron LI.Fa priv 64*c470a9c0SAaron LIwith the calling context (file descriptor) specified by 65*c470a9c0SAaron LI.Fa fp . 66*c470a9c0SAaron LIThe data may be retrieved later by 67*c470a9c0SAaron LI.Fn devfs_get_cdevpriv , 68*c470a9c0SAaron LIpossibly from another call 69*c470a9c0SAaron LIperformed on this file descriptor. 70*c470a9c0SAaron LI.Pp 71*c470a9c0SAaron LIThe 72*c470a9c0SAaron LI.Fn devfs_clear_cdevpriv 73*c470a9c0SAaron LIfunction disassociates the previously attached data from the 74*c470a9c0SAaron LIcontext specified by 75*c470a9c0SAaron LI.Fa fp . 76*c470a9c0SAaron LIAt the end of 77*c470a9c0SAaron LI.Fn devfs_clear_cdevpriv 78*c470a9c0SAaron LIoperation, the previously associated 79*c470a9c0SAaron LI.Fa dtr 80*c470a9c0SAaron LIcallback is called, with private data supplied its 81*c470a9c0SAaron LI.Fa data 82*c470a9c0SAaron LIargument. 83*c470a9c0SAaron LIThe 84*c470a9c0SAaron LI.Fn devfs_clear_cdevpriv 85*c470a9c0SAaron LIfunction will be automatically called upon the 86*c470a9c0SAaron LI.Xr close 2 87*c470a9c0SAaron LIof the file descriptor. 88*c470a9c0SAaron LI.Sh RETURN VALUES 89*c470a9c0SAaron LIIf successful, the functions return 0. 90*c470a9c0SAaron LI.Pp 91*c470a9c0SAaron LIThe function 92*c470a9c0SAaron LI.Fn devfs_set_cdevpriv 93*c470a9c0SAaron LIreturns the following values on error: 94*c470a9c0SAaron LI.Bl -tag -width Er 95*c470a9c0SAaron LI.It Bq Er ENOENT 96*c470a9c0SAaron LIThe passed 97*c470a9c0SAaron LI.Fa fp 98*c470a9c0SAaron LIargument is 99*c470a9c0SAaron LI.Va NULL . 100*c470a9c0SAaron LI.It Bq Er EBUSY 101*c470a9c0SAaron LIThe private driver data is already associated with the given 102*c470a9c0SAaron LI.Fa fp . 103*c470a9c0SAaron LI.El 104*c470a9c0SAaron LI.Pp 105*c470a9c0SAaron LIThe function 106*c470a9c0SAaron LI.Fn devfs_get_cdevpriv 107*c470a9c0SAaron LIreturns the following values on error: 108*c470a9c0SAaron LI.Bl -tag -width Er 109*c470a9c0SAaron LI.It Bq Er EBADF 110*c470a9c0SAaron LIThe passed 111*c470a9c0SAaron LI.Fa fp 112*c470a9c0SAaron LIargument is 113*c470a9c0SAaron LI.Va NULL . 114*c470a9c0SAaron LI.It Bq Er ENOENT 115*c470a9c0SAaron LIThe private driver data was not associated with the given 116*c470a9c0SAaron LI.Fa fp , 117*c470a9c0SAaron LIor 118*c470a9c0SAaron LI.Fn devfs_clear_cdevpriv 119*c470a9c0SAaron LIwas called. 120*c470a9c0SAaron LI.El 121*c470a9c0SAaron LI.Sh SEE ALSO 122*c470a9c0SAaron LI.Xr close 2 , 123*c470a9c0SAaron LI.Xr open 2 , 124*c470a9c0SAaron LI.Xr devfs 5 125*c470a9c0SAaron LI.Sh HISTORY 126*c470a9c0SAaron LIThe 127*c470a9c0SAaron LI.Fn devfs_xxx_cdevpriv 128*c470a9c0SAaron LIfamily of functions first appeared in 129*c470a9c0SAaron LI.Fx 7.1 , 130*c470a9c0SAaron LIand was implemented in 131*c470a9c0SAaron LI.Dx 3.8 . 132