1 /* $NetBSD: fdesc_vfsops.c,v 1.83 2009/11/30 10:59:20 pooka Exp $ */
4 * Copyright (c) 1992, 1993, 1995
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software donated to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)fdesc_vfsops.c 8.10 (Berkeley) 5/14/95
36 * #Id: fdesc_vfsops.c,v 1.9 1993/04/06 15:28:33 jsp Exp #
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.83 2009/11/30 10:59:20 pooka Exp $");
46 #if defined(_KERNEL_OPT)
47 #include "opt_compat_netbsd.h"
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/sysctl.h>
55 #include <sys/resourcevar.h>
56 #include <sys/filedesc.h>
57 #include <sys/vnode.h>
58 #include <sys/mount.h>
59 #include <sys/dirent.h>
60 #include <sys/namei.h>
61 #include <sys/malloc.h>
62 #include <sys/kauth.h>
63 #include <sys/module.h>
65 #include <miscfs/genfs/genfs.h>
66 #include <miscfs/fdesc/fdesc.h>
68 MODULE(MODULE_CLASS_VFS
, fdesc
, NULL
);
72 static struct sysctllog
*fdesc_sysctl_log
;
75 * Mount the per-process file descriptors (/dev/fd)
78 fdesc_mount(struct mount
*mp
, const char *path
, void *data
, size_t *data_len
)
80 struct lwp
*l
= curlwp
;
84 if (mp
->mnt_flag
& MNT_GETARGS
) {
91 if (mp
->mnt_flag
& MNT_UPDATE
)
94 error
= fdesc_allocvp(Froot
, FD_ROOT
, mp
, &rvp
);
99 rvp
->v_vflag
|= VV_ROOT
;
100 mp
->mnt_stat
.f_namemax
= MAXNAMLEN
;
101 mp
->mnt_flag
|= MNT_LOCAL
;
105 error
= set_statvfs_info(path
, UIO_USERSPACE
, "fdesc", UIO_SYSSPACE
,
106 mp
->mnt_op
->vfs_name
, mp
, l
);
112 fdesc_start(struct mount
*mp
, int flags
)
118 fdesc_unmount(struct mount
*mp
, int mntflags
)
122 struct vnode
*rtvp
= mp
->mnt_data
;
124 if (mntflags
& MNT_FORCE
)
127 if (rtvp
->v_usecount
> 1 && (mntflags
& MNT_FORCE
) == 0)
129 if ((error
= vflush(mp
, rtvp
, flags
)) != 0)
133 * Blow it away for future re-use
142 fdesc_root(struct mount
*mp
, struct vnode
**vpp
)
147 * Return locked reference to root.
151 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
);
158 fdesc_sync(struct mount
*mp
, int waitfor
,
166 * Fdesc flat namespace lookup.
167 * Currently unsupported.
170 fdesc_vget(struct mount
*mp
, ino_t ino
,
177 extern const struct vnodeopv_desc fdesc_vnodeop_opv_desc
;
179 const struct vnodeopv_desc
* const fdesc_vnodeopv_descs
[] = {
180 &fdesc_vnodeop_opv_desc
,
184 struct vfsops fdesc_vfsops
= {
191 (void *)eopnotsupp
, /* vfs_quotactl */
195 (void *)eopnotsupp
, /* vfs_fhtovp */
196 (void *)eopnotsupp
, /* vfs_vptofh */
200 NULL
, /* vfs_mountroot */
201 (int (*)(struct mount
*, struct vnode
*, struct timespec
*)) eopnotsupp
,
203 (void *)eopnotsupp
, /* vfs_suspendctl */
204 genfs_renamelock_enter
,
205 genfs_renamelock_exit
,
207 fdesc_vnodeopv_descs
,
213 fdesc_modcmd(modcmd_t cmd
, void *arg
)
218 case MODULE_CMD_INIT
:
219 error
= vfs_attach(&fdesc_vfsops
);
222 sysctl_createv(&fdesc_sysctl_log
, 0, NULL
, NULL
,
224 CTLTYPE_NODE
, "vfs", NULL
,
227 sysctl_createv(&fdesc_sysctl_log
, 0, NULL
, NULL
,
229 CTLTYPE_NODE
, "fdesc",
230 SYSCTL_DESCR("File-descriptor file system"),
232 CTL_VFS
, 7, CTL_EOL
);
234 * XXX the "7" above could be dynamic, thereby eliminating one
235 * more instance of the "number to vfs" mapping problem, but
236 * "7" is the order as taken from sys/mount.h
239 case MODULE_CMD_FINI
:
240 error
= vfs_detach(&fdesc_vfsops
);
243 sysctl_teardown(&fdesc_sysctl_log
);