Home | History | Annotate | Line # | Download | only in procfs
procfs_vfsops.c revision 1.46
      1 /*	$NetBSD: procfs_vfsops.c,v 1.46 2003/06/28 14:22:04 darrenr Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1993 Jan-Simon Pendry
      5  * Copyright (c) 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * Jan-Simon Pendry.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the University of
     22  *	California, Berkeley and its contributors.
     23  * 4. Neither the name of the University nor the names of its contributors
     24  *    may be used to endorse or promote products derived from this software
     25  *    without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  * SUCH DAMAGE.
     38  *
     39  *	@(#)procfs_vfsops.c	8.7 (Berkeley) 5/10/95
     40  */
     41 
     42 /*
     43  * procfs VFS interface
     44  */
     45 
     46 #include <sys/cdefs.h>
     47 __KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.46 2003/06/28 14:22:04 darrenr Exp $");
     48 
     49 #if defined(_KERNEL_OPT)
     50 #include "opt_compat_netbsd.h"
     51 #endif
     52 
     53 #include <sys/param.h>
     54 #include <sys/time.h>
     55 #include <sys/kernel.h>
     56 #include <sys/systm.h>
     57 #include <sys/proc.h>
     58 #include <sys/buf.h>
     59 #include <sys/syslog.h>
     60 #include <sys/mount.h>
     61 #include <sys/signalvar.h>
     62 #include <sys/vnode.h>
     63 #include <sys/malloc.h>
     64 
     65 #include <miscfs/procfs/procfs.h>
     66 
     67 #include <uvm/uvm_extern.h>			/* for PAGE_SIZE */
     68 
     69 void	procfs_init __P((void));
     70 void	procfs_reinit __P((void));
     71 void	procfs_done __P((void));
     72 int	procfs_mount __P((struct mount *, const char *, void *,
     73 			  struct nameidata *, struct lwp *));
     74 int	procfs_start __P((struct mount *, int, struct lwp *));
     75 int	procfs_unmount __P((struct mount *, int, struct lwp *));
     76 int	procfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
     77 			     struct lwp *));
     78 int	procfs_statfs __P((struct mount *, struct statfs *, struct lwp *));
     79 int	procfs_sync __P((struct mount *, int, struct ucred *, struct lwp *));
     80 int	procfs_vget __P((struct mount *, ino_t, struct vnode **, struct lwp *));
     81 int	procfs_fhtovp __P((struct mount *, struct fid *, struct vnode **, struct lwp *));
     82 int	procfs_checkexp __P((struct mount *, struct mbuf *, int *,
     83 			   struct ucred **));
     84 int	procfs_vptofh __P((struct vnode *, struct fid *));
     85 int	procfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
     86 			   struct lwp *));
     87 /*
     88  * VFS Operations.
     89  *
     90  * mount system call
     91  */
     92 /* ARGSUSED */
     93 int
     94 procfs_mount(mp, path, data, ndp, l)
     95 	struct mount *mp;
     96 	const char *path;
     97 	void *data;
     98 	struct nameidata *ndp;
     99 	struct lwp *l;
    100 {
    101 	struct procfsmount *pmnt;
    102 	struct procfs_args args;
    103 	int error;
    104 
    105 	if (UIO_MX & (UIO_MX-1)) {
    106 		log(LOG_ERR, "procfs: invalid directory entry size");
    107 		return (EINVAL);
    108 	}
    109 
    110 	if (mp->mnt_flag & MNT_GETARGS) {
    111 		pmnt = VFSTOPROC(mp);
    112 		if (pmnt == NULL)
    113 			return EIO;
    114 		args.version = PROCFS_ARGSVERSION;
    115 		args.flags = pmnt->pmnt_flags;
    116 		return copyout(&args, data, sizeof(args));
    117 	}
    118 
    119 	if (mp->mnt_flag & MNT_UPDATE)
    120 		return (EOPNOTSUPP);
    121 
    122 	if (data != NULL) {
    123 		error = copyin(data, &args, sizeof args);
    124 		if (error != 0)
    125 			return error;
    126 
    127 		if (args.version != PROCFS_ARGSVERSION)
    128 			return EINVAL;
    129 	} else
    130 		args.flags = 0;
    131 
    132 	mp->mnt_flag |= MNT_LOCAL;
    133 	pmnt = (struct procfsmount *) malloc(sizeof(struct procfsmount),
    134 	    M_UFSMNT, M_WAITOK);   /* XXX need new malloc type */
    135 
    136 	mp->mnt_data = pmnt;
    137 	vfs_getnewfsid(mp);
    138 
    139 	error = set_statfs_info(path, UIO_USERSPACE, "procfs", UIO_SYSSPACE,
    140 	    mp, l);
    141 	pmnt->pmnt_exechook = exechook_establish(procfs_revoke_vnodes, mp);
    142 	pmnt->pmnt_flags = args.flags;
    143 
    144 	return error;
    145 }
    146 
    147 /*
    148  * unmount system call
    149  */
    150 int
    151 procfs_unmount(mp, mntflags, l)
    152 	struct mount *mp;
    153 	int mntflags;
    154 	struct lwp *l;
    155 {
    156 	int error;
    157 	int flags = 0;
    158 
    159 	if (mntflags & MNT_FORCE)
    160 		flags |= FORCECLOSE;
    161 
    162 	if ((error = vflush(mp, 0, flags)) != 0)
    163 		return (error);
    164 
    165 	exechook_disestablish(VFSTOPROC(mp)->pmnt_exechook);
    166 
    167 	free(mp->mnt_data, M_UFSMNT);
    168 	mp->mnt_data = 0;
    169 
    170 	return (0);
    171 }
    172 
    173 int
    174 procfs_root(mp, vpp, l)
    175 	struct mount *mp;
    176 	struct vnode **vpp;
    177 	struct lwp *l;
    178 {
    179 
    180 	return (procfs_allocvp(mp, vpp, 0, Proot, -1));
    181 }
    182 
    183 /* ARGSUSED */
    184 int
    185 procfs_start(mp, flags, l)
    186 	struct mount *mp;
    187 	int flags;
    188 	struct lwp *l;
    189 {
    190 
    191 	return (0);
    192 }
    193 
    194 /*
    195  * Get file system statistics.
    196  */
    197 int
    198 procfs_statfs(mp, sbp, l)
    199 	struct mount *mp;
    200 	struct statfs *sbp;
    201 	struct lwp *l;
    202 {
    203 
    204 	sbp->f_bsize = PAGE_SIZE;
    205 	sbp->f_iosize = PAGE_SIZE;
    206 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
    207 	sbp->f_bfree = 0;
    208 	sbp->f_bavail = 0;
    209 	sbp->f_files = maxproc;			/* approx */
    210 	sbp->f_ffree = maxproc - nprocs;	/* approx */
    211 #ifdef COMPAT_09
    212 	sbp->f_type = 10;
    213 #else
    214 	sbp->f_type = 0;
    215 #endif
    216 	copy_statfs_info(sbp, mp);
    217 	return (0);
    218 }
    219 
    220 /*ARGSUSED*/
    221 int
    222 procfs_quotactl(mp, cmds, uid, arg, l)
    223 	struct mount *mp;
    224 	int cmds;
    225 	uid_t uid;
    226 	caddr_t arg;
    227 	struct lwp *l;
    228 {
    229 
    230 	return (EOPNOTSUPP);
    231 }
    232 
    233 /*ARGSUSED*/
    234 int
    235 procfs_sync(mp, waitfor, uc, l)
    236 	struct mount *mp;
    237 	int waitfor;
    238 	struct ucred *uc;
    239 	struct lwp *l;
    240 {
    241 
    242 	return (0);
    243 }
    244 
    245 /*ARGSUSED*/
    246 int
    247 procfs_vget(mp, ino, vpp, l)
    248 	struct mount *mp;
    249 	ino_t ino;
    250 	struct vnode **vpp;
    251 	struct lwp *l;
    252 {
    253 	return (EOPNOTSUPP);
    254 }
    255 
    256 /*ARGSUSED*/
    257 int
    258 procfs_fhtovp(mp, fhp, vpp, l)
    259 	struct mount *mp;
    260 	struct fid *fhp;
    261 	struct vnode **vpp;
    262 	struct lwp *l;
    263 {
    264 
    265 	return (EINVAL);
    266 }
    267 
    268 /*ARGSUSED*/
    269 int
    270 procfs_checkexp(mp, mb, what, anon)
    271 	struct mount *mp;
    272 	struct mbuf *mb;
    273 	int *what;
    274 	struct ucred **anon;
    275 {
    276 
    277 	return (EINVAL);
    278 }
    279 
    280 /*ARGSUSED*/
    281 int
    282 procfs_vptofh(vp, fhp)
    283 	struct vnode *vp;
    284 	struct fid *fhp;
    285 {
    286 
    287 	return (EINVAL);
    288 }
    289 
    290 void
    291 procfs_init()
    292 {
    293 	procfs_hashinit();
    294 }
    295 
    296 void
    297 procfs_reinit()
    298 {
    299 	procfs_hashreinit();
    300 }
    301 
    302 void
    303 procfs_done()
    304 {
    305 	procfs_hashdone();
    306 }
    307 
    308 int
    309 procfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, l)
    310 	int *name;
    311 	u_int namelen;
    312 	void *oldp;
    313 	size_t *oldlenp;
    314 	void *newp;
    315 	size_t newlen;
    316 	struct lwp *l;
    317 {
    318 	return (EOPNOTSUPP);
    319 }
    320 
    321 extern const struct vnodeopv_desc procfs_vnodeop_opv_desc;
    322 
    323 const struct vnodeopv_desc * const procfs_vnodeopv_descs[] = {
    324 	&procfs_vnodeop_opv_desc,
    325 	NULL,
    326 };
    327 
    328 struct vfsops procfs_vfsops = {
    329 	MOUNT_PROCFS,
    330 	procfs_mount,
    331 	procfs_start,
    332 	procfs_unmount,
    333 	procfs_root,
    334 	procfs_quotactl,
    335 	procfs_statfs,
    336 	procfs_sync,
    337 	procfs_vget,
    338 	procfs_fhtovp,
    339 	procfs_vptofh,
    340 	procfs_init,
    341 	procfs_reinit,
    342 	procfs_done,
    343 	procfs_sysctl,
    344 	NULL,				/* vfs_mountroot */
    345 	procfs_checkexp,
    346 	procfs_vnodeopv_descs,
    347 };
    348