xref: /freebsd/share/man/man9/devfs_set_cdevpriv.9 (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
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.Dd December 2, 2015
26.Dt DEVFS_CDEVPRIV 9
27.Os
28.Sh NAME
29.Nm devfs_set_cdevpriv ,
30.Nm devfs_get_cdevpriv ,
31.Nm devfs_clear_cdevpriv
32.Nd manage per-open filedescriptor data for devices
33.Sh SYNOPSIS
34.In sys/param.h
35.In sys/conf.h
36.Bd -literal
37typedef	void d_priv_dtor_t(void *data);
38.Ed
39.Ft int
40.Fn devfs_get_cdevpriv "void **datap"
41.Ft int
42.Fn devfs_set_cdevpriv "void *priv" "d_priv_dtor_t *dtr"
43.Ft void
44.Fn devfs_clear_cdevpriv "void"
45.Sh DESCRIPTION
46The
47.Fn devfs_xxx_cdevpriv
48family of functions allows the
49.Fa cdev
50driver methods to associate some driver-specific data with each
51user process
52.Xr open 2
53of the device special file.
54Currently, functioning of these functions is restricted to the context
55of the
56.Fa cdevsw
57switch method calls performed as
58.Xr devfs 5
59operations in response to system calls that use filedescriptors.
60.Pp
61The
62.Fn devfs_set_cdevpriv
63function associates a data pointed by
64.Va priv
65with current calling context (filedescriptor).
66The data may be retrieved later, possibly from another call
67performed on this filedescriptor, by the
68.Fn devfs_get_cdevpriv
69function.
70The
71.Fn devfs_clear_cdevpriv
72disassociates previously attached data from context.
73Immediately after
74.Fn devfs_clear_cdevpriv
75finished operating, the
76.Va dtr
77callback is called, with private data supplied
78.Va data
79argument.
80The
81.Fn devfs_clear_cdevpriv
82function will be also be called if the open callback
83function returns an error code.
84.Pp
85On the last filedescriptor close, system automatically arranges
86.Fn devfs_clear_cdevpriv
87call.
88.Pp
89If successful, the functions return 0.
90.Pp
91The function
92.Fn devfs_set_cdevpriv
93returns the following values on error:
94.Bl -tag -width Er
95.It Bq Er ENOENT
96The current call is not associated with some filedescriptor.
97.It Bq Er EBUSY
98The private driver data is already associated with current
99filedescriptor.
100.El
101.Pp
102The function
103.Fn devfs_get_cdevpriv
104returns the following values on error:
105.Bl -tag -width Er
106.It Bq Er EBADF
107The current call is not associated with some filedescriptor.
108.It Bq Er ENOENT
109The private driver data was not associated with current
110filedescriptor, or
111.Fn devfs_clear_cdevpriv
112was called.
113.El
114.Sh SEE ALSO
115.Xr close 2 ,
116.Xr open 2 ,
117.Xr devfs 5
118.Sh HISTORY
119The
120.Fn devfs_cdevpriv
121family of functions first appeared in
122.Fx 7.1 .
123