Home | History | Annotate | Line # | Download | only in procfs
procfs_vfsops.c revision 1.1.1.2
      1      1.1    pk /*
      2  1.1.1.1  fvdl  * Copyright (c) 1993 Jan-Simon Pendry
      3  1.1.1.1  fvdl  * Copyright (c) 1993
      4  1.1.1.1  fvdl  *	The Regents of the University of California.  All rights reserved.
      5  1.1.1.1  fvdl  *
      6  1.1.1.1  fvdl  * This code is derived from software contributed to Berkeley by
      7  1.1.1.1  fvdl  * Jan-Simon Pendry.
      8  1.1.1.1  fvdl  *
      9  1.1.1.1  fvdl  * Redistribution and use in source and binary forms, with or without
     10  1.1.1.1  fvdl  * modification, are permitted provided that the following conditions
     11  1.1.1.1  fvdl  * are met:
     12  1.1.1.1  fvdl  * 1. Redistributions of source code must retain the above copyright
     13  1.1.1.1  fvdl  *    notice, this list of conditions and the following disclaimer.
     14  1.1.1.1  fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1.1.1  fvdl  *    notice, this list of conditions and the following disclaimer in the
     16  1.1.1.1  fvdl  *    documentation and/or other materials provided with the distribution.
     17  1.1.1.1  fvdl  * 3. All advertising materials mentioning features or use of this software
     18  1.1.1.1  fvdl  *    must display the following acknowledgement:
     19  1.1.1.1  fvdl  *	This product includes software developed by the University of
     20  1.1.1.1  fvdl  *	California, Berkeley and its contributors.
     21  1.1.1.1  fvdl  * 4. Neither the name of the University nor the names of its contributors
     22  1.1.1.1  fvdl  *    may be used to endorse or promote products derived from this software
     23  1.1.1.1  fvdl  *    without specific prior written permission.
     24  1.1.1.1  fvdl  *
     25  1.1.1.1  fvdl  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  1.1.1.1  fvdl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.1.1.1  fvdl  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.1.1.1  fvdl  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  1.1.1.1  fvdl  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.1.1.1  fvdl  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.1.1.1  fvdl  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.1.1.1  fvdl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.1.1.1  fvdl  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.1.1.1  fvdl  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.1.1.1  fvdl  * SUCH DAMAGE.
     36  1.1.1.1  fvdl  *
     37  1.1.1.2  fvdl  *	@(#)procfs_vfsops.c	8.7 (Berkeley) 5/10/95
     38  1.1.1.1  fvdl  *
     39  1.1.1.1  fvdl  * From:
     40  1.1.1.1  fvdl  *	$Id: procfs_vfsops.c,v 1.1.1.2 1998/03/01 02:13:20 fvdl Exp $
     41      1.1    pk  */
     42      1.1    pk 
     43      1.1    pk /*
     44  1.1.1.1  fvdl  * procfs VFS interface
     45      1.1    pk  */
     46      1.1    pk 
     47  1.1.1.1  fvdl #include <sys/param.h>
     48  1.1.1.2  fvdl #include <sys/systm.h>
     49  1.1.1.1  fvdl #include <sys/time.h>
     50  1.1.1.1  fvdl #include <sys/kernel.h>
     51  1.1.1.1  fvdl #include <sys/proc.h>
     52  1.1.1.1  fvdl #include <sys/buf.h>
     53  1.1.1.1  fvdl #include <sys/syslog.h>
     54  1.1.1.1  fvdl #include <sys/mount.h>
     55  1.1.1.1  fvdl #include <sys/signalvar.h>
     56  1.1.1.1  fvdl #include <sys/vnode.h>
     57  1.1.1.1  fvdl #include <miscfs/procfs/procfs.h>
     58  1.1.1.1  fvdl #include <vm/vm.h>			/* for PAGE_SIZE */
     59      1.1    pk 
     60      1.1    pk /*
     61      1.1    pk  * VFS Operations.
     62      1.1    pk  *
     63      1.1    pk  * mount system call
     64      1.1    pk  */
     65      1.1    pk /* ARGSUSED */
     66  1.1.1.1  fvdl procfs_mount(mp, path, data, ndp, p)
     67  1.1.1.1  fvdl 	struct mount *mp;
     68      1.1    pk 	char *path;
     69      1.1    pk 	caddr_t data;
     70      1.1    pk 	struct nameidata *ndp;
     71      1.1    pk 	struct proc *p;
     72      1.1    pk {
     73      1.1    pk 	u_int size;
     74      1.1    pk 
     75  1.1.1.1  fvdl 	if (UIO_MX & (UIO_MX-1)) {
     76  1.1.1.1  fvdl 		log(LOG_ERR, "procfs: invalid directory entry size");
     77  1.1.1.1  fvdl 		return (EINVAL);
     78      1.1    pk 	}
     79      1.1    pk 
     80  1.1.1.1  fvdl 	if (mp->mnt_flag & MNT_UPDATE)
     81  1.1.1.1  fvdl 		return (EOPNOTSUPP);
     82  1.1.1.1  fvdl 
     83  1.1.1.1  fvdl 	mp->mnt_flag |= MNT_LOCAL;
     84  1.1.1.1  fvdl 	mp->mnt_data = 0;
     85  1.1.1.2  fvdl 	vfs_getnewfsid(mp);
     86  1.1.1.1  fvdl 
     87      1.1    pk 	(void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
     88      1.1    pk 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
     89      1.1    pk 
     90  1.1.1.1  fvdl 	size = sizeof("procfs") - 1;
     91  1.1.1.1  fvdl 	bcopy("procfs", mp->mnt_stat.f_mntfromname, size);
     92      1.1    pk 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
     93      1.1    pk 
     94      1.1    pk 	return (0);
     95      1.1    pk }
     96      1.1    pk 
     97      1.1    pk /*
     98      1.1    pk  * unmount system call
     99      1.1    pk  */
    100  1.1.1.1  fvdl procfs_unmount(mp, mntflags, p)
    101      1.1    pk 	struct mount *mp;
    102      1.1    pk 	int mntflags;
    103      1.1    pk 	struct proc *p;
    104      1.1    pk {
    105  1.1.1.1  fvdl 	int error;
    106  1.1.1.1  fvdl 	int flags = 0;
    107  1.1.1.1  fvdl 
    108  1.1.1.2  fvdl 	if (mntflags & MNT_FORCE)
    109  1.1.1.1  fvdl 		flags |= FORCECLOSE;
    110  1.1.1.1  fvdl 
    111  1.1.1.1  fvdl 	if (error = vflush(mp, 0, flags))
    112  1.1.1.1  fvdl 		return (error);
    113  1.1.1.1  fvdl 
    114      1.1    pk 	return (0);
    115      1.1    pk }
    116      1.1    pk 
    117  1.1.1.1  fvdl procfs_root(mp, vpp)
    118      1.1    pk 	struct mount *mp;
    119      1.1    pk 	struct vnode **vpp;
    120      1.1    pk {
    121      1.1    pk 
    122  1.1.1.2  fvdl 	return (procfs_allocvp(mp, vpp, 0, Proot));
    123      1.1    pk }
    124      1.1    pk 
    125      1.1    pk /* ARGSUSED */
    126  1.1.1.1  fvdl procfs_start(mp, flags, p)
    127      1.1    pk 	struct mount *mp;
    128      1.1    pk 	int flags;
    129      1.1    pk 	struct proc *p;
    130      1.1    pk {
    131  1.1.1.1  fvdl 
    132  1.1.1.1  fvdl 	return (0);
    133      1.1    pk }
    134      1.1    pk 
    135      1.1    pk /*
    136      1.1    pk  * Get file system statistics.
    137      1.1    pk  */
    138  1.1.1.1  fvdl procfs_statfs(mp, sbp, p)
    139      1.1    pk 	struct mount *mp;
    140      1.1    pk 	struct statfs *sbp;
    141      1.1    pk 	struct proc *p;
    142      1.1    pk {
    143  1.1.1.1  fvdl 	sbp->f_bsize = PAGE_SIZE;
    144  1.1.1.1  fvdl 	sbp->f_iosize = PAGE_SIZE;
    145  1.1.1.1  fvdl 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
    146  1.1.1.1  fvdl 	sbp->f_bfree = 0;
    147      1.1    pk 	sbp->f_bavail = 0;
    148  1.1.1.1  fvdl 	sbp->f_files = maxproc;			/* approx */
    149  1.1.1.1  fvdl 	sbp->f_ffree = maxproc - nprocs;	/* approx */
    150  1.1.1.1  fvdl 
    151  1.1.1.1  fvdl 	if (sbp != &mp->mnt_stat) {
    152  1.1.1.2  fvdl 		sbp->f_type = mp->mnt_vfc->vfc_typenum;
    153  1.1.1.1  fvdl 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
    154  1.1.1.1  fvdl 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
    155  1.1.1.1  fvdl 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
    156  1.1.1.1  fvdl 	}
    157      1.1    pk 
    158  1.1.1.1  fvdl 	return (0);
    159      1.1    pk }
    160      1.1    pk 
    161  1.1.1.2  fvdl procfs_init(vfsp)
    162  1.1.1.2  fvdl 	struct vfsconf *vfsp;
    163      1.1    pk {
    164  1.1.1.1  fvdl 
    165  1.1.1.1  fvdl 	return (0);
    166      1.1    pk }
    167      1.1    pk 
    168  1.1.1.2  fvdl #define procfs_fhtovp ((int (*) __P((struct mount *, struct fid *, \
    169  1.1.1.2  fvdl 	    struct mbuf *, struct vnode **, int *, struct ucred **)))einval)
    170  1.1.1.2  fvdl #define procfs_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
    171  1.1.1.2  fvdl 	    struct proc *)))eopnotsupp)
    172  1.1.1.2  fvdl #define procfs_sync ((int (*) __P((struct mount *, int, struct ucred *, \
    173  1.1.1.2  fvdl 	    struct proc *)))nullop)
    174  1.1.1.2  fvdl #define procfs_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
    175  1.1.1.2  fvdl 	    size_t, struct proc *)))eopnotsupp)
    176  1.1.1.2  fvdl #define procfs_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \
    177  1.1.1.2  fvdl 	    eopnotsupp)
    178  1.1.1.2  fvdl #define procfs_vptofh ((int (*) __P((struct vnode *, struct fid *)))einval)
    179  1.1.1.1  fvdl 
    180  1.1.1.1  fvdl struct vfsops procfs_vfsops = {
    181  1.1.1.1  fvdl 	procfs_mount,
    182  1.1.1.1  fvdl 	procfs_start,
    183  1.1.1.1  fvdl 	procfs_unmount,
    184  1.1.1.1  fvdl 	procfs_root,
    185  1.1.1.1  fvdl 	procfs_quotactl,
    186  1.1.1.1  fvdl 	procfs_statfs,
    187  1.1.1.1  fvdl 	procfs_sync,
    188  1.1.1.1  fvdl 	procfs_vget,
    189  1.1.1.1  fvdl 	procfs_fhtovp,
    190  1.1.1.1  fvdl 	procfs_vptofh,
    191  1.1.1.1  fvdl 	procfs_init,
    192  1.1.1.2  fvdl 	procfs_sysctl,
    193  1.1.1.1  fvdl };
    194