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