]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - share/man/man9/devfs_set_cdevpriv.9
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / share / man / man9 / devfs_set_cdevpriv.9
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 August 15, 2012
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
39 typedef 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
48 The
49 .Fn devfs_xxx_cdevpriv
50 family of functions allows the
51 .Fa cdev
52 driver methods to associate some driver-specific data with each
53 user process
54 .Xr open 2
55 of the device special file.
56 Currently, functioning of these functions is restricted to the context
57 of the
58 .Fa cdevsw
59 switch method calls performed as
60 .Xr devfs 5
61 operations in response to system calls that use filedescriptors.
62 .Pp
63 The
64 .Fn devfs_set_cdevpriv
65 function associates a data pointed by
66 .Va priv
67 with current calling context (filedescriptor).
68 The data may be retrieved later, possibly from another call
69 performed on this filedescriptor, by the
70 .Fn devfs_get_cdevpriv
71 function.
72 The
73 .Fn devfs_clear_cdevpriv
74 disassociates previously attached data from context.
75 Immediately after
76 .Fn devfs_clear_cdevpriv
77 finished operating, the
78 .Va dtr
79 callback is called, with private data supplied
80 .Va data
81 argument.
82 The
83 .Fn devfs_clear_cdevpriv
84 function will be also be called if the open callback
85 function returns an error code.
86 .Pp
87 On the last filedescriptor close, system automatically arranges
88 .Fn devfs_clear_cdevpriv
89 call.
90 .Pp
91 If successful, the functions return 0.
92 .Pp
93 The function
94 .Fn devfs_set_cdevpriv
95 returns the following values on error:
96 .Bl -tag -width Er
97 .It Bq Er ENOENT
98 The current call is not associated with some filedescriptor.
99 .It Bq Er EBUSY
100 The private driver data is already associated with current
101 filedescriptor.
102 .El
103 .Pp
104 The function
105 .Fn devfs_get_cdevpriv
106 returns the following values on error:
107 .Bl -tag -width Er
108 .It Bq Er EBADF
109 The current call is not associated with some filedescriptor.
110 .It Bq Er ENOENT
111 The private driver data was not associated with current
112 filedescriptor, or
113 .Fn devfs_clear_cdevpriv
114 was called.
115 .El
116 .Sh SEE ALSO
117 .Xr open 2 ,
118 .Xr close 2 ,
119 .Xr devfs 5 ,
120 .Xr kern_openat 9
121 .Sh HISTORY
122 The
123 .Fn devfs_cdevpriv
124 family of functions first appeared in
125 .Fx 7.1 .