devfs.h revision 208951
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 208951 2010-06-09 15:29:12Z jh $
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
121100206Sdd#ifdef MALLOC_DECLARE
12265515SphkMALLOC_DECLARE(M_DEVFS);
12365515Sphk#endif
12465515Sphk
12565515Sphkstruct devfs_dirent {
12665515Sphk	struct cdev_priv	*de_cdp;
12765515Sphk	int			de_inode;
12865515Sphk	int			de_flags;
12965515Sphk#define	DE_WHITEOUT	0x1
13064880Sphk#define	DE_DOT		0x2
13165515Sphk#define	DE_DOTDOT	0x4
13265515Sphk#define DE_DOOMED	0x8
13365515Sphk	int			de_holdcnt;
13465515Sphk	struct dirent 		*de_dirent;
13565515Sphk	TAILQ_ENTRY(devfs_dirent) de_list;
13665515Sphk	TAILQ_HEAD(, devfs_dirent) de_dlist;
13765515Sphk	struct devfs_dirent	*de_dir;
13865515Sphk	int			de_links;
13965515Sphk	mode_t			de_mode;
14065515Sphk	uid_t			de_uid;
14165515Sphk	gid_t			de_gid;
14295212Sbde	struct label		*de_label;
14364880Sphk	struct timespec 	de_atime;
14495212Sbde	struct timespec 	de_mtime;
14564880Sphk	struct timespec 	de_ctime;
14664880Sphk	struct vnode 		*de_vnode;
147125855Sphk	char 			*de_symlink;
148125855Sphk};
14977050Sphk
15065051Sphkstruct devfs_mount {
15165051Sphk	u_int			dm_idx;
152125855Sphk	struct mount		*dm_mount;
15364880Sphk	struct devfs_dirent	*dm_rootdir;
15465051Sphk	unsigned		dm_generation;
155142242Sphk	int			dm_holdcnt;
156125855Sphk	struct sx		dm_lock;
157125855Sphk	devfs_rsnum		dm_ruleset;
158125855Sphk};
159125855Sphk
160125855Sphk#define DEVFS_ROOTINO 2
161125855Sphk
162125855Sphkextern unsigned devfs_rule_depth;
163125855Sphk
164125855Sphk#define VFSTODEVFS(mp)	((struct devfs_mount *)((mp)->mnt_data))
165125855Sphk
166125855Sphk#define DEVFS_DE_HOLD(de)	((de)->de_holdcnt++)
16764880Sphk#define DEVFS_DE_DROP(de)	(--(de)->de_holdcnt == 0)
16864880Sphk
16964880Sphk#define DEVFS_DMP_HOLD(dmp)	((dmp)->dm_holdcnt++)
170125855Sphk#define DEVFS_DMP_DROP(dmp)	(--(dmp)->dm_holdcnt == 0)
171125855Sphk
172125855Sphkvoid devfs_rules_apply(struct devfs_mount *dm, struct devfs_dirent *de);
173125855Sphkvoid devfs_rules_cleanup (struct devfs_mount *dm);
174125855Sphkint devfs_rules_ioctl(struct devfs_mount *dm, u_long cmd, caddr_t data, struct thread *td);
175125855Sphkint devfs_allocv (struct devfs_dirent *de, struct mount *mp,
176125855Sphk    struct vnode **vpp);
177125855Sphkvoid devfs_delete(struct devfs_mount *dm, struct devfs_dirent *de, int vp_locked);
17864880Sphkvoid devfs_dirent_free(struct devfs_dirent *de);
17964880Sphkvoid devfs_populate (struct devfs_mount *dm);
180150147Sphkvoid devfs_cleanup (struct devfs_mount *dm);
181150147Sphkvoid devfs_unmount_final(struct devfs_mount *mp);
18265515Sphkstruct devfs_dirent *devfs_newdirent (char *name, int namelen);
18365515Sphkstruct devfs_dirent *devfs_parent_dirent(struct devfs_dirent *de);
18465515Sphkstruct devfs_dirent *devfs_vmkdir (struct devfs_mount *, char *name, int namelen, struct devfs_dirent *dotdot, u_int inode);
18565515Sphkstruct devfs_dirent *devfs_find (struct devfs_dirent *dd, const char *name, int namelen);
18664880Sphk
18764880Sphk#endif /* _KERNEL */
18864880Sphk
189100206Sdd#endif /* !_FS_DEVFS_DEVFS_H_ */
190105212Sphk