Home | History | Annotate | Line # | Download | only in procfs
procfs_vfsops.c revision 1.11
      1 /*
      2  * Copyright (c) 1993 The Regents of the University of California.
      3  * Copyright (c) 1993 Jan-Simon Pendry
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to Berkeley by
      7  * Jan-Simon Pendry.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by the University of
     20  *	California, Berkeley and its contributors.
     21  * 4. Neither the name of the University nor the names of its contributors
     22  *    may be used to endorse or promote products derived from this software
     23  *    without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  * From:
     38  *	Id: procfs_vfsops.c,v 4.1 1993/12/17 10:47:45 jsp Rel
     39  *
     40  *	$Id: procfs_vfsops.c,v 1.11 1994/01/20 21:23:08 ws Exp $
     41  */
     42 
     43 /*
     44  * procfs VFS interface
     45  */
     46 
     47 #include <sys/param.h>
     48 #include <sys/time.h>
     49 #include <sys/kernel.h>
     50 #include <sys/proc.h>
     51 #include <sys/resourcevar.h>
     52 #include <sys/buf.h>
     53 #include <sys/syslog.h>
     54 #include <sys/mount.h>
     55 #include <sys/signalvar.h>
     56 #include <sys/vnode.h>
     57 #include <miscfs/procfs/procfs.h>
     58 #include <vm/vm.h>			/* for page_size */
     59 
     60 /*
     61  * VFS Operations.
     62  *
     63  * mount system call
     64  */
     65 /* ARGSUSED */
     66 procfs_mount(mp, path, data, ndp, p)
     67 	struct mount *mp;
     68 	char *path;
     69 	caddr_t data;
     70 	struct nameidata *ndp;
     71 	struct proc *p;
     72 {
     73 	u_int size;
     74 	int error;
     75 
     76 	if (UIO_MX & (UIO_MX-1)) {
     77 		log(LOG_ERR, "procfs: invalid directory entry size");
     78 		return (EINVAL);
     79 	}
     80 
     81 	if (mp->mnt_flag & MNT_UPDATE)
     82 		return (EOPNOTSUPP);
     83 
     84 	mp->mnt_flag |= MNT_LOCAL;
     85 	mp->mnt_data = 0;
     86 	getnewfsid(mp, MOUNT_PROCFS);
     87 
     88 	(void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
     89 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
     90 
     91 	size = sizeof("proc") - 1;
     92 	bcopy("proc", mp->mnt_stat.f_mntfromname, size);
     93 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
     94 
     95 	return (0);
     96 }
     97 
     98 /*
     99  * unmount system call
    100  */
    101 procfs_unmount(mp, mntflags, p)
    102 	struct mount *mp;
    103 	int mntflags;
    104 	struct proc *p;
    105 {
    106 	int error;
    107 	extern int doforce;
    108 	int flags = 0;
    109 
    110 	if (mntflags & MNT_FORCE) {
    111 		/* procfs can never be rootfs so don't check for it */
    112 		if (!doforce)
    113 			return (EINVAL);
    114 		flags |= FORCECLOSE;
    115 	}
    116 
    117 	/*
    118 	 * Clear out buffer cache.  I don't think we
    119 	 * ever get anything cached at this level at the
    120 	 * moment, but who knows...
    121 	 */
    122 	mntflushbuf(mp, 0);
    123 
    124 	if (mntinvalbuf(mp, 1))
    125 		return (EBUSY);
    126 
    127 	if (error = vflush(mp, 0, flags))
    128 		return (error);
    129 
    130 	return (0);
    131 }
    132 
    133 procfs_root(mp, vpp)
    134 	struct mount *mp;
    135 	struct vnode **vpp;
    136 {
    137 	struct vnode *vp;
    138 	int error;
    139 
    140 	error = procfs_allocvp(mp, &vp, (pid_t) 0, Proot);
    141 	if (error)
    142 		return (error);
    143 
    144 	*vpp = vp;
    145 	return (0);
    146 }
    147 
    148 /*
    149  */
    150 /* ARGSUSED */
    151 procfs_start(mp, flags, p)
    152 	struct mount *mp;
    153 	int flags;
    154 	struct proc *p;
    155 {
    156 
    157 	return (0);
    158 }
    159 
    160 /*
    161  * Get file system statistics.
    162  */
    163 procfs_statfs(mp, sbp, p)
    164 	struct mount *mp;
    165 	struct statfs *sbp;
    166 	struct proc *p;
    167 {
    168 	sbp->f_type = MOUNT_PROCFS;
    169 	sbp->f_fsize = page_size >> 2;
    170 	sbp->f_bsize = page_size;
    171 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
    172 	sbp->f_bfree = 0;
    173 	sbp->f_bavail = 0;
    174 	sbp->f_files = maxproc;			/* approx */
    175 	sbp->f_ffree = maxproc - nprocs;	/* approx */
    176 
    177 	if (sbp != &mp->mnt_stat) {
    178 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
    179 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
    180 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
    181 	}
    182 
    183 	return (0);
    184 }
    185 
    186 
    187 procfs_quotactl(mp, cmds, uid, arg, p)
    188 	struct mount *mp;
    189 	int cmds;
    190 	uid_t uid;
    191 	caddr_t arg;
    192 	struct proc *p;
    193 {
    194 
    195 	return (EOPNOTSUPP);
    196 }
    197 
    198 procfs_sync(mp, waitfor)
    199 	struct mount *mp;
    200 	int waitfor;
    201 {
    202 
    203 	return (0);
    204 }
    205 
    206 procfs_fhtovp(mp, fhp, vpp)
    207 	struct mount *mp;
    208 	struct fid *fhp;
    209 	struct vnode **vpp;
    210 {
    211 	/*
    212 	 * NFS mounting of procfs doesn't work correctly.
    213 	 * The files in procfs are more similar to devices
    214 	 * than to regular files.
    215 	 */
    216 	return EOPNOTSUPP;
    217 }
    218 
    219 procfs_vptofh(vp, fhp)
    220 	struct vnode *vp;
    221 	struct fid *fhp;
    222 {
    223 	/*
    224 	 * NFS mounting of procfs doesn't work correctly.
    225 	 * The files in procfs are more similar to devices
    226 	 * than to regular files.
    227 	 */
    228 	return EOPNOTSUPP;
    229 }
    230 
    231 procfs_init()
    232 {
    233 
    234 	return (0);
    235 }
    236 
    237 struct vfsops procfs_vfsops = {
    238 	procfs_mount,
    239 	procfs_start,
    240 	procfs_unmount,
    241 	procfs_root,
    242 	procfs_quotactl,
    243 	procfs_statfs,
    244 	procfs_sync,
    245 	procfs_fhtovp,
    246 	procfs_vptofh,
    247 	procfs_init,
    248 };
    249