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