devfs.h revision 211226
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 211226 2010-08-12 15:29:07Z 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
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;
12977050Sphk#define	DE_WHITEOUT	0x01
13065051Sphk#define	DE_DOT		0x02
13165051Sphk#define	DE_DOTDOT	0x04
132162398Skib#define	DE_DOOMED	0x08
133162398Skib#define	DE_COVERED	0x10
134125855Sphk	int			de_holdcnt;
13564880Sphk	struct dirent 		*de_dirent;
13665051Sphk	TAILQ_ENTRY(devfs_dirent) de_list;
137125855Sphk	TAILQ_HEAD(, devfs_dirent) de_dlist;
138125855Sphk	struct devfs_dirent	*de_dir;
139125855Sphk	int			de_links;
140125855Sphk	mode_t			de_mode;
141125855Sphk	uid_t			de_uid;
142125855Sphk	gid_t			de_gid;
143125855Sphk	struct label		*de_label;
144125855Sphk	struct timespec 	de_atime;
145125855Sphk	struct timespec 	de_mtime;
146125855Sphk	struct timespec 	de_ctime;
147125855Sphk	struct vnode 		*de_vnode;
14864880Sphk	char 			*de_symlink;
14964880Sphk};
15064880Sphk
151150342Sphkstruct devfs_mount {
152125855Sphk	u_int			dm_idx;
153125855Sphk	struct mount		*dm_mount;
154125855Sphk	struct devfs_dirent	*dm_rootdir;
155162398Skib	unsigned		dm_generation;
156150342Sphk	int			dm_holdcnt;
157125855Sphk	struct sx		dm_lock;
15864880Sphk	devfs_rsnum		dm_ruleset;
15964880Sphk};
160150342Sphk
161150342Sphk#define DEVFS_ROOTINO 2
162150147Sphk
163150147Sphkextern unsigned devfs_rule_depth;
16464880Sphk
16564880Sphk#define VFSTODEVFS(mp)	((struct devfs_mount *)((mp)->mnt_data))
166162398Skib
167162398Skib#define DEVFS_DE_HOLD(de)	((de)->de_holdcnt++)
168162398Skib#define DEVFS_DE_DROP(de)	(--(de)->de_holdcnt == 0)
169162398Skib
170162398Skib#define DEVFS_DMP_HOLD(dmp)	((dmp)->dm_holdcnt++)
171162398Skib#define DEVFS_DMP_DROP(dmp)	(--(dmp)->dm_holdcnt == 0)
172100206Sdd
173150501Sphkvoid devfs_rules_apply(struct devfs_mount *dm, struct devfs_dirent *de);
174150149Sphkvoid devfs_rules_cleanup (struct devfs_mount *dm);
17583366Sjulianint devfs_rules_ioctl(struct devfs_mount *dm, u_long cmd, caddr_t data, struct thread *td);
176150342Sphkint devfs_allocv(struct devfs_dirent *de, struct mount *mp, int lockmode,
177162398Skib    struct vnode **vpp);
178150151Sphkvoid devfs_delete(struct devfs_mount *dm, struct devfs_dirent *de, int vp_locked);
179150342Sphkvoid devfs_dirent_free(struct devfs_dirent *de);
180162398Skibvoid devfs_populate (struct devfs_mount *dm);
18165515Sphkvoid devfs_cleanup (struct devfs_mount *dm);
182150342Sphkvoid devfs_unmount_final(struct devfs_mount *mp);
183150342Sphkstruct devfs_dirent *devfs_newdirent (char *name, int namelen);
18465515Sphkstruct devfs_dirent *devfs_parent_dirent(struct devfs_dirent *de);
18564880Sphkstruct devfs_dirent *devfs_vmkdir (struct devfs_mount *, char *name, int namelen, struct devfs_dirent *dotdot, u_int inode);
18695212Sbdestruct devfs_dirent *devfs_find(struct devfs_dirent *dd, const char *name, int namelen, int type);
18795212Sbde
188#endif /* _KERNEL */
189
190#endif /* !_FS_DEVFS_DEVFS_H_ */
191