1 .\" Copyright (c) 1999 Chris Costello
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
25 .\" $FreeBSD: src/share/man/man9/make_dev.9,v 1.2.2.3 2001/12/17 11:30:18 ru Exp $
26 .\" $DragonFly: src/share/man/man9/make_dev.9,v 1.3 2006/05/26 19:39:40 swildner Exp $
33 .Nm destroy_all_devs ,
36 .Nm dev_ops_add_override ,
37 .Nm dev_ops_intercept ,
48 .Nd "device entry manipulation functions"
53 .Fn compile_dev_ops "struct dev_ops *ops"
55 .Fn destroy_all_devs "struct dev_ops *ops" "u_int mask" "u_int match"
57 .Fn destroy_dev "cdev_t dev"
59 .Fn dev_ops_add "struct dev_ops *ops" "u_int mask" "u_int match"
61 .Fo dev_ops_add_override
62 .Fa "cdev_t backing_dev"
63 .Fa "struct dev_ops *template"
68 .Fn dev_ops_intercept "cdev_t dev" "struct dev_ops *iops"
70 .Fn dev_ops_release "struct dev_ops *ops"
72 .Fn dev_ops_remove "struct dev_ops *ops" "u_int mask" "u_int match"
74 .Fn dev_ops_restore "cdev_t dev" "struct dev_ops *oops"
76 .Fn dev_ops_scan "int (*callback)(struct dev_ops *, void *)" "void *arg"
78 .Fn get_dev "int x" "int y"
80 .Fn make_dev "struct dev_ops *ops" "int minor" "uid_t uid" "gid_t gid" "int perms" "char *fmt" ...
82 .Fn make_adhoc_dev "struct dev_ops *ops" "int minor"
84 .Fn make_sub_dev "cdev_t odev" "int minor"
86 .Fn reference_dev "cdev_t dev"
88 .Fn release_dev "cdev_t dev"
94 structure for a new device.
95 If an entry already exists, this function will set its cred
96 requirements and name.
97 The device will be owned by
99 with the group ownership as
101 The name is the expansion of
103 and following arguments as
106 The name determines its path under
108 The permissions of the file specified in
113 .Bd -literal -offset indent -compact
114 #define S_IRWXU 0000700 /* RWX mask for owner */
115 #define S_IRUSR 0000400 /* R for owner */
116 #define S_IWUSR 0000200 /* W for owner */
117 #define S_IXUSR 0000100 /* X for owner */
119 #define S_IRWXG 0000070 /* RWX mask for group */
120 #define S_IRGRP 0000040 /* R for group */
121 #define S_IWGRP 0000020 /* W for group */
122 #define S_IXGRP 0000010 /* X for group */
124 #define S_IRWXO 0000007 /* RWX mask for other */
125 #define S_IROTH 0000004 /* R for other */
126 #define S_IWOTH 0000002 /* W for other */
127 #define S_IXOTH 0000001 /* X for other */
129 #define S_ISUID 0004000 /* set user id on execution */
130 #define S_ISGID 0002000 /* set group id on execution */
131 #define S_ISVTX 0001000 /* sticky bit */
132 #ifndef _POSIX_SOURCE
133 #define S_ISTXT 0001000
140 data structure, which is defined as follows:
144 const char *name; /* base name, e.g. 'da' */
145 int maj; /* major device number */
146 u_int flags; /* D_XXX flags */
147 void *data; /* custom driver data */
148 int refs; /* ref count */
151 #define dev_ops_first_field d_default
152 d_default_t *d_default;
160 d_strategy_t *d_strategy;
163 d_kqfilter_t *d_kqfilter;
164 d_clone_t *d_clone; /* clone from base dev_ops */
165 #define dev_ops_last_field d_clone
171 family is defined as:
173 typedef int d_xxx_t (struct dev_xxx_args *ap);
176 Therefore, if one wants to implement a
178 function, this is the way:
183 mydev_open(struct dev_open_args *ap)
191 supplied in this call are a full 32 bits and the same mask and match must
192 be specified in a later
194 call to match this add.
195 However, the match value for the minor number should never have any bits
196 set in the major number's bit range (8-15).
197 The mask value may be conveniently specified as -1 without creating any
198 major number interference.
203 but no cred information or name need to be specified.
208 except that the new device is created using
213 takes as arguments a (major, minor) pair and returns a
221 and destroys the registration for that device.
224 destroys all ad-hoc device associations associated with a domain within
226 Only the minor numbers are included in the
234 Callers generally add their own references when they are going to store a device
235 node in a variable for long periods of time, to prevent a disassociation from
237 Also note that a caller that intends to call
239 must first obtain a reference on the device. The ad-hoc reference you get with
243 sufficient to be able to call
247 releases a reference on
249 The device will be terminated when the last reference has been released.
251 .Fn dev_ops_add_override
252 takes a cookie cutter to the
255 device space for the passed device and generates a new
257 visible to userland which the caller can then modify.
258 The original device is not modified but portions of its major/minor space will
259 no longer be visible to userland.
264 into the real thing by filling in uninitialized fields.
269 entries from the dev_ops_array[] major array so no new user opens can be
270 performed, and destroys all devices installed in the hash table that are
280 should match a previous call to
287 When fully implemented, if reference count reaches zero it will recurse through
290 .Fn dev_ops_intercept
291 intercepts the device operations vector of
297 is returned which may be used in a subsequent
300 The function sets the
306 restores the device operations vector of
316 issues a callback for all installed
319 The scan will terminate if a callback returns a negative number.
320 If not, it will return the sum of the returned values of all callback invocations.
326 functions first appeared in