devfs.h revision 65515
1/*
2 * Copyright (c) 1992, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 * Copyright (c) 2000
5 *	Poul-Henning Kamp.  All rights reserved.
6 *
7 * This code is derived from software donated to Berkeley by
8 * Jan-Simon Pendry.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Neither the name of the University nor the names of its contributors
16 *    may be used to endorse or promote products derived from this software
17 *    without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 *	@(#)kernfs.h	8.6 (Berkeley) 3/29/95
32 * From: FreeBSD: src/sys/miscfs/kernfs/kernfs.h 1.14
33 *
34 * $FreeBSD: head/sys/fs/devfs/devfs.h 65515 2000-09-06 11:26:43Z phk $
35 */
36
37#ifndef _FS_DEVFS_DEVFS_H_
38#define _FS_DEVFS_DEVFS_H_
39
40#ifdef _KERNEL	/* No userland stuff in here... */
41
42/*
43 * These are default sizes for the DEVFS inode table and the overflow
44 * table.  If the default table overflows we allocate the overflow
45 * table, the size of which can also be set with a sysctl.  If the
46 * overflow table fills you're toast.
47 */
48#ifndef NDEVFSINO
49#define NDEVFSINO 1024
50#endif
51
52#ifndef NDEVFSOVERFLOW
53#define NDEVFSOVERFLOW 32768
54#endif
55
56/*
57 * This is the first "per mount" inode, these are used for directories
58 * and symlinks and the like.  Must be larger than the number of "true"
59 * device nodes and symlinks.  It is.
60 */
61#define DEVFSINOMOUNT	0x2000000
62
63MALLOC_DECLARE(M_DEVFS);
64
65struct devfs_dirent {
66	int	de_inode;
67	int	de_flags;
68#define	DE_ORPHAN	0x1
69#define	DE_DOT		0x2
70#define	DE_DOTDOT	0x4
71	struct dirent *de_dirent;
72	TAILQ_ENTRY(devfs_dirent) de_list;
73	TAILQ_HEAD(, devfs_dirent) de_dlist;
74	struct devfs_dirent *de_dir;
75	int	de_links;
76	mode_t	de_mode;
77	uid_t	de_uid;
78	gid_t	de_gid;
79	struct timespec de_atime;
80	struct timespec de_mtime;
81	struct timespec de_ctime;
82	struct vnode *de_vnode;
83	char *	de_symlink;
84};
85
86struct devfs_mount {
87	struct vnode	*dm_root;	/* Root node */
88	struct devfs_dirent *dm_rootdir;
89	struct devfs_dirent *dm_basedir;
90	unsigned	dm_generation;
91	struct devfs_dirent *dm_dirent[NDEVFSINO];
92	struct devfs_dirent **dm_overflow;
93	int	dm_inode;
94	struct lock dm_lock;
95};
96
97/*
98 * This is what we fill in dm_dirent[N] for a deleted entry.
99 */
100#define DE_DELETED ((struct devfs_dirent *)sizeof(struct devfs_dirent))
101
102#define VFSTODEVFS(mp)	((struct devfs_mount *)((mp)->mnt_data))
103
104extern vop_t **devfs_vnodeop_p;
105extern vop_t **devfs_specop_p;
106
107int devfs_allocv (struct devfs_dirent *de, struct mount *mp, struct vnode **vpp, struct proc *p);
108void devfs_attemptoverflow(int insist);
109struct devfs_dirent *devfs_find (struct devfs_dirent *dd, const char *name, int namelen);
110dev_t *devfs_itod (int inode);
111struct devfs_dirent **devfs_itode (struct devfs_mount *dm, int inode);
112int devfs_populate (struct devfs_mount *dm);
113struct devfs_dirent *devfs_newdirent (char *name, int namelen);
114void devfs_purge (struct devfs_dirent *dd);
115struct devfs_dirent *devfs_vmkdir (char *name, int namelen, struct devfs_dirent *dotdot);
116
117#endif /* _KERNEL */
118#endif /* _FS_DEVFS_DEVFS_H_ */
119