devfs.h revision 125855
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 125855 2004-02-15 21:43:08Z phk $
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#define	DRC_MAJOR	0x004
82100206Sdd	int	dr_dswflags;			/* cdevsw flags to match. */
83100206Sdd#define	DEVFS_MAXPTRNLEN	200
84100206Sdd	char	dr_pathptrn[DEVFS_MAXPTRNLEN];	/* Pattern to match path. */
85100206Sdd	int	dr_major;			/* Device major number. */
86100206Sdd
87100206Sdd	/*
88100206Sdd	 * Things to change.  dr_iacts determines which of the other
89100206Sdd	 * variables we should process.
90100206Sdd	 */
91100206Sdd	int	dr_iacts;
92100206Sdd#define	DRA_BACTS	0x001
93100804Sdd#define	DRA_UID		0x002
94100206Sdd#define	DRA_GID		0x004
95100206Sdd#define	DRA_MODE	0x008
96100206Sdd#define	DRA_INCSET	0x010
97100206Sdd	int	dr_bacts;			/* Boolean (on/off) action. */
98100206Sdd#define	DRB_HIDE	0x001			/* Hide entry (DE_WHITEOUT). */
99100206Sdd#define	DRB_UNHIDE	0x002			/* Unhide entry. */
100100206Sdd	uid_t	dr_uid;
101100206Sdd	gid_t	dr_gid;
102100206Sdd	mode_t	dr_mode;
103100206Sdd	devfs_rsnum dr_incset;			/* Included ruleset. */
104100206Sdd};
105100206Sdd
106100206Sdd/*
107100206Sdd * Rule-related ioctls.
108100206Sdd */
109100206Sdd#define	DEVFSIO_RADD		_IOWR('D', 0, struct devfs_rule)
110100206Sdd#define	DEVFSIO_RDEL		_IOW('D', 1, devfs_rid)
111100206Sdd#define	DEVFSIO_RAPPLY		_IOW('D', 2, struct devfs_rule)
112100206Sdd#define	DEVFSIO_RAPPLYID	_IOW('D', 3, devfs_rid)
113100206Sdd#define	DEVFSIO_RGETNEXT       	_IOWR('D', 4, struct devfs_rule)
114100206Sdd
115100206Sdd#define	DEVFSIO_SUSE		_IOW('D', 10, devfs_rsnum)
116100206Sdd#define	DEVFSIO_SAPPLY		_IOW('D', 11, devfs_rsnum)
117100206Sdd#define	DEVFSIO_SGETNEXT	_IOWR('D', 12, devfs_rsnum)
118100206Sdd
119100206Sdd/* XXX: DEVFSIO_RS_GET_INFO for refcount, active if any, etc. */
120100206Sdd
121100206Sdd#ifdef _KERNEL
122100206Sdd
123100206Sdd/*
12465515Sphk * These are default sizes for the DEVFS inode table and the overflow
12565515Sphk * table.  If the default table overflows we allocate the overflow
12665515Sphk * table, the size of which can also be set with a sysctl.  If the
12765515Sphk * overflow table fills you're toast.
12865515Sphk */
12965515Sphk#ifndef NDEVFSINO
13065515Sphk#define NDEVFSINO 1024
13165515Sphk#endif
13264880Sphk
13365515Sphk#ifndef NDEVFSOVERFLOW
13465515Sphk#define NDEVFSOVERFLOW 32768
13565515Sphk#endif
13665515Sphk
13765515Sphk/*
13865515Sphk * This is the first "per mount" inode, these are used for directories
13965515Sphk * and symlinks and the like.  Must be larger than the number of "true"
14065515Sphk * device nodes and symlinks.  It is.
14165515Sphk */
14265515Sphk#define DEVFSINOMOUNT	0x2000000
14365515Sphk
14495212Sbde#ifdef MALLOC_DECLARE
14564880SphkMALLOC_DECLARE(M_DEVFS);
14695212Sbde#endif
14764880Sphk
14864880Sphkstruct devfs_dirent {
14964880Sphk	int			de_inode;
15065051Sphk	int			de_flags;
15177050Sphk#define	DE_WHITEOUT	0x1
15265051Sphk#define	DE_DOT		0x2
15365051Sphk#define	DE_DOTDOT	0x4
15464880Sphk	struct dirent 		*de_dirent;
15564880Sphk	TAILQ_ENTRY(devfs_dirent) de_list;
15665051Sphk	TAILQ_HEAD(, devfs_dirent) de_dlist;
15765051Sphk	struct devfs_dirent	*de_dir;
15865051Sphk	int			de_links;
15964880Sphk	mode_t			de_mode;
16064880Sphk	uid_t			de_uid;
16164880Sphk	gid_t			de_gid;
16264880Sphk	struct label		*de_label;
16364880Sphk	struct timespec 	de_atime;
16464880Sphk	struct timespec 	de_mtime;
16564880Sphk	struct timespec 	de_ctime;
16664880Sphk	struct vnode 		*de_vnode;
16764880Sphk	char 			*de_symlink;
16864880Sphk};
16964880Sphk
17064880Sphkstruct devfs_mount {
17165051Sphk	struct mount		*dm_mount;
17265051Sphk	struct devfs_dirent	*dm_rootdir;
17364880Sphk	struct devfs_dirent	*dm_basedir;
17465515Sphk	unsigned		dm_generation;
17565515Sphk	struct devfs_dirent	**dm_dirent;
17664880Sphk	struct devfs_dirent	**dm_overflow;
17765515Sphk	int			dm_inode;
178100206Sdd	struct lock		dm_lock;
17964880Sphk	devfs_rsnum		dm_ruleset;
18064880Sphk};
18165515Sphk
18265515Sphk/*
18365515Sphk * This is what we fill in dm_dirent[N] for a deleted entry.
18465515Sphk */
18564880Sphk#define DE_DELETED ((struct devfs_dirent *)sizeof(struct devfs_dirent))
18664880Sphk
18764880Sphk#define VFSTODEVFS(mp)	((struct devfs_mount *)((mp)->mnt_data))
18864880Sphk
18964880Sphkvoid devfs_rules_apply(struct devfs_mount *dm, struct devfs_dirent *de);
19065051Sphkint devfs_rules_ioctl(struct mount *mp, u_long cmd, caddr_t data, struct thread *td);
191100206Sddvoid devfs_rules_newmount(struct devfs_mount *dm, struct thread *td);
192100206Sddint devfs_allocv (struct devfs_dirent *de, struct mount *mp, struct vnode **vpp, struct thread *td);
193100206Sdddev_t *devfs_itod (int inode);
194100206Sddstruct devfs_dirent **devfs_itode (struct devfs_mount *dm, int inode);
19583366Sjulianint devfs_populate (struct devfs_mount *dm);
19665515Sphkstruct devfs_dirent *devfs_newdirent (char *name, int namelen);
19765515Sphkvoid devfs_purge (struct devfs_dirent *dd);
19865515Sphkstruct devfs_dirent *devfs_vmkdir (char *name, int namelen, struct devfs_dirent *dotdot);
19965515Sphk
20065515Sphk#endif /* _KERNEL */
20165515Sphk
20265515Sphk#endif /* !_FS_DEVFS_DEVFS_H_ */
20364880Sphk