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