Annotation of src/sys/miscfs/fdesc/fdesc_vfsops.c, Revision 1.33.2.3
1.33.2.3! jdolecek 1: /* $NetBSD: fdesc_vfsops.c,v 1.33.2.2 2002/09/06 08:48:34 jdolecek 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.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
1.6 cgd 20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
1.2 cgd 22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
1.1 cgd 25: *
1.2 cgd 26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
1.1 cgd 37: *
1.24 fvdl 38: * @(#)fdesc_vfsops.c 8.10 (Berkeley) 5/14/95
1.15 mycroft 39: *
40: * #Id: fdesc_vfsops.c,v 1.9 1993/04/06 15:28:33 jsp Exp #
1.1 cgd 41: */
42:
43: /*
44: * /dev/fd Filesystem
45: */
1.25 jonathan 46:
1.33.2.1 thorpej 47: #include <sys/cdefs.h>
1.33.2.3! jdolecek 48: __KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.33.2.2 2002/09/06 08:48:34 jdolecek Exp $");
1.33.2.1 thorpej 49:
1.33 mrg 50: #if defined(_KERNEL_OPT)
1.25 jonathan 51: #include "opt_compat_netbsd.h"
52: #endif
1.1 cgd 53:
1.6 cgd 54: #include <sys/param.h>
55: #include <sys/systm.h>
56: #include <sys/time.h>
57: #include <sys/proc.h>
58: #include <sys/resourcevar.h>
59: #include <sys/filedesc.h>
60: #include <sys/vnode.h>
61: #include <sys/mount.h>
62: #include <sys/namei.h>
63: #include <sys/malloc.h>
64: #include <miscfs/fdesc/fdesc.h>
1.1 cgd 65:
1.22 cgd 66: int fdesc_mount __P((struct mount *, const char *, void *,
1.21 christos 67: struct nameidata *, struct proc *));
68: int fdesc_start __P((struct mount *, int, struct proc *));
69: int fdesc_unmount __P((struct mount *, int, struct proc *));
70: int fdesc_quotactl __P((struct mount *, int, uid_t, caddr_t,
71: struct proc *));
72: int fdesc_statfs __P((struct mount *, struct statfs *, struct proc *));
73: int fdesc_sync __P((struct mount *, int, struct ucred *, struct proc *));
74: int fdesc_vget __P((struct mount *, ino_t, struct vnode **));
1.27 wrstuden 75: int fdesc_fhtovp __P((struct mount *, struct fid *, struct vnode **));
76: int fdesc_checkexp __P((struct mount *, struct mbuf *, int *,
77: struct ucred **));
1.21 christos 78: int fdesc_vptofh __P((struct vnode *, struct fid *));
1.24 fvdl 79: int fdesc_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
80: struct proc *));
1.21 christos 81:
1.1 cgd 82: /*
83: * Mount the per-process file descriptors (/dev/fd)
84: */
1.12 mycroft 85: int
1.1 cgd 86: fdesc_mount(mp, path, data, ndp, p)
87: struct mount *mp;
1.22 cgd 88: const char *path;
89: void *data;
1.1 cgd 90: struct nameidata *ndp;
91: struct proc *p;
92: {
93: int error = 0;
1.19 mycroft 94: size_t size;
1.1 cgd 95: struct fdescmount *fmp;
96: struct vnode *rvp;
97:
1.33.2.3! jdolecek 98: if (mp->mnt_flag & MNT_GETARGS)
! 99: return 0;
1.1 cgd 100: /*
101: * Update is a no-op
102: */
103: if (mp->mnt_flag & MNT_UPDATE)
104: return (EOPNOTSUPP);
105:
1.6 cgd 106: error = fdesc_allocvp(Froot, FD_ROOT, mp, &rvp);
1.1 cgd 107: if (error)
108: return (error);
109:
1.6 cgd 110: MALLOC(fmp, struct fdescmount *, sizeof(struct fdescmount),
1.12 mycroft 111: M_UFSMNT, M_WAITOK); /* XXX */
1.1 cgd 112: rvp->v_type = VDIR;
113: rvp->v_flag |= VROOT;
114: fmp->f_root = rvp;
1.14 mycroft 115: mp->mnt_flag |= MNT_LOCAL;
1.33.2.2 jdolecek 116: mp->mnt_data = fmp;
1.31 assar 117: vfs_getnewfsid(mp);
1.1 cgd 118:
119: (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
1.26 perry 120: memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
121: memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
122: memcpy(mp->mnt_stat.f_mntfromname, "fdesc", sizeof("fdesc"));
1.28 wrstuden 123: VOP_UNLOCK(rvp, 0);
1.1 cgd 124: return (0);
125: }
126:
1.12 mycroft 127: int
1.1 cgd 128: fdesc_start(mp, flags, p)
129: struct mount *mp;
130: int flags;
131: struct proc *p;
132: {
133: return (0);
134: }
135:
1.12 mycroft 136: int
1.1 cgd 137: fdesc_unmount(mp, mntflags, p)
138: struct mount *mp;
139: int mntflags;
140: struct proc *p;
141: {
142: int error;
143: int flags = 0;
144: struct vnode *rootvp = VFSTOFDESC(mp)->f_root;
145:
1.24 fvdl 146: if (mntflags & MNT_FORCE)
1.1 cgd 147: flags |= FORCECLOSE;
148:
149: /*
150: * Clear out buffer cache. I don't think we
151: * ever get anything cached at this level at the
152: * moment, but who knows...
153: */
154: if (rootvp->v_usecount > 1)
155: return (EBUSY);
1.21 christos 156: if ((error = vflush(mp, rootvp, flags)) != 0)
1.1 cgd 157: return (error);
158:
159: /*
160: * Release reference on underlying root vnode
161: */
162: vrele(rootvp);
163: /*
164: * And blow it away for future re-use
165: */
166: vgone(rootvp);
167: /*
168: * Finally, throw away the fdescmount structure
169: */
1.12 mycroft 170: free(mp->mnt_data, M_UFSMNT); /* XXX */
1.1 cgd 171: mp->mnt_data = 0;
1.12 mycroft 172:
173: return (0);
1.1 cgd 174: }
175:
1.12 mycroft 176: int
1.1 cgd 177: fdesc_root(mp, vpp)
178: struct mount *mp;
179: struct vnode **vpp;
180: {
181: struct vnode *vp;
182:
183: /*
184: * Return locked reference to root.
185: */
186: vp = VFSTOFDESC(mp)->f_root;
187: VREF(vp);
1.24 fvdl 188: vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1.1 cgd 189: *vpp = vp;
190: return (0);
191: }
192:
1.12 mycroft 193: int
1.1 cgd 194: fdesc_quotactl(mp, cmd, uid, arg, p)
195: struct mount *mp;
196: int cmd;
197: uid_t uid;
198: caddr_t arg;
199: struct proc *p;
200: {
1.12 mycroft 201:
1.1 cgd 202: return (EOPNOTSUPP);
203: }
204:
1.12 mycroft 205: int
1.1 cgd 206: fdesc_statfs(mp, sbp, p)
207: struct mount *mp;
208: struct statfs *sbp;
209: struct proc *p;
210: {
211: struct filedesc *fdp;
212: int lim;
213: int i;
214: int last;
215: int freefd;
216:
217: /*
218: * Compute number of free file descriptors.
219: * [ Strange results will ensue if the open file
220: * limit is ever reduced below the current number
221: * of open files... ]
222: */
1.5 mycroft 223: lim = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
1.1 cgd 224: fdp = p->p_fd;
225: last = min(fdp->fd_nfiles, lim);
226: freefd = 0;
227: for (i = fdp->fd_freefile; i < last; i++)
228: if (fdp->fd_ofiles[i] == NULL)
229: freefd++;
230:
231: /*
232: * Adjust for the fact that the fdesc array may not
233: * have been fully allocated yet.
234: */
235: if (fdp->fd_nfiles < lim)
236: freefd += (lim - fdp->fd_nfiles);
237:
238: sbp->f_bsize = DEV_BSIZE;
1.10 cgd 239: sbp->f_iosize = DEV_BSIZE;
1.1 cgd 240: sbp->f_blocks = 2; /* 1K to keep df happy */
241: sbp->f_bfree = 0;
242: sbp->f_bavail = 0;
243: sbp->f_files = lim + 1; /* Allow for "." */
244: sbp->f_ffree = freefd; /* See comments above */
1.24 fvdl 245: #ifdef COMPAT_09
246: sbp->f_type = 6;
247: #else
248: sbp->f_type = 0;
249: #endif
1.1 cgd 250: if (sbp != &mp->mnt_stat) {
1.26 perry 251: memcpy(&sbp->f_fsid, &mp->mnt_stat.f_fsid, sizeof(sbp->f_fsid));
252: memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
253: memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
1.1 cgd 254: }
1.17 mycroft 255: strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
1.1 cgd 256: return (0);
257: }
258:
1.21 christos 259: /*ARGSUSED*/
1.12 mycroft 260: int
1.21 christos 261: fdesc_sync(mp, waitfor, uc, p)
1.1 cgd 262: struct mount *mp;
263: int waitfor;
1.21 christos 264: struct ucred *uc;
265: struct proc *p;
1.1 cgd 266: {
1.12 mycroft 267:
1.1 cgd 268: return (0);
269: }
270:
1.12 mycroft 271: /*
272: * Fdesc flat namespace lookup.
273: * Currently unsupported.
274: */
275: int
276: fdesc_vget(mp, ino, vpp)
277: struct mount *mp;
278: ino_t ino;
279: struct vnode **vpp;
280: {
281:
282: return (EOPNOTSUPP);
283: }
284:
1.21 christos 285:
286: /*ARGSUSED*/
1.12 mycroft 287: int
1.27 wrstuden 288: fdesc_fhtovp(mp, fhp, vpp)
1.1 cgd 289: struct mount *mp;
290: struct fid *fhp;
1.27 wrstuden 291: struct vnode **vpp;
292: {
293:
294: return (EOPNOTSUPP);
295: }
296:
297: /*ARGSUSED*/
298: int
299: fdesc_checkexp(mp, nam, exflagsp, credanonp)
300: struct mount *mp;
1.21 christos 301: struct mbuf *nam;
302: int *exflagsp;
303: struct ucred **credanonp;
1.1 cgd 304: {
1.21 christos 305:
1.1 cgd 306: return (EOPNOTSUPP);
307: }
308:
1.21 christos 309: /*ARGSUSED*/
1.12 mycroft 310: int
1.1 cgd 311: fdesc_vptofh(vp, fhp)
312: struct vnode *vp;
313: struct fid *fhp;
314: {
315: return (EOPNOTSUPP);
316: }
317:
1.24 fvdl 318: int
319: fdesc_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
320: int *name;
321: u_int namelen;
322: void *oldp;
323: size_t *oldlenp;
324: void *newp;
325: size_t newlen;
326: struct proc *p;
327: {
328: return (EOPNOTSUPP);
329: }
330:
1.32 jdolecek 331: extern const struct vnodeopv_desc fdesc_vnodeop_opv_desc;
1.23 thorpej 332:
1.32 jdolecek 333: const struct vnodeopv_desc * const fdesc_vnodeopv_descs[] = {
1.23 thorpej 334: &fdesc_vnodeop_opv_desc,
335: NULL,
336: };
337:
1.1 cgd 338: struct vfsops fdesc_vfsops = {
1.9 cgd 339: MOUNT_FDESC,
1.1 cgd 340: fdesc_mount,
341: fdesc_start,
342: fdesc_unmount,
343: fdesc_root,
344: fdesc_quotactl,
345: fdesc_statfs,
346: fdesc_sync,
1.12 mycroft 347: fdesc_vget,
1.1 cgd 348: fdesc_fhtovp,
349: fdesc_vptofh,
350: fdesc_init,
1.33.2.1 thorpej 351: NULL,
1.29 jdolecek 352: fdesc_done,
1.24 fvdl 353: fdesc_sysctl,
1.23 thorpej 354: NULL, /* vfs_mountroot */
1.27 wrstuden 355: fdesc_checkexp,
1.23 thorpej 356: fdesc_vnodeopv_descs,
1.1 cgd 357: };
CVSweb <webmaster@jp.NetBSD.org>