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: releng/10.2/sys/fs/devfs/devfs.h 231265 2012-02-09 10:09:12Z mm $
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
125212966Sjhstruct componentname;
126212966Sjh
127213215SjhTAILQ_HEAD(devfs_dlist_head, devfs_dirent);
128213215Sjh
12964880Sphkstruct devfs_dirent {
130150342Sphk	struct cdev_priv	*de_cdp;
131125855Sphk	int			de_inode;
132125855Sphk	int			de_flags;
133211226Sjh#define	DE_WHITEOUT	0x01
134211226Sjh#define	DE_DOT		0x02
135211226Sjh#define	DE_DOTDOT	0x04
136211226Sjh#define	DE_DOOMED	0x08
137211226Sjh#define	DE_COVERED	0x10
138213215Sjh#define	DE_USER		0x20
139162398Skib	int			de_holdcnt;
140125855Sphk	struct dirent 		*de_dirent;
14164880Sphk	TAILQ_ENTRY(devfs_dirent) de_list;
142213215Sjh	struct devfs_dlist_head	de_dlist;
143125855Sphk	struct devfs_dirent	*de_dir;
144125855Sphk	int			de_links;
145125855Sphk	mode_t			de_mode;
146125855Sphk	uid_t			de_uid;
147125855Sphk	gid_t			de_gid;
148125855Sphk	struct label		*de_label;
149125855Sphk	struct timespec 	de_atime;
150125855Sphk	struct timespec 	de_mtime;
151125855Sphk	struct timespec 	de_ctime;
152125855Sphk	struct vnode 		*de_vnode;
153125855Sphk	char 			*de_symlink;
15464880Sphk};
15564880Sphk
15664880Sphkstruct devfs_mount {
157150342Sphk	u_int			dm_idx;
158125855Sphk	struct mount		*dm_mount;
159125855Sphk	struct devfs_dirent	*dm_rootdir;
160125855Sphk	unsigned		dm_generation;
161162398Skib	int			dm_holdcnt;
162150342Sphk	struct sx		dm_lock;
163125855Sphk	devfs_rsnum		dm_ruleset;
16464880Sphk};
16564880Sphk
166150342Sphk#define DEVFS_ROOTINO 2
167150342Sphk
168150147Sphkextern unsigned devfs_rule_depth;
169150147Sphk
17064880Sphk#define VFSTODEVFS(mp)	((struct devfs_mount *)((mp)->mnt_data))
17164880Sphk
172162398Skib#define DEVFS_DE_HOLD(de)	((de)->de_holdcnt++)
173162398Skib#define DEVFS_DE_DROP(de)	(--(de)->de_holdcnt == 0)
174162398Skib
175162398Skib#define DEVFS_DMP_HOLD(dmp)	((dmp)->dm_holdcnt++)
176162398Skib#define DEVFS_DMP_DROP(dmp)	(--(dmp)->dm_holdcnt == 0)
177162398Skib
178212660Sjh#define	DEVFS_DEL_VNLOCKED	0x01
179212660Sjh#define	DEVFS_DEL_NORECURSE	0x02
180212660Sjh
181213725Sjhvoid	devfs_rules_apply(struct devfs_mount *, struct devfs_dirent *);
182213725Sjhvoid	devfs_rules_cleanup(struct devfs_mount *);
183213725Sjhint	devfs_rules_ioctl(struct devfs_mount *, u_long, caddr_t,
184213725Sjh	    struct thread *);
185231265Smmvoid	devfs_ruleset_set(devfs_rsnum rsnum, struct devfs_mount *dm);
186231265Smmvoid	devfs_ruleset_apply(struct devfs_mount *dm);
187213725Sjhint	devfs_allocv(struct devfs_dirent *, struct mount *, int,
188213725Sjh	    struct vnode **);
189213725Sjhchar	*devfs_fqpn(char *, struct devfs_mount *, struct devfs_dirent *,
190213725Sjh	    struct componentname *);
191213725Sjhvoid	devfs_delete(struct devfs_mount *, struct devfs_dirent *, int);
192213725Sjhvoid	devfs_dirent_free(struct devfs_dirent *);
193213725Sjhvoid	devfs_populate(struct devfs_mount *);
194213725Sjhvoid	devfs_cleanup(struct devfs_mount *);
195213725Sjhvoid	devfs_unmount_final(struct devfs_mount *);
196213725Sjhstruct devfs_dirent	*devfs_newdirent(char *, int);
197213725Sjhstruct devfs_dirent	*devfs_parent_dirent(struct devfs_dirent *);
198213725Sjhstruct devfs_dirent	*devfs_vmkdir(struct devfs_mount *, char *, int,
199213725Sjh			    struct devfs_dirent *, u_int);
200213725Sjhstruct devfs_dirent	*devfs_find(struct devfs_dirent *, const char *, int,
201213725Sjh			    int);
20265515Sphk
20364880Sphk#endif /* _KERNEL */
20495212Sbde
20595212Sbde#endif /* !_FS_DEVFS_DEVFS_H_ */
206