Annotation of src/sys/miscfs/fdesc/fdesc_vfsops.c, Revision 1.94
1.94 ! pgoyette 1: /* $NetBSD: fdesc_vfsops.c,v 1.93 2020/01/17 20:08:09 ad Exp $ */
1.13 cgd 2:
1.1 cgd 3: /*
1.24 fvdl 4: * Copyright (c) 1992, 1993, 1995
1.12 mycroft 5: * The Regents of the University of California. All rights reserved.
1.1 cgd 6: *
1.6 cgd 7: * This code is derived from software donated to Berkeley by
1.1 cgd 8: * Jan-Simon Pendry.
9: *
1.2 cgd 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. 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.
1.44 agc 18: * 3. Neither the name of the University nor the names of its contributors
1.2 cgd 19: * may be used to endorse or promote products derived from this software
20: * without specific prior written permission.
1.1 cgd 21: *
1.2 cgd 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
32: * SUCH DAMAGE.
1.1 cgd 33: *
1.24 fvdl 34: * @(#)fdesc_vfsops.c 8.10 (Berkeley) 5/14/95
1.15 mycroft 35: *
36: * #Id: fdesc_vfsops.c,v 1.9 1993/04/06 15:28:33 jsp Exp #
1.1 cgd 37: */
38:
39: /*
40: * /dev/fd Filesystem
41: */
1.35 lukem 42:
43: #include <sys/cdefs.h>
1.94 ! pgoyette 44: __KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.93 2020/01/17 20:08:09 ad Exp $");
1.25 jonathan 45:
1.33 mrg 46: #if defined(_KERNEL_OPT)
1.25 jonathan 47: #include "opt_compat_netbsd.h"
48: #endif
1.1 cgd 49:
1.6 cgd 50: #include <sys/param.h>
51: #include <sys/systm.h>
1.45 atatat 52: #include <sys/sysctl.h>
1.6 cgd 53: #include <sys/time.h>
54: #include <sys/proc.h>
55: #include <sys/resourcevar.h>
56: #include <sys/filedesc.h>
57: #include <sys/vnode.h>
58: #include <sys/mount.h>
1.48 christos 59: #include <sys/dirent.h>
1.6 cgd 60: #include <sys/namei.h>
1.59 elad 61: #include <sys/kauth.h>
1.75 rumble 62: #include <sys/module.h>
1.59 elad 63:
1.73 dholland 64: #include <miscfs/genfs/genfs.h>
1.6 cgd 65: #include <miscfs/fdesc/fdesc.h>
1.1 cgd 66:
1.75 rumble 67: MODULE(MODULE_CLASS_VFS, fdesc, NULL);
68:
1.69 pooka 69: VFS_PROTOS(fdesc);
1.21 christos 70:
1.77 rumble 71: static struct sysctllog *fdesc_sysctl_log;
72:
1.1 cgd 73: /*
74: * Mount the per-process file descriptors (/dev/fd)
75: */
1.12 mycroft 76: int
1.71 pooka 77: fdesc_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
1.1 cgd 78: {
1.71 pooka 79: struct lwp *l = curlwp;
1.89 hannken 80: int error = 0, ix;
1.1 cgd 81: struct vnode *rvp;
82:
1.66 dsl 83: if (mp->mnt_flag & MNT_GETARGS) {
84: *data_len = 0;
1.38 christos 85: return 0;
1.66 dsl 86: }
1.1 cgd 87: /*
88: * Update is a no-op
89: */
90: if (mp->mnt_flag & MNT_UPDATE)
91: return (EOPNOTSUPP);
92:
1.89 hannken 93: ix = FD_ROOT;
94: error = vcache_get(mp, &ix, sizeof(ix), &rvp);
1.1 cgd 95: if (error)
1.89 hannken 96: return error;
1.1 cgd 97:
1.86 christos 98: mp->mnt_stat.f_namemax = FDESC_MAXNAMLEN;
1.14 mycroft 99: mp->mnt_flag |= MNT_LOCAL;
1.82 pooka 100: mp->mnt_data = rvp;
1.31 assar 101: vfs_getnewfsid(mp);
1.1 cgd 102:
1.47 christos 103: error = set_statvfs_info(path, UIO_USERSPACE, "fdesc", UIO_SYSSPACE,
1.67 pooka 104: mp->mnt_op->vfs_name, mp, l);
1.39 christos 105: return error;
1.1 cgd 106: }
107:
1.12 mycroft 108: int
1.71 pooka 109: fdesc_start(struct mount *mp, int flags)
1.1 cgd 110: {
111: return (0);
112: }
113:
1.12 mycroft 114: int
1.71 pooka 115: fdesc_unmount(struct mount *mp, int mntflags)
1.1 cgd 116: {
117: int error;
118: int flags = 0;
1.82 pooka 119: struct vnode *rtvp = mp->mnt_data;
1.1 cgd 120:
1.24 fvdl 121: if (mntflags & MNT_FORCE)
1.1 cgd 122: flags |= FORCECLOSE;
123:
1.65 pooka 124: if (rtvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0)
1.1 cgd 125: return (EBUSY);
1.55 christos 126: if ((error = vflush(mp, rtvp, flags)) != 0)
1.1 cgd 127: return (error);
128:
129: /*
1.72 ad 130: * Blow it away for future re-use
1.1 cgd 131: */
1.55 christos 132: vgone(rtvp);
1.76 simonb 133: mp->mnt_data = NULL;
1.12 mycroft 134:
135: return (0);
1.1 cgd 136: }
137:
1.12 mycroft 138: int
1.93 ad 139: fdesc_root(struct mount *mp, int lktype, struct vnode **vpp)
1.1 cgd 140: {
141: struct vnode *vp;
142:
143: /*
144: * Return locked reference to root.
145: */
1.82 pooka 146: vp = mp->mnt_data;
1.84 pooka 147: vref(vp);
1.93 ad 148: vn_lock(vp, lktype | LK_RETRY);
1.1 cgd 149: *vpp = vp;
150: return (0);
151: }
152:
1.21 christos 153: /*ARGSUSED*/
1.12 mycroft 154: int
1.62 christos 155: fdesc_sync(struct mount *mp, int waitfor,
1.71 pooka 156: kauth_cred_t uc)
1.1 cgd 157: {
1.12 mycroft 158:
1.1 cgd 159: return (0);
160: }
161:
1.12 mycroft 162: /*
163: * Fdesc flat namespace lookup.
164: * Currently unsupported.
165: */
166: int
1.93 ad 167: fdesc_vget(struct mount *mp, ino_t ino, int lktype,
1.62 christos 168: struct vnode **vpp)
1.12 mycroft 169: {
170:
171: return (EOPNOTSUPP);
172: }
173:
1.89 hannken 174: int
175: fdesc_loadvnode(struct mount *mp, struct vnode *vp,
176: const void *key, size_t key_len, const void **new_key)
177: {
178: int ix;
179: struct fdescnode *fd;
180:
181: KASSERT(key_len == sizeof(ix));
182: memcpy(&ix, key, key_len);
183:
184: fd = kmem_alloc(sizeof(struct fdescnode), KM_SLEEP);
185: fd->fd_fd = -1;
186: fd->fd_link = NULL;
187: fd->fd_ix = ix;
188: fd->fd_vnode = vp;
189: vp->v_tag = VT_FDESC;
190: vp->v_op = fdesc_vnodeop_p;
191: vp->v_data = fd;
192: switch (ix) {
193: case FD_ROOT:
194: fd->fd_type = Froot;
195: vp->v_type = VDIR;
196: vp->v_vflag |= VV_ROOT;
197: break;
198: case FD_DEVFD:
199: fd->fd_type = Fdevfd;
200: vp->v_type = VDIR;
201: break;
202: case FD_CTTY:
203: fd->fd_type = Fctty;
1.90 christos 204: vp->v_type = VCHR;
1.89 hannken 205: break;
206: case FD_STDIN:
207: fd->fd_type = Flink;
208: fd->fd_link = "fd/0";
209: vp->v_type = VLNK;
210: break;
211: case FD_STDOUT:
212: fd->fd_type = Flink;
213: fd->fd_link = "fd/1";
214: vp->v_type = VLNK;
215: break;
216: case FD_STDERR:
217: fd->fd_type = Flink;
218: fd->fd_link = "fd/2";
219: vp->v_type = VLNK;
220: break;
221: default:
222: KASSERT(ix >= FD_DESC);
223: fd->fd_type = Fdesc;
224: fd->fd_fd = ix - FD_DESC;
225: vp->v_type = VNON;
226: break;
227: }
228: uvm_vnp_setsize(vp, 0);
229: *new_key = &fd->fd_ix;
230:
231: return 0;
232: }
233:
1.32 jdolecek 234: extern const struct vnodeopv_desc fdesc_vnodeop_opv_desc;
1.23 thorpej 235:
1.32 jdolecek 236: const struct vnodeopv_desc * const fdesc_vnodeopv_descs[] = {
1.23 thorpej 237: &fdesc_vnodeop_opv_desc,
238: NULL,
239: };
240:
1.1 cgd 241: struct vfsops fdesc_vfsops = {
1.88 hannken 242: .vfs_name = MOUNT_FDESC,
243: .vfs_min_mount_data = 0,
244: .vfs_mount = fdesc_mount,
245: .vfs_start = fdesc_start,
246: .vfs_unmount = fdesc_unmount,
247: .vfs_root = fdesc_root,
248: .vfs_quotactl = (void *)eopnotsupp,
249: .vfs_statvfs = genfs_statvfs,
250: .vfs_sync = fdesc_sync,
251: .vfs_vget = fdesc_vget,
1.89 hannken 252: .vfs_loadvnode = fdesc_loadvnode,
1.88 hannken 253: .vfs_fhtovp = (void *)eopnotsupp,
254: .vfs_vptofh = (void *)eopnotsupp,
255: .vfs_init = fdesc_init,
256: .vfs_done = fdesc_done,
257: .vfs_snapshot = (void *)eopnotsupp,
258: .vfs_extattrctl = vfs_stdextattrctl,
1.92 hannken 259: .vfs_suspendctl = genfs_suspendctl,
1.88 hannken 260: .vfs_renamelock_enter = genfs_renamelock_enter,
261: .vfs_renamelock_exit = genfs_renamelock_exit,
262: .vfs_fsync = (void *)eopnotsupp,
263: .vfs_opv_descs = fdesc_vnodeopv_descs
1.1 cgd 264: };
1.75 rumble 265:
1.94 ! pgoyette 266: SYSCTL_SETUP(fdesc_sysctl_setup, "fdesc sysctl")
1.75 rumble 267: {
268:
1.77 rumble 269: sysctl_createv(&fdesc_sysctl_log, 0, NULL, NULL,
270: CTLFLAG_PERMANENT,
271: CTLTYPE_NODE, "fdesc",
272: SYSCTL_DESCR("File-descriptor file system"),
273: NULL, 0, NULL, 0,
274: CTL_VFS, 7, CTL_EOL);
275: /*
276: * XXX the "7" above could be dynamic, thereby eliminating one
277: * more instance of the "number to vfs" mapping problem, but
278: * "7" is the order as taken from sys/mount.h
279: */
1.94 ! pgoyette 280: }
! 281:
! 282: static int
! 283: fdesc_modcmd(modcmd_t cmd, void *arg)
! 284: {
! 285: int error;
! 286:
! 287: switch (cmd) {
! 288: case MODULE_CMD_INIT:
! 289: error = vfs_attach(&fdesc_vfsops);
! 290: if (error != 0)
! 291: break;
1.77 rumble 292: break;
1.75 rumble 293: case MODULE_CMD_FINI:
1.77 rumble 294: error = vfs_detach(&fdesc_vfsops);
295: if (error != 0)
296: break;
297: break;
1.75 rumble 298: default:
1.77 rumble 299: error = ENOTTY;
300: break;
1.75 rumble 301: }
1.77 rumble 302:
303: return (error);
1.75 rumble 304: }
CVSweb <webmaster@jp.NetBSD.org>