make_autoclone_dev.9: Improve some description and markups
[dragonfly.git] / share / man / man9 / make_autoclone_dev.9
CommitLineData
2c8ac1b3
SW
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.\"
ec90fa66 32.Dd June 30, 2020
2c8ac1b3 33.Dt MAKE_AUTOCLONE_DEV 9
fb5b3747 34.Os
2c8ac1b3
SW
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 ,
2c8ac1b3
SW
40.Nm devfs_clone_bitmap_chk ,
41.Nm devfs_clone_bitmap_set ,
2c8ac1b3
SW
42.Nm devfs_clone_bitmap_get ,
43.Nm devfs_clone_bitmap_put ,
44.Nm DEVFS_DECLARE_CLONE_BITMAP ,
0cf7fc2c 45.Nm DEVFS_DEFINE_CLONE_BITMAP ,
2c8ac1b3
SW
46.Nm DEVFS_CLONE_BITMAP
47.Nd device clone functions
48.Sh SYNOPSIS
49.In sys/types.h
50.In sys/conf.h
51.In sys/devfs.h
52.Ft cdev_t
4aff68f4 53.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" "..."
2c8ac1b3
SW
54.Ft void
55.Fn destroy_autoclone_dev "cdev_t dev" "struct devfs_bitmap *bitmap"
56.Ft void
57.Fn devfs_clone_bitmap_init "struct devfs_bitmap *bitmap"
58.Ft void
59.Fn devfs_clone_bitmap_uninit "struct devfs_bitmap *bitmap"
7d807da9 60.Ft int
4aff68f4 61.Fn devfs_clone_bitmap_chk "struct devfs_bitmap *bitmap" "int unit"
cbaf7dd9 62.Ft int
4aff68f4 63.Fn devfs_clone_bitmap_set "struct devfs_bitmap *bitmap" "int unit"
2c8ac1b3 64.Ft int
4aff68f4 65.Fn devfs_clone_bitmap_get "struct devfs_bitmap *bitmap" "int limit"
2c8ac1b3 66.Ft void
4aff68f4 67.Fn devfs_clone_bitmap_put "struct devfs_bitmap *bitmap" "int unit"
2c8ac1b3 68.Fn DEVFS_DECLARE_CLONE_BITMAP "name"
0cf7fc2c 69.Fn DEVFS_DEFINE_CLONE_BITMAP "name"
2c8ac1b3
SW
70.Fn DEVFS_CLONE_BITMAP "name"
71.Sh DESCRIPTION
72.Fn make_autoclone_dev
73creates a
74.Vt cdev_t
75with the default
76.Fa ops ,
77visible in the
78.Xr devfs 5
ec90fa66
AL
79namespace, that will invoke the clone handler specified by
80.Fa nhandler
81when it is opened.
82If the
2c8ac1b3 83.Fa bitmap
ec90fa66 84argument is specified, it will be initialized using
2c8ac1b3
SW
85.Fn devfs_clone_bitmap_init .
86.Pp
87The clone handler must be defined as follows:
ec90fa66 88.Bd -literal -offset indent
2c8ac1b3
SW
89d_clone_t mydev_clone;
90
91int
92mydev_clone(struct dev_clone_args *ap)
93{
94};
95.Ed
96.Pp
97When called, the handler is passed a pointer to a populated
98.Vt dev_clone_args
99structure, which is defined as follows:
ec90fa66 100.Bd -literal -offset indent
2c8ac1b3
SW
101struct dev_clone_args {
102 struct dev_generic_args a_head;
103 struct cdev *a_dev;
104 const char *a_name;
105 size_t a_namelen;
106 struct ucred *a_cred;
107 int a_mode;
108};
109.Ed
110.Pp
ec90fa66 111The
2c8ac1b3
SW
112.Fa a_head.a_dev
113is the
114.Vt cdev_t
115of the accessed autoclone device.
ec90fa66 116The
2c8ac1b3
SW
117.Fa a_name
118and
119.Fa a_namelen
120are the registered clonable base name and its length, as specified to
121.Fn make_autoclone_dev .
ec90fa66 122The
2c8ac1b3
SW
123.Fa a_mode
124and
125.Fa a_cred
ec90fa66
AL
126contain the mode and credential passed to the
127.Fn open
128of the autoclone device.
2c8ac1b3 129.Pp
ec90fa66 130The clone handler must set
2c8ac1b3
SW
131.Fa a_dev
132to a new
ec90fa66
AL
133.Vt cdev_t
134that is returned by a call to
2c8ac1b3 135.Fn make_only_dev .
ec90fa66
AL
136The new
137.Vt cdev_t
138will be automatically made visible and linked into
2c8ac1b3 139.Xr devfs 5
ec90fa66 140namespace, as if it was created with
2c8ac1b3
SW
141.Fn make_dev .
142Thus,
143.Fn destroy_dev
144should be used to destroy the cloned
145.Vt cdev_t
146once it is no longer required,
147usually during
148.Fn close .
149.Pp
150.Fn destroy_autoclone_dev
151destroys a
152.Vt cdev_t
153created by
154.Fn make_autoclone_dev
155unregistering its clone handler and (if non-NULL) also uninitializes its
156.Fa bitmap
157using
158.Fn devfs_clone_bitmap_uninit .
159.Pp
160.Fn devfs_clone_bitmap_init
161initializes the given clone
162.Fa bitmap
163so it is ready to use.
164.Pp
165.Fn devfs_clone_bitmap_uninit
166frees the memory associated with the specified clone
167.Fa bitmap
168and leaves it unusable.
169.Pp
2c8ac1b3
SW
170.Fn devfs_clone_bitmap_chk
171checks if
172.Fa unit
173is in use (set) and returns 1 if it is; otherwise 0 is returned.
174.Pp
175.Fn devfs_clone_bitmap_set
176marks
177.Fa unit
d7e26e2b 178in the
2c8ac1b3
SW
179.Fa bitmap
180as used, so further calls to
2c8ac1b3
SW
181.Fn devfs_clone_bitmap_get
182cannot retrieve it.
d7e26e2b 183The function returns -1 if the unit is already allocated, otherwise 0.
2c8ac1b3
SW
184If one intends to use a clone handler along with preallocated devices, it
185is recommended to block the unit numbers of the preallocated devices by
186calling
187.Fn devfs_clone_bitmap_set
188on them.
189.Pp
3dde3292
AL
190.Fn devfs_clone_bitmap_get
191will return the first unused unit number and also mark it as used
192in the
193.Fa bitmap .
194If the
195.Fa limit
196argument is greater than 0, the requested unit number cannot be greater
197than the given
198.Fa limit .
199The function returns -1 if no more units are available.
200.Pp
5fccb22f 201.Fn devfs_clone_bitmap_put
2c8ac1b3
SW
202marks
203.Fa unit
204in the
205.Fa bitmap
206as unused so further calls to
2c8ac1b3
SW
207.Fn devfs_clone_bitmap_get
208can retrieve it again.
b0564672
MD
209It is recommended that the associated device be destroyed prior to
210making the
211.Fa unit
212available in the bitmap again, to avoid racing against a new clone.
2c8ac1b3 213.Pp
2c8ac1b3 214The
0cf7fc2c
SW
215.Fn DEVFS_DEFINE_CLONE_BITMAP
216macro defines a clone bitmap with the specified
2c8ac1b3 217.Fa name .
0cf7fc2c 218As long as the name specified is unique, this macro can be used to define
2c8ac1b3 219global variables.
0cf7fc2c
SW
220Similarly,
221.Fn DEVFS_DECLARE_CLONE_BITMAP
222declares a clone bitmap.
2c8ac1b3
SW
223.Pp
224The
225.Fn DEVFS_CLONE_BITMAP
226is a macro which expands the specified
227.Fa name
228to the full name of a clone bitmap.
229It is used in conjunction with
0cf7fc2c
SW
230.Fn DEVFS_DEFINE_CLONE_BITMAP
231and
2c8ac1b3
SW
232.Fn DEVFS_DECLARE_CLONE_BITMAP ,
233as it uses the same name.
d7e26e2b
AL
234.Sh SEE ALSO
235.Xr devfs 5 ,
236.Xr destroy_dev 9 ,
237.Xr make_dev 9 ,
238.Xr make_only_dev 9
2c8ac1b3
SW
239.Sh HISTORY
240The
241.Xr devfs 5
242clone facilities and the associated functions all appeared in
243.Dx 2.3 .
831fa461 244.Sh AUTHORS
2c8ac1b3 245.An Alex Hornung