xref: /freebsd/sbin/devfs/devfs.8 (revision 2546665afcaf0d53dc2c7058fee96354b3680f5a)
1.\"
2.\" Copyright (c) 2002 Dima Dorfman.
3.\" 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.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd July 1, 2002
29.Dt DEVFS 8
30.Os
31.Sh NAME
32.Nm devfs
33.Nd "DEVFS control"
34.Sh SYNOPSIS
35.Nm
36.Op Fl m Ar mount-point
37.Ar keyword
38.Ar argument ...
39.Sh DESCRIPTION
40The
41.Nm
42utility provides an interface to manipulate properties of
43.Xr devfs 5
44mounts.
45.Pp
46The
47.Ar keyword
48argument determines the context for
49the rest of the arguments.
50For example,
51most of the commands related to the rule subsystem must be preceded by the
52.Cm rule
53keyword.
54The following flags are common to all keywords:
55.Bl -tag -offset indent
56.It Fl m Ar mount-point
57Operate on
58.Ar mount-point ,
59which is expected to be a
60.Xr devfs 5
61mount.
62If this option is not specified,
63.Nm
64operates on
65.Pa /dev .
66.El
67.Ss Rule Subsystem
68The
69.Xr devfs 5
70rule subsystem provides a way for the administrator of a system to control
71the attributes of DEVFS nodes.
72.\" XXX devfs node?  entry?  what?
73Each DEVFS mount-point has a
74.Dq ruleset ,
75or a list of rules,
76associated with it.
77When a device driver creates a new node,
78all the rules in the ruleset associated with each mount-point are applied
79(see below) before the node becomes visible to the userland.
80This permits the administrator to change the properties,
81including the visibility,
82of certain nodes.
83For example, one might want to hide all disk nodes in a
84.Xr jail 2 Ns 's
85.Pa /dev .
86.Ss Rule Manipulation
87Rule manipulation commands follow the
88.Cm rule
89keyword.
90The following flags are common to all of the rule manipulation commands:
91.Bl -tag -offset indent
92.It Fl s Ar ruleset
93Operate on the ruleset with the number
94.Ar ruleset .
95If this is not specified,
96the commands operate on the ruleset currently associated with the
97specified mount-point.
98.El
99.Pp
100The following commands are recognized:
101.Bl -tag -offset indent
102.It Cm rule add Oo Ar rulenum Oc Ar rulespec
103Add the rule described by
104.Ar rulespec
105(defined below)
106to the ruleset.
107The rule has the number
108.Ar rulenum
109if it is explicitly specified;
110otherwise, the rule number is automatically determined by the kernel.
111.It Cm rule apply Ar rulenum | rulespec
112Apply rule number
113.Ar rulenum
114or the rule described by
115.Ar rulespec
116to the mount-point.
117Rules that are
118.Dq applied
119have their conditions checked against all nodes
120in the mount-point, and the actions taken if they match.
121.It Cm rule applyset
122Apply all the rules in the ruleset to the mount-point
123(see above for the definition of
124.Dq apply ) .
125.It Cm rule del Ar rulenum
126Delete rule number
127.Ar rulenum
128from the ruleset.
129.It Cm rule delset
130Delete all rules from the ruleset.
131.It Cm rule show Op Ar rulenum
132Display the rule number
133.Ar rulenum ,
134or all the rules in the ruleset.
135The output lines (one line per rule) are expected to be valid
136.Ar rulespec Ns s .
137.It Cm rule showsets
138Report the numbers of existing rulesets.
139.It Cm ruleset Ar ruleset
140Set ruleset number
141.Ar ruleset
142as the current ruleset for the mount-point.
143.El
144.Ss Rule Specification
145Rules have two parts: the conditions and the actions.
146The conditions determine which DEVFS nodes the rule matches,
147and the actions determine what should be done when a rule matches a node.
148For example, a rule can be written that sets the GID to
149.Dq Li games
150for all devices with major number 53.
151If the first token of a rule specification is a single dash
152.Pq Sq Fl ,
153rules are read from the standard input and the rest of the specification
154is ignored.
155.Pp
156The following conditions are recognized.
157Conditions are ANDed together when matching a device;
158if OR is desired, multiple rules can be written.
159.Bl -tag -offset indent
160.It Cm major Ar majdev
161Matches any node with a major number equal to
162.Ar majdev .
163.It Cm path Ar pattern
164Matches any node with a path that matches
165.Ar pattern .
166The latter is interpreted as a
167.Xr glob 3 Ns -style
168pattern.
169.It Cm type Ar devtype
170Matches any node that is of type
171.Ar devtype .
172Valid types are
173.Cm disk , mem , tape
174and
175.Cm tty .
176.El
177.Pp
178The following actions are recognized.
179Although there is no explicit delimiter between conditions and actions,
180they may not be intermixed.
181.Bl -tag -offset indent
182.It Cm group Ar gid
183Set the GID of the node to
184.Ar gid ,
185which may be a group name
186(looked up in
187.Pa /etc/group )
188or number.
189.It Cm hide
190Hide the node.
191Nodes may later be revived manually with
192.Xr mknod 8 ,
193or with the
194.Cm unhide
195action.
196.It Cm include Ar ruleset
197Apply all the rules in ruleset number
198.Ar ruleset
199to the node.
200This does not necessarily result in any changes to the node
201(e.g., if none of the rules in the included ruleset match).
202.It Cm mode Ar filemode
203Set the file mode to
204.Ar filemode ,
205which is interpreted in octal.
206.It Cm user Ar uid
207Set the UID to
208.Ar uid ,
209which may be a user name
210(looked up in
211.Pa /etc/passwd )
212or number.
213.It Cm unhide
214Unhide the node.
215.El
216.Sh IMPLEMENTATION NOTES
217Rulesets are created by the kernel at the first reference,
218and destroyed when the last reference disappears.
219E.g., a ruleset is created when a rule is added to it or when it is set
220as the current ruleset for a mount-point;
221a ruleset is destroyed when the last rule in it is deleted,
222and no other references to it exist
223(i.e., it is not included by any rules, and it is not the current ruleset
224for any mount-point).
225.Pp
226Ruleset number 0 is the default ruleset for all new mount-points.
227It is always empty, cannot be modified or deleted, and does not show up
228in the output of
229.Cm showsets .
230.Pp
231Rules and rulesets are unique to the entire system,
232not a particular mount-point.
233I.e., a
234.Cm showsets
235will return the same information regardless of the mount-point specified with
236.Fl m .
237The mount-point is only relevant when changing what its current ruleset is,
238or when using one of the apply commands.
239.Sh EXAMPLES
240When the system boots,
241the only ruleset that exists is ruleset number 0;
242since the latter may not be modified, we have to create another ruleset
243before adding rules.
244Note that since most of the following examples do not specify
245.Fl m ,
246the operations are performed on
247.Pa /dev
248(this only matters for things that might change the properties of nodes).
249.Pp
250.Dl "devfs ruleset 10"
251.Pp
252Specify that ruleset 10 should be the current ruleset for
253.Pa /dev
254(if it does not already exist, it is created).
255.Pp
256.Dl "devfs rule add path speaker mode 666"
257.Pp
258Add a rule that causes all nodes that have a path that matches
259.Dq Li speaker
260(this is only
261.Pa /dev/speaker )
262to have the file mode 666 (read and write for all).
263Note that if any such nodes already exist, their mode will not be changed
264unless this rule (or ruleset) is explicitly applied (see below).
265The mode
266.Em will
267be changed if the node is created
268.Em after
269the rule is added
270(e.g., the
271.Pa atspeaker
272module is loaded after the above rule is added).
273.Pp
274.Dl "devfs rule applyset"
275.Pp
276Apply all the rules in the current ruleset to all the existing nodes.
277E.g., if the above rule was added after
278.Pa /dev/speaker
279was created,
280this command will cause its file mode to be changed to 666,
281as rule prescribes.
282.Pp
283.Dl devfs rule add path "snp*" mode 660 group snoopers
284.Pp
285(Quoting the argument to
286.Cm path
287is often necessary to disable the shell's globbing features.)
288For all devices with a path that matches
289.Dq Li snp* ,
290set the file more to 660, and the GID to
291.Dq Li snoopers .
292This permits users in the
293.Dq Li snoopers
294group to use the
295.Xr snp 4
296devices.
297.Pp
298.Dl "devfs rule -s 20 add major 53 group games"
299.Pp
300Add a rule to ruleset number 20.
301Since this ruleset is not the current ruleset for any mount-points,
302this rule is never applied automatically (unless ruleset 20 becomes
303a current ruleset for some mount-point at a later time).
304However, it can be applied explicitly, as such:
305.Pp
306.Dl "devfs -m /my/jail/dev rule -s 20 applyset"
307.Pp
308This will apply all rules in ruleset number 20 to the DEVFS mount on
309.Pa /my/jail/dev .
310It does not matter that ruleset 20 is not the current ruleset for that
311mount-point; the rules are applied regardless.
312.Pp
313.Dl "devfs rule apply hide"
314.Pp
315Since this rule has no conditions, the action
316.Pq Cm hide
317will be applied to all nodes.
318Since hiding all nodes is not very useful, we can undo like so:
319.Pp
320.Dl "devfs rule apply unhide"
321.Pp
322which applies
323.Cm unhide
324to all the nodes,
325causing them to reappear.
326.Pp
327.Dl "cat my_rules | devfs rule -s 10 add -"
328.Pp
329Add all the rules from the file
330.Pa my_rules
331to ruleset 10.
332.Pp
333.Dl "devfs rule -s 20 show | devfs rule -s 10 add -"
334.Pp
335Since
336.Cm show
337outputs valid rules,
338this feature can be used to copy rulesets.
339The above copies all the rules from ruleset 20 into ruleset 10.
340The rule numbers are preserved,
341but ruleset 10 may already have rules with non-conflicting numbers
342(these will be preserved).
343.Sh SEE ALSO
344.Xr chmod 1 ,
345.Xr jail 2 ,
346.Xr glob 3 ,
347.Xr devfs 5 ,
348.Xr chown 8 ,
349.Xr jail 8 ,
350.Xr mknod 8
351.Sh AUTHORS
352.An Dima Dorfman
353