Deleted Added
full compact
devfs.h (212966) devfs.h (213215)
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2000
5 * Poul-Henning Kamp. All rights reserved.
6 * Copyright (c) 2002
7 * Dima Dorfman. All rights reserved.
8 *
9 * This code is derived from software donated to Berkeley by
10 * Jan-Simon Pendry.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)kernfs.h 8.6 (Berkeley) 3/29/95
34 * From: FreeBSD: src/sys/miscfs/kernfs/kernfs.h 1.14
35 *
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2000
5 * Poul-Henning Kamp. All rights reserved.
6 * Copyright (c) 2002
7 * Dima Dorfman. All rights reserved.
8 *
9 * This code is derived from software donated to Berkeley by
10 * Jan-Simon Pendry.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)kernfs.h 8.6 (Berkeley) 3/29/95
34 * From: FreeBSD: src/sys/miscfs/kernfs/kernfs.h 1.14
35 *
36 * $FreeBSD: head/sys/fs/devfs/devfs.h 212966 2010-09-21 16:49:02Z jh $
36 * $FreeBSD: head/sys/fs/devfs/devfs.h 213215 2010-09-27 17:47:09Z jh $
37 */
38
39#ifndef _FS_DEVFS_DEVFS_H_
40#define _FS_DEVFS_DEVFS_H_
41
42#define DEVFS_MAGIC 0xdb0a087a
43
44/*
45 * Identifiers. The ruleset and rule numbers are 16-bit values. The
46 * "rule ID" is a combination of the ruleset and rule number; it
47 * should be able to univocally describe a rule in the system. In
48 * this implementation, the upper 16 bits of the rule ID is the
49 * ruleset number; the lower 16 bits, the rule number within the
50 * aforementioned ruleset.
51 */
52typedef uint16_t devfs_rnum;
53typedef uint16_t devfs_rsnum;
54typedef uint32_t devfs_rid;
55
56/*
57 * Identifier manipulators.
58 */
59#define rid2rsn(rid) ((rid) >> 16)
60#define rid2rn(rid) ((rid) & 0xffff)
61#define mkrid(rsn, rn) ((rn) | ((rsn) << 16))
62
63/*
64 * Plain DEVFS rule. This gets shared between kernel and userland
65 * verbatim, so it shouldn't contain any pointers or other kernel- or
66 * userland-specific values.
67 */
68struct devfs_rule {
69 uint32_t dr_magic; /* Magic number. */
70 devfs_rid dr_id; /* Identifier. */
71
72 /*
73 * Conditions under which this rule should be applied. These
74 * are ANDed together since OR can be simulated by using
75 * multiple rules. dr_icond determines which of the other
76 * variables we should process.
77 */
78 int dr_icond;
79#define DRC_DSWFLAGS 0x001
80#define DRC_PATHPTRN 0x002
81 int dr_dswflags; /* cdevsw flags to match. */
82#define DEVFS_MAXPTRNLEN 200
83 char dr_pathptrn[DEVFS_MAXPTRNLEN]; /* Pattern to match path. */
84
85 /*
86 * Things to change. dr_iacts determines which of the other
87 * variables we should process.
88 */
89 int dr_iacts;
90#define DRA_BACTS 0x001
91#define DRA_UID 0x002
92#define DRA_GID 0x004
93#define DRA_MODE 0x008
94#define DRA_INCSET 0x010
95 int dr_bacts; /* Boolean (on/off) action. */
96#define DRB_HIDE 0x001 /* Hide entry (DE_WHITEOUT). */
97#define DRB_UNHIDE 0x002 /* Unhide entry. */
98 uid_t dr_uid;
99 gid_t dr_gid;
100 mode_t dr_mode;
101 devfs_rsnum dr_incset; /* Included ruleset. */
102};
103
104/*
105 * Rule-related ioctls.
106 */
107#define DEVFSIO_RADD _IOWR('D', 0, struct devfs_rule)
108#define DEVFSIO_RDEL _IOW('D', 1, devfs_rid)
109#define DEVFSIO_RAPPLY _IOW('D', 2, struct devfs_rule)
110#define DEVFSIO_RAPPLYID _IOW('D', 3, devfs_rid)
111#define DEVFSIO_RGETNEXT _IOWR('D', 4, struct devfs_rule)
112
113#define DEVFSIO_SUSE _IOW('D', 10, devfs_rsnum)
114#define DEVFSIO_SAPPLY _IOW('D', 11, devfs_rsnum)
115#define DEVFSIO_SGETNEXT _IOWR('D', 12, devfs_rsnum)
116
117/* XXX: DEVFSIO_RS_GET_INFO for refcount, active if any, etc. */
118
119#ifdef _KERNEL
120
121#ifdef MALLOC_DECLARE
122MALLOC_DECLARE(M_DEVFS);
123#endif
124
125struct componentname;
126
37 */
38
39#ifndef _FS_DEVFS_DEVFS_H_
40#define _FS_DEVFS_DEVFS_H_
41
42#define DEVFS_MAGIC 0xdb0a087a
43
44/*
45 * Identifiers. The ruleset and rule numbers are 16-bit values. The
46 * "rule ID" is a combination of the ruleset and rule number; it
47 * should be able to univocally describe a rule in the system. In
48 * this implementation, the upper 16 bits of the rule ID is the
49 * ruleset number; the lower 16 bits, the rule number within the
50 * aforementioned ruleset.
51 */
52typedef uint16_t devfs_rnum;
53typedef uint16_t devfs_rsnum;
54typedef uint32_t devfs_rid;
55
56/*
57 * Identifier manipulators.
58 */
59#define rid2rsn(rid) ((rid) >> 16)
60#define rid2rn(rid) ((rid) & 0xffff)
61#define mkrid(rsn, rn) ((rn) | ((rsn) << 16))
62
63/*
64 * Plain DEVFS rule. This gets shared between kernel and userland
65 * verbatim, so it shouldn't contain any pointers or other kernel- or
66 * userland-specific values.
67 */
68struct devfs_rule {
69 uint32_t dr_magic; /* Magic number. */
70 devfs_rid dr_id; /* Identifier. */
71
72 /*
73 * Conditions under which this rule should be applied. These
74 * are ANDed together since OR can be simulated by using
75 * multiple rules. dr_icond determines which of the other
76 * variables we should process.
77 */
78 int dr_icond;
79#define DRC_DSWFLAGS 0x001
80#define DRC_PATHPTRN 0x002
81 int dr_dswflags; /* cdevsw flags to match. */
82#define DEVFS_MAXPTRNLEN 200
83 char dr_pathptrn[DEVFS_MAXPTRNLEN]; /* Pattern to match path. */
84
85 /*
86 * Things to change. dr_iacts determines which of the other
87 * variables we should process.
88 */
89 int dr_iacts;
90#define DRA_BACTS 0x001
91#define DRA_UID 0x002
92#define DRA_GID 0x004
93#define DRA_MODE 0x008
94#define DRA_INCSET 0x010
95 int dr_bacts; /* Boolean (on/off) action. */
96#define DRB_HIDE 0x001 /* Hide entry (DE_WHITEOUT). */
97#define DRB_UNHIDE 0x002 /* Unhide entry. */
98 uid_t dr_uid;
99 gid_t dr_gid;
100 mode_t dr_mode;
101 devfs_rsnum dr_incset; /* Included ruleset. */
102};
103
104/*
105 * Rule-related ioctls.
106 */
107#define DEVFSIO_RADD _IOWR('D', 0, struct devfs_rule)
108#define DEVFSIO_RDEL _IOW('D', 1, devfs_rid)
109#define DEVFSIO_RAPPLY _IOW('D', 2, struct devfs_rule)
110#define DEVFSIO_RAPPLYID _IOW('D', 3, devfs_rid)
111#define DEVFSIO_RGETNEXT _IOWR('D', 4, struct devfs_rule)
112
113#define DEVFSIO_SUSE _IOW('D', 10, devfs_rsnum)
114#define DEVFSIO_SAPPLY _IOW('D', 11, devfs_rsnum)
115#define DEVFSIO_SGETNEXT _IOWR('D', 12, devfs_rsnum)
116
117/* XXX: DEVFSIO_RS_GET_INFO for refcount, active if any, etc. */
118
119#ifdef _KERNEL
120
121#ifdef MALLOC_DECLARE
122MALLOC_DECLARE(M_DEVFS);
123#endif
124
125struct componentname;
126
127TAILQ_HEAD(devfs_dlist_head, devfs_dirent);
128
127struct devfs_dirent {
128 struct cdev_priv *de_cdp;
129 int de_inode;
130 int de_flags;
131#define DE_WHITEOUT 0x01
132#define DE_DOT 0x02
133#define DE_DOTDOT 0x04
134#define DE_DOOMED 0x08
135#define DE_COVERED 0x10
129struct devfs_dirent {
130 struct cdev_priv *de_cdp;
131 int de_inode;
132 int de_flags;
133#define DE_WHITEOUT 0x01
134#define DE_DOT 0x02
135#define DE_DOTDOT 0x04
136#define DE_DOOMED 0x08
137#define DE_COVERED 0x10
138#define DE_USER 0x20
136 int de_holdcnt;
137 struct dirent *de_dirent;
138 TAILQ_ENTRY(devfs_dirent) de_list;
139 int de_holdcnt;
140 struct dirent *de_dirent;
141 TAILQ_ENTRY(devfs_dirent) de_list;
139 TAILQ_HEAD(, devfs_dirent) de_dlist;
142 struct devfs_dlist_head de_dlist;
140 struct devfs_dirent *de_dir;
141 int de_links;
142 mode_t de_mode;
143 uid_t de_uid;
144 gid_t de_gid;
145 struct label *de_label;
146 struct timespec de_atime;
147 struct timespec de_mtime;
148 struct timespec de_ctime;
149 struct vnode *de_vnode;
150 char *de_symlink;
151};
152
153struct devfs_mount {
154 u_int dm_idx;
155 struct mount *dm_mount;
156 struct devfs_dirent *dm_rootdir;
157 unsigned dm_generation;
158 int dm_holdcnt;
159 struct sx dm_lock;
160 devfs_rsnum dm_ruleset;
161};
162
163#define DEVFS_ROOTINO 2
164
165extern unsigned devfs_rule_depth;
166
167#define VFSTODEVFS(mp) ((struct devfs_mount *)((mp)->mnt_data))
168
169#define DEVFS_DE_HOLD(de) ((de)->de_holdcnt++)
170#define DEVFS_DE_DROP(de) (--(de)->de_holdcnt == 0)
171
172#define DEVFS_DMP_HOLD(dmp) ((dmp)->dm_holdcnt++)
173#define DEVFS_DMP_DROP(dmp) (--(dmp)->dm_holdcnt == 0)
174
175#define DEVFS_DEL_VNLOCKED 0x01
176#define DEVFS_DEL_NORECURSE 0x02
177
178void devfs_rules_apply(struct devfs_mount *dm, struct devfs_dirent *de);
179void devfs_rules_cleanup (struct devfs_mount *dm);
180int devfs_rules_ioctl(struct devfs_mount *dm, u_long cmd, caddr_t data, struct thread *td);
181int devfs_allocv(struct devfs_dirent *de, struct mount *mp, int lockmode,
182 struct vnode **vpp);
183char *devfs_fqpn(char *, struct devfs_mount *, struct devfs_dirent *,
184 struct componentname *);
185void devfs_delete(struct devfs_mount *dm, struct devfs_dirent *de, int flags);
186void devfs_dirent_free(struct devfs_dirent *de);
187void devfs_populate (struct devfs_mount *dm);
188void devfs_cleanup (struct devfs_mount *dm);
189void devfs_unmount_final(struct devfs_mount *mp);
190struct devfs_dirent *devfs_newdirent (char *name, int namelen);
191struct devfs_dirent *devfs_parent_dirent(struct devfs_dirent *de);
192struct devfs_dirent *devfs_vmkdir (struct devfs_mount *, char *name, int namelen, struct devfs_dirent *dotdot, u_int inode);
193struct devfs_dirent *devfs_find(struct devfs_dirent *dd, const char *name, int namelen, int type);
194
195#endif /* _KERNEL */
196
197#endif /* !_FS_DEVFS_DEVFS_H_ */
143 struct devfs_dirent *de_dir;
144 int de_links;
145 mode_t de_mode;
146 uid_t de_uid;
147 gid_t de_gid;
148 struct label *de_label;
149 struct timespec de_atime;
150 struct timespec de_mtime;
151 struct timespec de_ctime;
152 struct vnode *de_vnode;
153 char *de_symlink;
154};
155
156struct devfs_mount {
157 u_int dm_idx;
158 struct mount *dm_mount;
159 struct devfs_dirent *dm_rootdir;
160 unsigned dm_generation;
161 int dm_holdcnt;
162 struct sx dm_lock;
163 devfs_rsnum dm_ruleset;
164};
165
166#define DEVFS_ROOTINO 2
167
168extern unsigned devfs_rule_depth;
169
170#define VFSTODEVFS(mp) ((struct devfs_mount *)((mp)->mnt_data))
171
172#define DEVFS_DE_HOLD(de) ((de)->de_holdcnt++)
173#define DEVFS_DE_DROP(de) (--(de)->de_holdcnt == 0)
174
175#define DEVFS_DMP_HOLD(dmp) ((dmp)->dm_holdcnt++)
176#define DEVFS_DMP_DROP(dmp) (--(dmp)->dm_holdcnt == 0)
177
178#define DEVFS_DEL_VNLOCKED 0x01
179#define DEVFS_DEL_NORECURSE 0x02
180
181void devfs_rules_apply(struct devfs_mount *dm, struct devfs_dirent *de);
182void devfs_rules_cleanup (struct devfs_mount *dm);
183int devfs_rules_ioctl(struct devfs_mount *dm, u_long cmd, caddr_t data, struct thread *td);
184int devfs_allocv(struct devfs_dirent *de, struct mount *mp, int lockmode,
185 struct vnode **vpp);
186char *devfs_fqpn(char *, struct devfs_mount *, struct devfs_dirent *,
187 struct componentname *);
188void devfs_delete(struct devfs_mount *dm, struct devfs_dirent *de, int flags);
189void devfs_dirent_free(struct devfs_dirent *de);
190void devfs_populate (struct devfs_mount *dm);
191void devfs_cleanup (struct devfs_mount *dm);
192void devfs_unmount_final(struct devfs_mount *mp);
193struct devfs_dirent *devfs_newdirent (char *name, int namelen);
194struct devfs_dirent *devfs_parent_dirent(struct devfs_dirent *de);
195struct devfs_dirent *devfs_vmkdir (struct devfs_mount *, char *name, int namelen, struct devfs_dirent *dotdot, u_int inode);
196struct devfs_dirent *devfs_find(struct devfs_dirent *dd, const char *name, int namelen, int type);
197
198#endif /* _KERNEL */
199
200#endif /* !_FS_DEVFS_DEVFS_H_ */