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