devfs.h revision 162398
195212Sbde/*-
264880Sphk * Copyright (c) 1992, 1993
364880Sphk *	The Regents of the University of California.  All rights reserved.
464880Sphk * Copyright (c) 2000
564880Sphk *	Poul-Henning Kamp.  All rights reserved.
6100206Sdd * Copyright (c) 2002
7100206Sdd *	Dima Dorfman.  All rights reserved.
864880Sphk *
964880Sphk * This code is derived from software donated to Berkeley by
1064880Sphk * Jan-Simon Pendry.
1164880Sphk *
1264880Sphk * Redistribution and use in source and binary forms, with or without
1364880Sphk * modification, are permitted provided that the following conditions
1464880Sphk * are met:
1564880Sphk * 1. Redistributions of source code must retain the above copyright
1664880Sphk *    notice, this list of conditions and the following disclaimer.
1764880Sphk * 2. Neither the name of the University nor the names of its contributors
1864880Sphk *    may be used to endorse or promote products derived from this software
1964880Sphk *    without specific prior written permission.
2064880Sphk *
2164880Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2264880Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2364880Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2464880Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2564880Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2664880Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2764880Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2864880Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2964880Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3064880Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3164880Sphk * SUCH DAMAGE.
3264880Sphk *
3364880Sphk *	@(#)kernfs.h	8.6 (Berkeley) 3/29/95
3464880Sphk * From: FreeBSD: src/sys/miscfs/kernfs/kernfs.h 1.14
3564880Sphk *
3664880Sphk * $FreeBSD: head/sys/fs/devfs/devfs.h 162398 2006-09-18 13:23:08Z kib $
3764880Sphk */
3864880Sphk
3965515Sphk#ifndef _FS_DEVFS_DEVFS_H_
4095212Sbde#define	_FS_DEVFS_DEVFS_H_
4164880Sphk
42100206Sdd#define	DEVFS_MAGIC	0xdb0a087a
4364880Sphk
4465515Sphk/*
45100206Sdd * Identifiers.  The ruleset and rule numbers are 16-bit values.  The
46100206Sdd * "rule ID" is a combination of the ruleset and rule number; it
47100206Sdd * should be able to univocally describe a rule in the system.  In
48100206Sdd * this implementation, the upper 16 bits of the rule ID is the
49100206Sdd * ruleset number; the lower 16 bits, the rule number within the
50100206Sdd * aforementioned ruleset.
51100206Sdd */
52100206Sddtypedef uint16_t devfs_rnum;
53100206Sddtypedef uint16_t devfs_rsnum;
54100206Sddtypedef uint32_t devfs_rid;
55100206Sdd
56100206Sdd/*
57100206Sdd * Identifier manipulators.
58100206Sdd */
59100206Sdd#define	rid2rsn(rid)	((rid) >> 16)
60100206Sdd#define	rid2rn(rid)	((rid) & 0xffff)
61100206Sdd#define	mkrid(rsn, rn)	((rn) | ((rsn) << 16))
62100206Sdd
63100206Sdd/*
64100206Sdd * Plain DEVFS rule.  This gets shared between kernel and userland
65100206Sdd * verbatim, so it shouldn't contain any pointers or other kernel- or
66100206Sdd * userland-specific values.
67100206Sdd */
68100206Sddstruct devfs_rule {
69100206Sdd	uint32_t dr_magic;			/* Magic number. */
70100206Sdd	devfs_rid dr_id;			/* Identifier. */
71100206Sdd
72100206Sdd	/*
73100206Sdd	 * Conditions under which this rule should be applied.  These
74100206Sdd	 * are ANDed together since OR can be simulated by using
75100206Sdd	 * multiple rules.  dr_icond determines which of the other
76100206Sdd	 * variables we should process.
77100206Sdd	 */
78100206Sdd	int	dr_icond;
79100206Sdd#define	DRC_DSWFLAGS	0x001
80100206Sdd#define	DRC_PATHPTRN	0x002
81100206Sdd	int	dr_dswflags;			/* cdevsw flags to match. */
82100206Sdd#define	DEVFS_MAXPTRNLEN	200
83100206Sdd	char	dr_pathptrn[DEVFS_MAXPTRNLEN];	/* Pattern to match path. */
84100206Sdd
85100206Sdd	/*
86100206Sdd	 * Things to change.  dr_iacts determines which of the other
87100206Sdd	 * variables we should process.
88100206Sdd	 */
89100206Sdd	int	dr_iacts;
90100206Sdd#define	DRA_BACTS	0x001
91100804Sdd#define	DRA_UID		0x002
92100206Sdd#define	DRA_GID		0x004
93100206Sdd#define	DRA_MODE	0x008
94100206Sdd#define	DRA_INCSET	0x010
95100206Sdd	int	dr_bacts;			/* Boolean (on/off) action. */
96100206Sdd#define	DRB_HIDE	0x001			/* Hide entry (DE_WHITEOUT). */
97100206Sdd#define	DRB_UNHIDE	0x002			/* Unhide entry. */
98100206Sdd	uid_t	dr_uid;
99100206Sdd	gid_t	dr_gid;
100100206Sdd	mode_t	dr_mode;
101100206Sdd	devfs_rsnum dr_incset;			/* Included ruleset. */
102100206Sdd};
103100206Sdd
104100206Sdd/*
105100206Sdd * Rule-related ioctls.
106100206Sdd */
107100206Sdd#define	DEVFSIO_RADD		_IOWR('D', 0, struct devfs_rule)
108100206Sdd#define	DEVFSIO_RDEL		_IOW('D', 1, devfs_rid)
109100206Sdd#define	DEVFSIO_RAPPLY		_IOW('D', 2, struct devfs_rule)
110100206Sdd#define	DEVFSIO_RAPPLYID	_IOW('D', 3, devfs_rid)
111100206Sdd#define	DEVFSIO_RGETNEXT       	_IOWR('D', 4, struct devfs_rule)
112100206Sdd
113100206Sdd#define	DEVFSIO_SUSE		_IOW('D', 10, devfs_rsnum)
114100206Sdd#define	DEVFSIO_SAPPLY		_IOW('D', 11, devfs_rsnum)
115100206Sdd#define	DEVFSIO_SGETNEXT	_IOWR('D', 12, devfs_rsnum)
116100206Sdd
117100206Sdd/* XXX: DEVFSIO_RS_GET_INFO for refcount, active if any, etc. */
118100206Sdd
119100206Sdd#ifdef _KERNEL
120100206Sdd
12195212Sbde#ifdef MALLOC_DECLARE
12264880SphkMALLOC_DECLARE(M_DEVFS);
12395212Sbde#endif
12464880Sphk
12564880Sphkstruct devfs_dirent {
126150342Sphk	struct cdev_priv	*de_cdp;
127125855Sphk	int			de_inode;
128125855Sphk	int			de_flags;
129211226Sjh#define	DE_WHITEOUT	0x1
130211226Sjh#define	DE_DOT		0x2
131211226Sjh#define	DE_DOTDOT	0x4
132211226Sjh#define DE_DOOMED	0x8
133211226Sjh	int			de_holdcnt;
134162398Skib	struct dirent 		*de_dirent;
135125855Sphk	TAILQ_ENTRY(devfs_dirent) de_list;
13664880Sphk	TAILQ_HEAD(, devfs_dirent) de_dlist;
13765051Sphk	struct devfs_dirent	*de_dir;
138125855Sphk	int			de_links;
139125855Sphk	mode_t			de_mode;
140125855Sphk	uid_t			de_uid;
141125855Sphk	gid_t			de_gid;
142125855Sphk	struct label		*de_label;
143125855Sphk	struct timespec 	de_atime;
144125855Sphk	struct timespec 	de_mtime;
145125855Sphk	struct timespec 	de_ctime;
146125855Sphk	struct vnode 		*de_vnode;
147125855Sphk	char 			*de_symlink;
148125855Sphk};
14964880Sphk
15064880Sphkstruct devfs_mount {
15164880Sphk	u_int			dm_idx;
152150342Sphk	struct mount		*dm_mount;
153125855Sphk	struct devfs_dirent	*dm_rootdir;
154125855Sphk	unsigned		dm_generation;
155125855Sphk	int			dm_holdcnt;
156162398Skib	struct sx		dm_lock;
157150342Sphk	devfs_rsnum		dm_ruleset;
158125855Sphk};
15964880Sphk
16064880Sphk#define DEVFS_ROOTINO 2
161150342Sphk
162150342Sphkextern unsigned devfs_rule_depth;
163150147Sphk
164150147Sphk#define VFSTODEVFS(mp)	((struct devfs_mount *)((mp)->mnt_data))
16564880Sphk
16664880Sphk#define DEVFS_DE_HOLD(de)	((de)->de_holdcnt++)
167162398Skib#define DEVFS_DE_DROP(de)	(--(de)->de_holdcnt == 0)
168162398Skib
169162398Skib#define DEVFS_DMP_HOLD(dmp)	((dmp)->dm_holdcnt++)
170162398Skib#define DEVFS_DMP_DROP(dmp)	(--(dmp)->dm_holdcnt == 0)
171162398Skib
172162398Skibvoid devfs_rules_apply(struct devfs_mount *dm, struct devfs_dirent *de);
173100206Sddvoid devfs_rules_cleanup (struct devfs_mount *dm);
174150501Sphkint devfs_rules_ioctl(struct devfs_mount *dm, u_long cmd, caddr_t data, struct thread *td);
175150149Sphkint devfs_allocv (struct devfs_dirent *de, struct mount *mp, struct vnode **vpp, struct thread *td);
176210921Skibvoid devfs_delete(struct devfs_mount *dm, struct devfs_dirent *de);
177191990Sattiliovoid devfs_dirent_free(struct devfs_dirent *de);
178163481Skibvoid devfs_populate (struct devfs_mount *dm);
179162398Skibvoid devfs_cleanup (struct devfs_mount *dm);
180150151Sphkvoid devfs_unmount_final(struct devfs_mount *mp);
181150342Sphkstruct devfs_dirent *devfs_newdirent (char *name, int namelen);
182162398Skibstruct devfs_dirent *devfs_vmkdir (struct devfs_mount *, char *name, int namelen, struct devfs_dirent *dotdot, u_int inode);
18365515Sphkstruct devfs_dirent *devfs_find (struct devfs_dirent *dd, const char *name, int namelen);
184208951Sjh
185150342Sphk#endif /* _KERNEL */
186211226Sjh
18765515Sphk#endif /* !_FS_DEVFS_DEVFS_H_ */
18864880Sphk