Home | History | Annotate | Line # | Download | only in procfs
procfs_vfsops.c revision 1.48.2.1
      1  1.48.2.1   darrenr /*	$NetBSD: procfs_vfsops.c,v 1.48.2.1 2003/07/02 15:26:53 darrenr 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.41     lukem 
     46      1.41     lukem #include <sys/cdefs.h>
     47  1.48.2.1   darrenr __KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.48.2.1 2003/07/02 15:26:53 darrenr Exp $");
     48      1.29  jonathan 
     49      1.39       mrg #if defined(_KERNEL_OPT)
     50      1.29  jonathan #include "opt_compat_netbsd.h"
     51      1.29  jonathan #endif
     52       1.1        pk 
     53       1.8   mycroft #include <sys/param.h>
     54       1.8   mycroft #include <sys/time.h>
     55       1.8   mycroft #include <sys/kernel.h>
     56      1.25  christos #include <sys/systm.h>
     57       1.8   mycroft #include <sys/proc.h>
     58       1.8   mycroft #include <sys/buf.h>
     59       1.9       cgd #include <sys/syslog.h>
     60       1.8   mycroft #include <sys/mount.h>
     61       1.8   mycroft #include <sys/signalvar.h>
     62       1.8   mycroft #include <sys/vnode.h>
     63      1.32      fvdl #include <sys/malloc.h>
     64      1.35       mrg 
     65       1.9       cgd #include <miscfs/procfs/procfs.h>
     66      1.35       mrg 
     67      1.35       mrg #include <uvm/uvm_extern.h>			/* for PAGE_SIZE */
     68       1.1        pk 
     69      1.28      fvdl void	procfs_init __P((void));
     70      1.40       chs void	procfs_reinit __P((void));
     71      1.33  jdolecek void	procfs_done __P((void));
     72      1.26       cgd int	procfs_mount __P((struct mount *, const char *, void *,
     73  1.48.2.1   darrenr 			  struct nameidata *, struct lwp *));
     74  1.48.2.1   darrenr int	procfs_start __P((struct mount *, int, struct lwp *));
     75  1.48.2.1   darrenr int	procfs_unmount __P((struct mount *, int, struct lwp *));
     76      1.25  christos int	procfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
     77  1.48.2.1   darrenr 			     struct lwp *));
     78  1.48.2.1   darrenr int	procfs_statfs __P((struct mount *, struct statfs *, struct lwp *));
     79  1.48.2.1   darrenr int	procfs_sync __P((struct mount *, int, struct ucred *, struct lwp *));
     80  1.48.2.1   darrenr int	procfs_vget __P((struct mount *, ino_t, struct vnode **, struct lwp *));
     81  1.48.2.1   darrenr int	procfs_fhtovp __P((struct mount *, struct fid *, struct vnode **, struct lwp *));
     82      1.31  wrstuden int	procfs_checkexp __P((struct mount *, struct mbuf *, int *,
     83      1.31  wrstuden 			   struct ucred **));
     84      1.25  christos int	procfs_vptofh __P((struct vnode *, struct fid *));
     85      1.28      fvdl int	procfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
     86  1.48.2.1   darrenr 			   struct lwp *));
     87       1.1        pk /*
     88       1.1        pk  * VFS Operations.
     89       1.1        pk  *
     90       1.1        pk  * mount system call
     91       1.1        pk  */
     92       1.1        pk /* ARGSUSED */
     93      1.25  christos int
     94  1.48.2.1   darrenr procfs_mount(mp, path, data, ndp, l)
     95       1.9       cgd 	struct mount *mp;
     96      1.26       cgd 	const char *path;
     97      1.26       cgd 	void *data;
     98       1.1        pk 	struct nameidata *ndp;
     99  1.48.2.1   darrenr 	struct lwp *l;
    100       1.1        pk {
    101      1.32      fvdl 	struct procfsmount *pmnt;
    102      1.36      fvdl 	struct procfs_args args;
    103      1.36      fvdl 	int error;
    104       1.1        pk 
    105       1.9       cgd 	if (UIO_MX & (UIO_MX-1)) {
    106       1.9       cgd 		log(LOG_ERR, "procfs: invalid directory entry size");
    107       1.9       cgd 		return (EINVAL);
    108      1.43  christos 	}
    109      1.43  christos 
    110      1.43  christos 	if (mp->mnt_flag & MNT_GETARGS) {
    111      1.43  christos 		pmnt = VFSTOPROC(mp);
    112      1.43  christos 		if (pmnt == NULL)
    113      1.43  christos 			return EIO;
    114      1.43  christos 		args.version = PROCFS_ARGSVERSION;
    115      1.43  christos 		args.flags = pmnt->pmnt_flags;
    116      1.43  christos 		return copyout(&args, data, sizeof(args));
    117       1.1        pk 	}
    118       1.1        pk 
    119       1.9       cgd 	if (mp->mnt_flag & MNT_UPDATE)
    120       1.9       cgd 		return (EOPNOTSUPP);
    121       1.9       cgd 
    122      1.36      fvdl 	if (data != NULL) {
    123      1.36      fvdl 		error = copyin(data, &args, sizeof args);
    124      1.36      fvdl 		if (error != 0)
    125      1.36      fvdl 			return error;
    126      1.36      fvdl 
    127      1.36      fvdl 		if (args.version != PROCFS_ARGSVERSION)
    128      1.36      fvdl 			return EINVAL;
    129      1.36      fvdl 	} else
    130      1.36      fvdl 		args.flags = 0;
    131      1.36      fvdl 
    132      1.16   mycroft 	mp->mnt_flag |= MNT_LOCAL;
    133      1.32      fvdl 	pmnt = (struct procfsmount *) malloc(sizeof(struct procfsmount),
    134      1.32      fvdl 	    M_UFSMNT, M_WAITOK);   /* XXX need new malloc type */
    135      1.32      fvdl 
    136      1.42     soren 	mp->mnt_data = pmnt;
    137      1.34     assar 	vfs_getnewfsid(mp);
    138       1.9       cgd 
    139      1.45  christos 	error = set_statfs_info(path, UIO_USERSPACE, "procfs", UIO_SYSSPACE,
    140  1.48.2.1   darrenr 	    mp, l);
    141      1.32      fvdl 	pmnt->pmnt_exechook = exechook_establish(procfs_revoke_vnodes, mp);
    142      1.36      fvdl 	pmnt->pmnt_flags = args.flags;
    143      1.32      fvdl 
    144      1.45  christos 	return error;
    145       1.1        pk }
    146       1.1        pk 
    147       1.1        pk /*
    148       1.1        pk  * unmount system call
    149       1.1        pk  */
    150      1.25  christos int
    151  1.48.2.1   darrenr procfs_unmount(mp, mntflags, l)
    152       1.1        pk 	struct mount *mp;
    153       1.1        pk 	int mntflags;
    154  1.48.2.1   darrenr 	struct lwp *l;
    155       1.1        pk {
    156       1.9       cgd 	int error;
    157       1.9       cgd 	int flags = 0;
    158       1.9       cgd 
    159      1.28      fvdl 	if (mntflags & MNT_FORCE)
    160       1.9       cgd 		flags |= FORCECLOSE;
    161       1.9       cgd 
    162      1.25  christos 	if ((error = vflush(mp, 0, flags)) != 0)
    163       1.9       cgd 		return (error);
    164       1.9       cgd 
    165      1.32      fvdl 	exechook_disestablish(VFSTOPROC(mp)->pmnt_exechook);
    166      1.32      fvdl 
    167      1.32      fvdl 	free(mp->mnt_data, M_UFSMNT);
    168      1.32      fvdl 	mp->mnt_data = 0;
    169      1.32      fvdl 
    170       1.1        pk 	return (0);
    171       1.1        pk }
    172       1.1        pk 
    173      1.25  christos int
    174  1.48.2.1   darrenr procfs_root(mp, vpp, l)
    175       1.1        pk 	struct mount *mp;
    176       1.1        pk 	struct vnode **vpp;
    177  1.48.2.1   darrenr 	struct lwp *l;
    178       1.1        pk {
    179       1.1        pk 
    180      1.44  christos 	return (procfs_allocvp(mp, vpp, 0, Proot, -1));
    181       1.1        pk }
    182       1.1        pk 
    183       1.1        pk /* ARGSUSED */
    184      1.25  christos int
    185  1.48.2.1   darrenr procfs_start(mp, flags, l)
    186       1.1        pk 	struct mount *mp;
    187       1.1        pk 	int flags;
    188  1.48.2.1   darrenr 	struct lwp *l;
    189       1.1        pk {
    190       1.9       cgd 
    191       1.9       cgd 	return (0);
    192       1.1        pk }
    193       1.1        pk 
    194       1.1        pk /*
    195       1.1        pk  * Get file system statistics.
    196       1.1        pk  */
    197      1.25  christos int
    198  1.48.2.1   darrenr procfs_statfs(mp, sbp, l)
    199       1.1        pk 	struct mount *mp;
    200       1.1        pk 	struct statfs *sbp;
    201  1.48.2.1   darrenr 	struct lwp *l;
    202       1.1        pk {
    203      1.16   mycroft 
    204      1.16   mycroft 	sbp->f_bsize = PAGE_SIZE;
    205      1.14       cgd 	sbp->f_iosize = PAGE_SIZE;
    206       1.9       cgd 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
    207       1.4        pk 	sbp->f_bfree = 0;
    208       1.1        pk 	sbp->f_bavail = 0;
    209       1.9       cgd 	sbp->f_files = maxproc;			/* approx */
    210       1.9       cgd 	sbp->f_ffree = maxproc - nprocs;	/* approx */
    211      1.28      fvdl #ifdef COMPAT_09
    212      1.28      fvdl 	sbp->f_type = 10;
    213      1.28      fvdl #else
    214      1.28      fvdl 	sbp->f_type = 0;
    215      1.28      fvdl #endif
    216      1.45  christos 	copy_statfs_info(sbp, mp);
    217       1.9       cgd 	return (0);
    218       1.1        pk }
    219       1.1        pk 
    220      1.25  christos /*ARGSUSED*/
    221      1.25  christos int
    222  1.48.2.1   darrenr procfs_quotactl(mp, cmds, uid, arg, l)
    223       1.1        pk 	struct mount *mp;
    224       1.1        pk 	int cmds;
    225       1.1        pk 	uid_t uid;
    226       1.1        pk 	caddr_t arg;
    227  1.48.2.1   darrenr 	struct lwp *l;
    228       1.1        pk {
    229       1.9       cgd 
    230       1.9       cgd 	return (EOPNOTSUPP);
    231       1.1        pk }
    232       1.1        pk 
    233      1.25  christos /*ARGSUSED*/
    234      1.25  christos int
    235  1.48.2.1   darrenr procfs_sync(mp, waitfor, uc, l)
    236       1.1        pk 	struct mount *mp;
    237       1.1        pk 	int waitfor;
    238      1.25  christos 	struct ucred *uc;
    239  1.48.2.1   darrenr 	struct lwp *l;
    240       1.1        pk {
    241       1.9       cgd 
    242       1.9       cgd 	return (0);
    243       1.1        pk }
    244       1.1        pk 
    245      1.25  christos /*ARGSUSED*/
    246      1.25  christos int
    247  1.48.2.1   darrenr procfs_vget(mp, ino, vpp, l)
    248      1.16   mycroft 	struct mount *mp;
    249      1.16   mycroft 	ino_t ino;
    250      1.16   mycroft 	struct vnode **vpp;
    251  1.48.2.1   darrenr 	struct lwp *l;
    252      1.16   mycroft {
    253      1.16   mycroft 	return (EOPNOTSUPP);
    254      1.16   mycroft }
    255      1.16   mycroft 
    256      1.25  christos /*ARGSUSED*/
    257      1.25  christos int
    258  1.48.2.1   darrenr procfs_fhtovp(mp, fhp, vpp, l)
    259       1.9       cgd 	struct mount *mp;
    260       1.1        pk 	struct fid *fhp;
    261      1.31  wrstuden 	struct vnode **vpp;
    262  1.48.2.1   darrenr 	struct lwp *l;
    263      1.31  wrstuden {
    264      1.31  wrstuden 
    265      1.31  wrstuden 	return (EINVAL);
    266      1.31  wrstuden }
    267      1.31  wrstuden 
    268      1.31  wrstuden /*ARGSUSED*/
    269      1.31  wrstuden int
    270      1.31  wrstuden procfs_checkexp(mp, mb, what, anon)
    271      1.31  wrstuden 	struct mount *mp;
    272      1.25  christos 	struct mbuf *mb;
    273      1.25  christos 	int *what;
    274      1.25  christos 	struct ucred **anon;
    275       1.1        pk {
    276      1.16   mycroft 
    277      1.16   mycroft 	return (EINVAL);
    278       1.1        pk }
    279       1.1        pk 
    280      1.25  christos /*ARGSUSED*/
    281      1.25  christos int
    282       1.9       cgd procfs_vptofh(vp, fhp)
    283       1.1        pk 	struct vnode *vp;
    284       1.1        pk 	struct fid *fhp;
    285       1.1        pk {
    286      1.16   mycroft 
    287      1.16   mycroft 	return (EINVAL);
    288       1.1        pk }
    289       1.1        pk 
    290      1.25  christos void
    291       1.9       cgd procfs_init()
    292       1.1        pk {
    293      1.32      fvdl 	procfs_hashinit();
    294       1.1        pk }
    295       1.9       cgd 
    296      1.33  jdolecek void
    297      1.40       chs procfs_reinit()
    298      1.40       chs {
    299      1.40       chs 	procfs_hashreinit();
    300      1.40       chs }
    301      1.40       chs 
    302      1.40       chs void
    303      1.33  jdolecek procfs_done()
    304      1.33  jdolecek {
    305      1.33  jdolecek 	procfs_hashdone();
    306      1.33  jdolecek }
    307      1.33  jdolecek 
    308      1.28      fvdl int
    309  1.48.2.1   darrenr procfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, l)
    310      1.28      fvdl 	int *name;
    311      1.28      fvdl 	u_int namelen;
    312      1.28      fvdl 	void *oldp;
    313      1.28      fvdl 	size_t *oldlenp;
    314      1.28      fvdl 	void *newp;
    315      1.28      fvdl 	size_t newlen;
    316  1.48.2.1   darrenr 	struct lwp *l;
    317      1.28      fvdl {
    318      1.28      fvdl 	return (EOPNOTSUPP);
    319      1.28      fvdl }
    320      1.28      fvdl 
    321      1.37  jdolecek extern const struct vnodeopv_desc procfs_vnodeop_opv_desc;
    322      1.27   thorpej 
    323      1.37  jdolecek const struct vnodeopv_desc * const procfs_vnodeopv_descs[] = {
    324      1.27   thorpej 	&procfs_vnodeop_opv_desc,
    325      1.27   thorpej 	NULL,
    326      1.27   thorpej };
    327      1.27   thorpej 
    328       1.9       cgd struct vfsops procfs_vfsops = {
    329      1.12       cgd 	MOUNT_PROCFS,
    330       1.9       cgd 	procfs_mount,
    331       1.9       cgd 	procfs_start,
    332       1.9       cgd 	procfs_unmount,
    333       1.9       cgd 	procfs_root,
    334       1.9       cgd 	procfs_quotactl,
    335       1.9       cgd 	procfs_statfs,
    336       1.9       cgd 	procfs_sync,
    337      1.16   mycroft 	procfs_vget,
    338       1.9       cgd 	procfs_fhtovp,
    339       1.9       cgd 	procfs_vptofh,
    340       1.9       cgd 	procfs_init,
    341      1.40       chs 	procfs_reinit,
    342      1.33  jdolecek 	procfs_done,
    343      1.28      fvdl 	procfs_sysctl,
    344      1.27   thorpej 	NULL,				/* vfs_mountroot */
    345      1.31  wrstuden 	procfs_checkexp,
    346      1.27   thorpej 	procfs_vnodeopv_descs,
    347       1.9       cgd };
    348