Merge branch 'vendor/LIBRESSL'
[dragonfly.git] / share / man / man9 / make_autoclone_dev.9
1 .\"
2 .\" Copyright (c) 2009
3 .\"     The DragonFly Project.  All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\"
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in
13 .\"    the documentation and/or other materials provided with the
14 .\"    distribution.
15 .\" 3. Neither the name of The DragonFly Project nor the names of its
16 .\"    contributors may be used to endorse or promote products derived
17 .\"    from this software without specific, prior written permission.
18 .\"
19 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
23 .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 .\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .Dd December 2, 2012
33 .Dt MAKE_AUTOCLONE_DEV 9
34 .Os
35 .Sh NAME
36 .Nm make_autoclone_dev ,
37 .Nm destroy_autoclone_dev ,
38 .Nm devfs_clone_bitmap_init ,
39 .Nm devfs_clone_bitmap_uninit ,
40 .Nm devfs_clone_bitmap_fff ,
41 .Nm devfs_clone_bitmap_chk ,
42 .Nm devfs_clone_bitmap_set ,
43 .Nm devfs_clone_bitmap_get ,
44 .Nm devfs_clone_bitmap_put ,
45 .Nm DEVFS_DECLARE_CLONE_BITMAP ,
46 .Nm DEVFS_DEFINE_CLONE_BITMAP ,
47 .Nm DEVFS_CLONE_BITMAP
48 .Nd device clone functions
49 .Sh SYNOPSIS
50 .In sys/types.h
51 .In sys/conf.h
52 .In sys/devfs.h
53 .Ft cdev_t
54 .Fn make_autoclone_dev "struct dev_ops *ops" "struct devfs_bitmap *bitmap" "d_clone_t *nhandler" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" "..."
55 .Ft void
56 .Fn destroy_autoclone_dev "cdev_t dev" "struct devfs_bitmap *bitmap"
57 .Ft void
58 .Fn devfs_clone_bitmap_init "struct devfs_bitmap *bitmap"
59 .Ft void
60 .Fn devfs_clone_bitmap_uninit "struct devfs_bitmap *bitmap"
61 .Ft int
62 .Fn devfs_clone_bitmap_fff "struct devfs_bitmap *bitmap"
63 .Ft int
64 .Fn devfs_clone_bitmap_chk "struct devfs_bitmap *bitmap" "int unit"
65 .Ft void
66 .Fn devfs_clone_bitmap_set "struct devfs_bitmap *bitmap" "int unit"
67 .Ft int
68 .Fn devfs_clone_bitmap_get "struct devfs_bitmap *bitmap" "int limit"
69 .Ft void
70 .Fn devfs_clone_bitmap_put "struct devfs_bitmap *bitmap" "int unit"
71 .Fn DEVFS_DECLARE_CLONE_BITMAP "name"
72 .Fn DEVFS_DEFINE_CLONE_BITMAP "name"
73 .Fn DEVFS_CLONE_BITMAP "name"
74 .Sh DESCRIPTION
75 .Fn make_autoclone_dev
76 creates a
77 .Vt cdev_t
78 with the default
79 .Fa ops ,
80 visible in the
81 .Xr devfs 5
82 namespace, that (when opened) will invoke the clone handler specified by
83 .Fa nhandler .
84 If a
85 .Vt devfs_bitmap *
86 is specified, the given
87 .Fa bitmap
88 is initialized using
89 .Fn devfs_clone_bitmap_init .
90 .Pp
91 The clone handler must be defined as follows:
92 .Bd -literal
93 d_clone_t mydev_clone;
94
95 int
96 mydev_clone(struct dev_clone_args *ap)
97 {
98 };
99 .Ed
100 .Pp
101 When called, the handler is passed a pointer to a populated
102 .Vt dev_clone_args
103 structure, which is defined as follows:
104 .Bd -literal
105 struct dev_clone_args {
106         struct dev_generic_args a_head;
107         struct cdev     *a_dev;
108         const char      *a_name;
109         size_t           a_namelen;
110         struct ucred    *a_cred;
111         int              a_mode;
112 };
113 .Ed
114 .Pp
115 .Fa a_head.a_dev
116 is the
117 .Vt cdev_t
118 of the accessed autoclone device.
119 .Fa a_name
120 and
121 .Fa a_namelen
122 are the registered clonable base name and its length, as specified to
123 .Fn make_autoclone_dev .
124 .Fa a_mode
125 and
126 .Fa a_cred
127 contain the mode and cred passed to the autoclone device's
128 .Fn open .
129 .Pp
130 The clone handler must set
131 .Fa a_dev
132 to a new
133 .Vt cdev_t ,
134 returned by a call to
135 .Fn make_only_dev .
136 .Fa a_dev
137 may also be set to
138 .Dv NULL ,
139 in which case the
140 .Fn open
141 will ultimately fail with
142 .Er ENXIO .
143 If
144 .Fa a_dev
145 is
146 .Pf non- Ns Dv NULL ,
147 it is automatically made visible and linked into
148 .Xr devfs 5
149 as if it was created with
150 .Fn make_dev .
151 Thus,
152 .Fn destroy_dev
153 should be used to destroy the cloned
154 .Vt cdev_t
155 once it is no longer required,
156 usually during
157 .Fn close .
158 .Pp
159 .Fn destroy_autoclone_dev
160 destroys a
161 .Vt cdev_t
162 created by
163 .Fn make_autoclone_dev
164 unregistering its clone handler and (if non-NULL) also uninitializes its
165 .Fa bitmap
166 using
167 .Fn devfs_clone_bitmap_uninit .
168 .Pp
169 .Fn devfs_clone_bitmap_init
170 initializes the given clone
171 .Fa bitmap
172 so it is ready to use.
173 .Pp
174 .Fn devfs_clone_bitmap_uninit
175 frees the memory associated with the specified clone
176 .Fa bitmap
177 and leaves it unusable.
178 .Pp
179 .Fn devfs_clone_bitmap_fff
180 returns the first unused unit in
181 .Fa bitmap .
182 To use this unit, it has to be acquired by a call to
183 .Fn devfs_clone_bitmap_set .
184 .Pp
185 .Fn devfs_clone_bitmap_chk
186 checks if
187 .Fa unit
188 is in use (set) and returns 1 if it is; otherwise 0 is returned.
189 .Pp
190 .Fn devfs_clone_bitmap_set
191 marks
192 .Fa unit
193 in
194 .Fa bitmap
195 as used, so further calls to
196 .Fn devfs_clone_bitmap_fff
197 or
198 .Fn devfs_clone_bitmap_get
199 cannot retrieve it.
200 If one intends to use a clone handler along with preallocated devices, it
201 is recommended to block the unit numbers of the preallocated devices by
202 calling
203 .Fn devfs_clone_bitmap_set
204 on them.
205 .Pp
206 .Fn devfs_clone_bitmap_put
207 marks
208 .Fa unit
209 in the
210 .Fa bitmap
211 as unused so further calls to
212 .Fn devfs_clone_bitmap_fff
213 or
214 .Fn devfs_clone_bitmap_get
215 can retrieve it again.
216 .Pp
217 .Fn devfs_clone_bitmap_get
218 is a shortcut to
219 .Fn devfs_clone_bitmap_fff
220 and
221 .Fn devfs_clone_bitmap_set .
222 It will return the first unused unit number and also mark it as used.
223 .Pp
224 The
225 .Fn DEVFS_DEFINE_CLONE_BITMAP
226 macro defines a clone bitmap with the specified
227 .Fa name .
228 As long as the name specified is unique, this macro can be used to define
229 global variables.
230 Similarly,
231 .Fn DEVFS_DECLARE_CLONE_BITMAP
232 declares a clone bitmap.
233 .Pp
234 The
235 .Fn DEVFS_CLONE_BITMAP
236 is a macro which expands the specified
237 .Fa name
238 to the full name of a clone bitmap.
239 It is used in conjunction with
240 .Fn DEVFS_DEFINE_CLONE_BITMAP
241 and
242 .Fn DEVFS_DECLARE_CLONE_BITMAP ,
243 as it uses the same name.
244 .Sh HISTORY
245 The
246 .Xr devfs 5
247 clone facilities and the associated functions all appeared in
248 .Dx 2.3 .
249 .Sh AUTHOR
250 .An Alex Hornung