xref: /freebsd/share/man/man9/devfs_set_cdevpriv.9 (revision bb15ca603fa442c72dde3f3cb8b46db6970e3950)
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 September 8, 2008
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 (*cdevpriv_dtr_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" "cdevpriv_dtr_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.
82.Pp
83On the last filedescriptor close, system automatically arranges
84.Fn devfs_clear_cdevpriv
85call.
86.Pp
87If successful, the functions return 0.
88.Pp
89The function
90.Fn devfs_set_cdevpriv
91returns the following values on error:
92.Bl -tag -width Er
93.It Bq Er ENOENT
94The current call is not associated with some filedescriptor.
95.It Bq Er EBUSY
96The private driver data is already associated with current
97filedescriptor.
98.El
99.Pp
100The function
101.Fn devfs_get_cdevpriv
102returns the following values on error:
103.Bl -tag -width Er
104.It Bq Er EBADF
105The current call is not associated with some filedescriptor.
106.It Bq Er ENOENT
107The private driver data was not associated with current
108filedescriptor, or
109.Fn devfs_clear_cdevpriv
110was called.
111.El
112.Sh SEE ALSO
113.Xr open 2 ,
114.Xr close 2 ,
115.Xr devfs 5 ,
116.Xr kern_openat 9
117.Sh HISTORY
118The
119.Fn devfs_cdevpriv
120family of functions first appeared in
121.Fx 7.1 .
122