Home | History | Annotate | Line # | Download | only in procfs
procfs_vfsops.c revision 1.48.2.8
      1  1.48.2.8     skrll /*	$NetBSD: procfs_vfsops.c,v 1.48.2.8 2005/11/10 14:10:32 skrll 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.48.2.2     skrll  * 3. Neither the name of the University nor the names of its contributors
     19  1.48.2.2     skrll  *    may be used to endorse or promote products derived from this software
     20  1.48.2.2     skrll  *    without specific prior written permission.
     21  1.48.2.2     skrll  *
     22  1.48.2.2     skrll  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.48.2.2     skrll  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.48.2.2     skrll  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.48.2.2     skrll  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.48.2.2     skrll  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.48.2.2     skrll  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.48.2.2     skrll  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.48.2.2     skrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.48.2.2     skrll  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.48.2.2     skrll  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.48.2.2     skrll  * SUCH DAMAGE.
     33  1.48.2.2     skrll  *
     34  1.48.2.2     skrll  *	@(#)procfs_vfsops.c	8.7 (Berkeley) 5/10/95
     35  1.48.2.2     skrll  */
     36  1.48.2.2     skrll 
     37  1.48.2.2     skrll /*
     38  1.48.2.2     skrll  * Copyright (c) 1993 Jan-Simon Pendry
     39  1.48.2.2     skrll  *
     40  1.48.2.2     skrll  * This code is derived from software contributed to Berkeley by
     41  1.48.2.2     skrll  * Jan-Simon Pendry.
     42  1.48.2.2     skrll  *
     43  1.48.2.2     skrll  * Redistribution and use in source and binary forms, with or without
     44  1.48.2.2     skrll  * modification, are permitted provided that the following conditions
     45  1.48.2.2     skrll  * are met:
     46  1.48.2.2     skrll  * 1. Redistributions of source code must retain the above copyright
     47  1.48.2.2     skrll  *    notice, this list of conditions and the following disclaimer.
     48  1.48.2.2     skrll  * 2. Redistributions in binary form must reproduce the above copyright
     49  1.48.2.2     skrll  *    notice, this list of conditions and the following disclaimer in the
     50  1.48.2.2     skrll  *    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.48.2.8     skrll __KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.48.2.8 2005/11/10 14:10:32 skrll 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.48.2.2     skrll #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.48.2.2     skrll #include <sys/dirent.h>
     95       1.8   mycroft #include <sys/signalvar.h>
     96       1.8   mycroft #include <sys/vnode.h>
     97      1.32      fvdl #include <sys/malloc.h>
     98      1.35       mrg 
     99       1.9       cgd #include <miscfs/procfs/procfs.h>
    100      1.35       mrg 
    101      1.35       mrg #include <uvm/uvm_extern.h>			/* for PAGE_SIZE */
    102       1.1        pk 
    103  1.48.2.8     skrll void	procfs_init(void);
    104  1.48.2.8     skrll void	procfs_reinit(void);
    105  1.48.2.8     skrll void	procfs_done(void);
    106  1.48.2.8     skrll int	procfs_mount(struct mount *, const char *, void *,
    107  1.48.2.8     skrll 			  struct nameidata *, struct lwp *);
    108  1.48.2.8     skrll int	procfs_start(struct mount *, int, struct lwp *);
    109  1.48.2.8     skrll int	procfs_unmount(struct mount *, int, struct lwp *);
    110  1.48.2.8     skrll int	procfs_quotactl(struct mount *, int, uid_t, void *,
    111  1.48.2.8     skrll 			     struct lwp *);
    112  1.48.2.8     skrll int	procfs_statvfs(struct mount *, struct statvfs *, struct lwp *);
    113  1.48.2.8     skrll int	procfs_sync(struct mount *, int, struct ucred *, struct lwp *);
    114  1.48.2.8     skrll int	procfs_vget(struct mount *, ino_t, struct vnode **);
    115  1.48.2.2     skrll 
    116       1.1        pk /*
    117       1.1        pk  * VFS Operations.
    118       1.1        pk  *
    119       1.1        pk  * mount system call
    120       1.1        pk  */
    121       1.1        pk /* ARGSUSED */
    122      1.25  christos int
    123  1.48.2.5     skrll procfs_mount(mp, path, data, ndp, l)
    124       1.9       cgd 	struct mount *mp;
    125      1.26       cgd 	const char *path;
    126      1.26       cgd 	void *data;
    127       1.1        pk 	struct nameidata *ndp;
    128  1.48.2.5     skrll 	struct lwp *l;
    129       1.1        pk {
    130      1.32      fvdl 	struct procfsmount *pmnt;
    131      1.36      fvdl 	struct procfs_args args;
    132      1.36      fvdl 	int error;
    133       1.1        pk 
    134       1.9       cgd 	if (UIO_MX & (UIO_MX-1)) {
    135       1.9       cgd 		log(LOG_ERR, "procfs: invalid directory entry size");
    136       1.9       cgd 		return (EINVAL);
    137      1.43  christos 	}
    138      1.43  christos 
    139      1.43  christos 	if (mp->mnt_flag & MNT_GETARGS) {
    140      1.43  christos 		pmnt = VFSTOPROC(mp);
    141      1.43  christos 		if (pmnt == NULL)
    142      1.43  christos 			return EIO;
    143      1.43  christos 		args.version = PROCFS_ARGSVERSION;
    144      1.43  christos 		args.flags = pmnt->pmnt_flags;
    145      1.43  christos 		return copyout(&args, data, sizeof(args));
    146       1.1        pk 	}
    147       1.1        pk 
    148       1.9       cgd 	if (mp->mnt_flag & MNT_UPDATE)
    149       1.9       cgd 		return (EOPNOTSUPP);
    150       1.9       cgd 
    151      1.36      fvdl 	if (data != NULL) {
    152      1.36      fvdl 		error = copyin(data, &args, sizeof args);
    153      1.36      fvdl 		if (error != 0)
    154      1.36      fvdl 			return error;
    155      1.36      fvdl 
    156      1.36      fvdl 		if (args.version != PROCFS_ARGSVERSION)
    157      1.36      fvdl 			return EINVAL;
    158      1.36      fvdl 	} else
    159      1.36      fvdl 		args.flags = 0;
    160      1.36      fvdl 
    161      1.32      fvdl 	pmnt = (struct procfsmount *) malloc(sizeof(struct procfsmount),
    162      1.32      fvdl 	    M_UFSMNT, M_WAITOK);   /* XXX need new malloc type */
    163      1.32      fvdl 
    164  1.48.2.4     skrll 	mp->mnt_stat.f_namemax = MAXNAMLEN;
    165  1.48.2.4     skrll 	mp->mnt_flag |= MNT_LOCAL;
    166      1.42     soren 	mp->mnt_data = pmnt;
    167      1.34     assar 	vfs_getnewfsid(mp);
    168       1.9       cgd 
    169  1.48.2.2     skrll 	error = set_statvfs_info(path, UIO_USERSPACE, "procfs", UIO_SYSSPACE,
    170  1.48.2.5     skrll 	    mp, l);
    171      1.32      fvdl 	pmnt->pmnt_exechook = exechook_establish(procfs_revoke_vnodes, mp);
    172      1.36      fvdl 	pmnt->pmnt_flags = args.flags;
    173      1.32      fvdl 
    174      1.45  christos 	return error;
    175       1.1        pk }
    176       1.1        pk 
    177       1.1        pk /*
    178       1.1        pk  * unmount system call
    179       1.1        pk  */
    180      1.25  christos int
    181  1.48.2.5     skrll procfs_unmount(mp, mntflags, l)
    182       1.1        pk 	struct mount *mp;
    183       1.1        pk 	int mntflags;
    184  1.48.2.5     skrll 	struct lwp *l;
    185       1.1        pk {
    186       1.9       cgd 	int error;
    187       1.9       cgd 	int flags = 0;
    188       1.9       cgd 
    189      1.28      fvdl 	if (mntflags & MNT_FORCE)
    190       1.9       cgd 		flags |= FORCECLOSE;
    191       1.9       cgd 
    192      1.25  christos 	if ((error = vflush(mp, 0, flags)) != 0)
    193       1.9       cgd 		return (error);
    194       1.9       cgd 
    195      1.32      fvdl 	exechook_disestablish(VFSTOPROC(mp)->pmnt_exechook);
    196      1.32      fvdl 
    197      1.32      fvdl 	free(mp->mnt_data, M_UFSMNT);
    198      1.32      fvdl 	mp->mnt_data = 0;
    199      1.32      fvdl 
    200       1.1        pk 	return (0);
    201       1.1        pk }
    202       1.1        pk 
    203      1.25  christos int
    204  1.48.2.3     skrll procfs_root(mp, vpp)
    205       1.1        pk 	struct mount *mp;
    206       1.1        pk 	struct vnode **vpp;
    207       1.1        pk {
    208       1.1        pk 
    209  1.48.2.2     skrll 	return (procfs_allocvp(mp, vpp, 0, PFSroot, -1));
    210       1.1        pk }
    211       1.1        pk 
    212       1.1        pk /* ARGSUSED */
    213      1.25  christos int
    214  1.48.2.5     skrll procfs_start(mp, flags, l)
    215       1.1        pk 	struct mount *mp;
    216       1.1        pk 	int flags;
    217  1.48.2.5     skrll 	struct lwp *l;
    218       1.1        pk {
    219       1.9       cgd 
    220       1.9       cgd 	return (0);
    221       1.1        pk }
    222       1.1        pk 
    223       1.1        pk /*
    224       1.1        pk  * Get file system statistics.
    225       1.1        pk  */
    226      1.25  christos int
    227  1.48.2.5     skrll procfs_statvfs(mp, sbp, l)
    228       1.1        pk 	struct mount *mp;
    229  1.48.2.2     skrll 	struct statvfs *sbp;
    230  1.48.2.5     skrll 	struct lwp *l;
    231       1.1        pk {
    232      1.16   mycroft 
    233      1.16   mycroft 	sbp->f_bsize = PAGE_SIZE;
    234  1.48.2.2     skrll 	sbp->f_frsize = PAGE_SIZE;
    235      1.14       cgd 	sbp->f_iosize = PAGE_SIZE;
    236       1.9       cgd 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
    237       1.4        pk 	sbp->f_bfree = 0;
    238       1.1        pk 	sbp->f_bavail = 0;
    239  1.48.2.2     skrll 	sbp->f_bresvd = 0;
    240       1.9       cgd 	sbp->f_files = maxproc;			/* approx */
    241       1.9       cgd 	sbp->f_ffree = maxproc - nprocs;	/* approx */
    242  1.48.2.2     skrll 	sbp->f_favail = maxproc - nprocs;	/* approx */
    243  1.48.2.2     skrll 	sbp->f_fresvd = 0;
    244  1.48.2.2     skrll 	copy_statvfs_info(sbp, mp);
    245       1.9       cgd 	return (0);
    246       1.1        pk }
    247       1.1        pk 
    248      1.25  christos /*ARGSUSED*/
    249      1.25  christos int
    250  1.48.2.5     skrll procfs_quotactl(mp, cmds, uid, arg, l)
    251       1.1        pk 	struct mount *mp;
    252       1.1        pk 	int cmds;
    253       1.1        pk 	uid_t uid;
    254  1.48.2.2     skrll 	void *arg;
    255  1.48.2.5     skrll 	struct lwp *l;
    256       1.1        pk {
    257       1.9       cgd 
    258       1.9       cgd 	return (EOPNOTSUPP);
    259       1.1        pk }
    260       1.1        pk 
    261      1.25  christos /*ARGSUSED*/
    262      1.25  christos int
    263  1.48.2.5     skrll procfs_sync(mp, waitfor, uc, l)
    264       1.1        pk 	struct mount *mp;
    265       1.1        pk 	int waitfor;
    266      1.25  christos 	struct ucred *uc;
    267  1.48.2.5     skrll 	struct lwp *l;
    268       1.1        pk {
    269       1.9       cgd 
    270       1.9       cgd 	return (0);
    271       1.1        pk }
    272       1.1        pk 
    273      1.25  christos /*ARGSUSED*/
    274      1.25  christos int
    275  1.48.2.3     skrll procfs_vget(mp, ino, vpp)
    276      1.16   mycroft 	struct mount *mp;
    277      1.16   mycroft 	ino_t ino;
    278      1.16   mycroft 	struct vnode **vpp;
    279      1.16   mycroft {
    280      1.16   mycroft 	return (EOPNOTSUPP);
    281      1.16   mycroft }
    282      1.16   mycroft 
    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.40       chs procfs_reinit()
    291      1.40       chs {
    292      1.40       chs 	procfs_hashreinit();
    293      1.40       chs }
    294      1.40       chs 
    295      1.40       chs void
    296      1.33  jdolecek procfs_done()
    297      1.33  jdolecek {
    298      1.33  jdolecek 	procfs_hashdone();
    299      1.33  jdolecek }
    300      1.33  jdolecek 
    301  1.48.2.2     skrll SYSCTL_SETUP(sysctl_vfs_procfs_setup, "sysctl vfs.procfs subtree setup")
    302      1.28      fvdl {
    303  1.48.2.2     skrll 
    304  1.48.2.2     skrll 	sysctl_createv(clog, 0, NULL, NULL,
    305  1.48.2.2     skrll 		       CTLFLAG_PERMANENT,
    306  1.48.2.2     skrll 		       CTLTYPE_NODE, "vfs", NULL,
    307  1.48.2.2     skrll 		       NULL, 0, NULL, 0,
    308  1.48.2.2     skrll 		       CTL_VFS, CTL_EOL);
    309  1.48.2.2     skrll 	sysctl_createv(clog, 0, NULL, NULL,
    310  1.48.2.2     skrll 		       CTLFLAG_PERMANENT,
    311  1.48.2.2     skrll 		       CTLTYPE_NODE, "procfs",
    312  1.48.2.2     skrll 		       SYSCTL_DESCR("Process file system"),
    313  1.48.2.2     skrll 		       NULL, 0, NULL, 0,
    314  1.48.2.2     skrll 		       CTL_VFS, 12, CTL_EOL);
    315  1.48.2.2     skrll 	/*
    316  1.48.2.2     skrll 	 * XXX the "12" above could be dynamic, thereby eliminating
    317  1.48.2.2     skrll 	 * one more instance of the "number to vfs" mapping problem,
    318  1.48.2.2     skrll 	 * but "12" is the order as taken from sys/mount.h
    319  1.48.2.2     skrll 	 */
    320      1.28      fvdl }
    321      1.28      fvdl 
    322      1.37  jdolecek extern const struct vnodeopv_desc procfs_vnodeop_opv_desc;
    323      1.27   thorpej 
    324      1.37  jdolecek const struct vnodeopv_desc * const procfs_vnodeopv_descs[] = {
    325      1.27   thorpej 	&procfs_vnodeop_opv_desc,
    326      1.27   thorpej 	NULL,
    327      1.27   thorpej };
    328      1.27   thorpej 
    329       1.9       cgd struct vfsops procfs_vfsops = {
    330      1.12       cgd 	MOUNT_PROCFS,
    331       1.9       cgd 	procfs_mount,
    332       1.9       cgd 	procfs_start,
    333       1.9       cgd 	procfs_unmount,
    334       1.9       cgd 	procfs_root,
    335       1.9       cgd 	procfs_quotactl,
    336  1.48.2.2     skrll 	procfs_statvfs,
    337       1.9       cgd 	procfs_sync,
    338      1.16   mycroft 	procfs_vget,
    339  1.48.2.8     skrll 	NULL,				/* vfs_fhtovp */
    340  1.48.2.8     skrll 	NULL,				/* vfs_vptofh */
    341       1.9       cgd 	procfs_init,
    342      1.40       chs 	procfs_reinit,
    343      1.33  jdolecek 	procfs_done,
    344      1.27   thorpej 	NULL,				/* vfs_mountroot */
    345  1.48.2.2     skrll 	(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
    346  1.48.2.6     skrll 	vfs_stdextattrctl,
    347      1.27   thorpej 	procfs_vnodeopv_descs,
    348       1.9       cgd };
    349  1.48.2.7     skrll VFS_ATTACH(procfs_vfsops);
    350