Home | History | Annotate | Line # | Download | only in procfs
procfs_vfsops.c revision 1.26
      1 /*	$NetBSD: procfs_vfsops.c,v 1.26 1996/12/22 10:10:27 cgd 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.5 (Berkeley) 6/15/94
     40  */
     41 
     42 /*
     43  * procfs VFS interface
     44  */
     45 
     46 #include <sys/param.h>
     47 #include <sys/time.h>
     48 #include <sys/kernel.h>
     49 #include <sys/systm.h>
     50 #include <sys/proc.h>
     51 #include <sys/buf.h>
     52 #include <sys/syslog.h>
     53 #include <sys/mount.h>
     54 #include <sys/signalvar.h>
     55 #include <sys/vnode.h>
     56 #include <miscfs/procfs/procfs.h>
     57 #include <vm/vm.h>			/* for PAGE_SIZE */
     58 
     59 int	procfs_mount __P((struct mount *, const char *, void *,
     60 			  struct nameidata *, struct proc *));
     61 int	procfs_start __P((struct mount *, int, struct proc *));
     62 int	procfs_unmount __P((struct mount *, int, struct proc *));
     63 int	procfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
     64 			     struct proc *));
     65 int	procfs_statfs __P((struct mount *, struct statfs *, struct proc *));
     66 int	procfs_sync __P((struct mount *, int, struct ucred *, struct proc *));
     67 int	procfs_vget __P((struct mount *, ino_t, struct vnode **));
     68 int	procfs_fhtovp __P((struct mount *, struct fid *, struct mbuf *,
     69 			   struct vnode **, int *, struct ucred **));
     70 int	procfs_vptofh __P((struct vnode *, struct fid *));
     71 /*
     72  * VFS Operations.
     73  *
     74  * mount system call
     75  */
     76 /* ARGSUSED */
     77 int
     78 procfs_mount(mp, path, data, ndp, p)
     79 	struct mount *mp;
     80 	const char *path;
     81 	void *data;
     82 	struct nameidata *ndp;
     83 	struct proc *p;
     84 {
     85 	size_t size;
     86 
     87 	if (UIO_MX & (UIO_MX-1)) {
     88 		log(LOG_ERR, "procfs: invalid directory entry size");
     89 		return (EINVAL);
     90 	}
     91 
     92 	if (mp->mnt_flag & MNT_UPDATE)
     93 		return (EOPNOTSUPP);
     94 
     95 	mp->mnt_flag |= MNT_LOCAL;
     96 	mp->mnt_data = 0;
     97 	getnewfsid(mp, makefstype(MOUNT_PROCFS));
     98 
     99 	(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN, &size);
    100 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
    101 	bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
    102 	bcopy("procfs", mp->mnt_stat.f_mntfromname, sizeof("procfs"));
    103 	return (0);
    104 }
    105 
    106 /*
    107  * unmount system call
    108  */
    109 int
    110 procfs_unmount(mp, mntflags, p)
    111 	struct mount *mp;
    112 	int mntflags;
    113 	struct proc *p;
    114 {
    115 	int error;
    116 	extern int doforce;
    117 	int flags = 0;
    118 
    119 	if (mntflags & MNT_FORCE) {
    120 		/* procfs can never be rootfs so don't check for it */
    121 		if (!doforce)
    122 			return (EINVAL);
    123 		flags |= FORCECLOSE;
    124 	}
    125 
    126 	if ((error = vflush(mp, 0, flags)) != 0)
    127 		return (error);
    128 
    129 	return (0);
    130 }
    131 
    132 int
    133 procfs_root(mp, vpp)
    134 	struct mount *mp;
    135 	struct vnode **vpp;
    136 {
    137 
    138 	return (procfs_allocvp(mp, vpp, 0, Proot));
    139 }
    140 
    141 /* ARGSUSED */
    142 int
    143 procfs_start(mp, flags, p)
    144 	struct mount *mp;
    145 	int flags;
    146 	struct proc *p;
    147 {
    148 
    149 	return (0);
    150 }
    151 
    152 /*
    153  * Get file system statistics.
    154  */
    155 int
    156 procfs_statfs(mp, sbp, p)
    157 	struct mount *mp;
    158 	struct statfs *sbp;
    159 	struct proc *p;
    160 {
    161 
    162 #ifdef COMPAT_09
    163 	sbp->f_type = 10;
    164 #else
    165 	sbp->f_type = 0;
    166 #endif
    167 	sbp->f_bsize = PAGE_SIZE;
    168 	sbp->f_iosize = PAGE_SIZE;
    169 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
    170 	sbp->f_bfree = 0;
    171 	sbp->f_bavail = 0;
    172 	sbp->f_files = maxproc;			/* approx */
    173 	sbp->f_ffree = maxproc - nprocs;	/* approx */
    174 	if (sbp != &mp->mnt_stat) {
    175 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
    176 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
    177 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
    178 	}
    179 	strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
    180 	return (0);
    181 }
    182 
    183 /*ARGSUSED*/
    184 int
    185 procfs_quotactl(mp, cmds, uid, arg, p)
    186 	struct mount *mp;
    187 	int cmds;
    188 	uid_t uid;
    189 	caddr_t arg;
    190 	struct proc *p;
    191 {
    192 
    193 	return (EOPNOTSUPP);
    194 }
    195 
    196 /*ARGSUSED*/
    197 int
    198 procfs_sync(mp, waitfor, uc, p)
    199 	struct mount *mp;
    200 	int waitfor;
    201 	struct ucred *uc;
    202 	struct proc *p;
    203 {
    204 
    205 	return (0);
    206 }
    207 
    208 /*ARGSUSED*/
    209 int
    210 procfs_vget(mp, ino, vpp)
    211 	struct mount *mp;
    212 	ino_t ino;
    213 	struct vnode **vpp;
    214 {
    215 
    216 	return (EOPNOTSUPP);
    217 }
    218 
    219 /*ARGSUSED*/
    220 int
    221 procfs_fhtovp(mp, fhp, mb, vpp, what, anon)
    222 	struct mount *mp;
    223 	struct fid *fhp;
    224 	struct mbuf *mb;
    225 	struct vnode **vpp;
    226 	int *what;
    227 	struct ucred **anon;
    228 {
    229 
    230 	return (EINVAL);
    231 }
    232 
    233 /*ARGSUSED*/
    234 int
    235 procfs_vptofh(vp, fhp)
    236 	struct vnode *vp;
    237 	struct fid *fhp;
    238 {
    239 
    240 	return (EINVAL);
    241 }
    242 
    243 void
    244 procfs_init()
    245 {
    246 }
    247 
    248 struct vfsops procfs_vfsops = {
    249 	MOUNT_PROCFS,
    250 	procfs_mount,
    251 	procfs_start,
    252 	procfs_unmount,
    253 	procfs_root,
    254 	procfs_quotactl,
    255 	procfs_statfs,
    256 	procfs_sync,
    257 	procfs_vget,
    258 	procfs_fhtovp,
    259 	procfs_vptofh,
    260 	procfs_init,
    261 };
    262