Home | History | Annotate | Line # | Download | only in procfs
procfs_vfsops.c revision 1.28
      1  1.28      fvdl /*	$NetBSD: procfs_vfsops.c,v 1.28 1998/03/01 02:21:16 fvdl 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.1        pk 
     46   1.8   mycroft #include <sys/param.h>
     47   1.8   mycroft #include <sys/time.h>
     48   1.8   mycroft #include <sys/kernel.h>
     49  1.25  christos #include <sys/systm.h>
     50   1.8   mycroft #include <sys/proc.h>
     51   1.8   mycroft #include <sys/buf.h>
     52   1.9       cgd #include <sys/syslog.h>
     53   1.8   mycroft #include <sys/mount.h>
     54   1.8   mycroft #include <sys/signalvar.h>
     55   1.8   mycroft #include <sys/vnode.h>
     56   1.9       cgd #include <miscfs/procfs/procfs.h>
     57  1.16   mycroft #include <vm/vm.h>			/* for PAGE_SIZE */
     58   1.1        pk 
     59  1.28      fvdl void	procfs_init __P((void));
     60  1.26       cgd int	procfs_mount __P((struct mount *, const char *, void *,
     61  1.25  christos 			  struct nameidata *, struct proc *));
     62  1.25  christos int	procfs_start __P((struct mount *, int, struct proc *));
     63  1.25  christos int	procfs_unmount __P((struct mount *, int, struct proc *));
     64  1.25  christos int	procfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
     65  1.25  christos 			     struct proc *));
     66  1.25  christos int	procfs_statfs __P((struct mount *, struct statfs *, struct proc *));
     67  1.25  christos int	procfs_sync __P((struct mount *, int, struct ucred *, struct proc *));
     68  1.25  christos int	procfs_vget __P((struct mount *, ino_t, struct vnode **));
     69  1.25  christos int	procfs_fhtovp __P((struct mount *, struct fid *, struct mbuf *,
     70  1.25  christos 			   struct vnode **, int *, struct ucred **));
     71  1.25  christos int	procfs_vptofh __P((struct vnode *, struct fid *));
     72  1.28      fvdl int	procfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
     73  1.28      fvdl 			   struct proc *));
     74   1.1        pk /*
     75   1.1        pk  * VFS Operations.
     76   1.1        pk  *
     77   1.1        pk  * mount system call
     78   1.1        pk  */
     79   1.1        pk /* ARGSUSED */
     80  1.25  christos int
     81   1.9       cgd procfs_mount(mp, path, data, ndp, p)
     82   1.9       cgd 	struct mount *mp;
     83  1.26       cgd 	const char *path;
     84  1.26       cgd 	void *data;
     85   1.1        pk 	struct nameidata *ndp;
     86   1.1        pk 	struct proc *p;
     87   1.1        pk {
     88  1.23   mycroft 	size_t size;
     89   1.1        pk 
     90   1.9       cgd 	if (UIO_MX & (UIO_MX-1)) {
     91   1.9       cgd 		log(LOG_ERR, "procfs: invalid directory entry size");
     92   1.9       cgd 		return (EINVAL);
     93   1.1        pk 	}
     94   1.1        pk 
     95   1.9       cgd 	if (mp->mnt_flag & MNT_UPDATE)
     96   1.9       cgd 		return (EOPNOTSUPP);
     97   1.9       cgd 
     98  1.16   mycroft 	mp->mnt_flag |= MNT_LOCAL;
     99   1.9       cgd 	mp->mnt_data = 0;
    100  1.28      fvdl 	vfs_getnewfsid(mp, MOUNT_PROCFS);
    101   1.9       cgd 
    102  1.16   mycroft 	(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN, &size);
    103   1.1        pk 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
    104  1.16   mycroft 	bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
    105  1.16   mycroft 	bcopy("procfs", mp->mnt_stat.f_mntfromname, sizeof("procfs"));
    106   1.1        pk 	return (0);
    107   1.1        pk }
    108   1.1        pk 
    109   1.1        pk /*
    110   1.1        pk  * unmount system call
    111   1.1        pk  */
    112  1.25  christos int
    113   1.9       cgd procfs_unmount(mp, mntflags, p)
    114   1.1        pk 	struct mount *mp;
    115   1.1        pk 	int mntflags;
    116   1.1        pk 	struct proc *p;
    117   1.1        pk {
    118   1.9       cgd 	int error;
    119   1.9       cgd 	int flags = 0;
    120   1.9       cgd 
    121  1.28      fvdl 	if (mntflags & MNT_FORCE)
    122   1.9       cgd 		flags |= FORCECLOSE;
    123   1.9       cgd 
    124  1.25  christos 	if ((error = vflush(mp, 0, flags)) != 0)
    125   1.9       cgd 		return (error);
    126   1.9       cgd 
    127   1.1        pk 	return (0);
    128   1.1        pk }
    129   1.1        pk 
    130  1.25  christos int
    131   1.9       cgd procfs_root(mp, vpp)
    132   1.1        pk 	struct mount *mp;
    133   1.1        pk 	struct vnode **vpp;
    134   1.1        pk {
    135   1.1        pk 
    136  1.16   mycroft 	return (procfs_allocvp(mp, vpp, 0, Proot));
    137   1.1        pk }
    138   1.1        pk 
    139   1.1        pk /* ARGSUSED */
    140  1.25  christos int
    141   1.9       cgd procfs_start(mp, flags, p)
    142   1.1        pk 	struct mount *mp;
    143   1.1        pk 	int flags;
    144   1.1        pk 	struct proc *p;
    145   1.1        pk {
    146   1.9       cgd 
    147   1.9       cgd 	return (0);
    148   1.1        pk }
    149   1.1        pk 
    150   1.1        pk /*
    151   1.1        pk  * Get file system statistics.
    152   1.1        pk  */
    153  1.25  christos int
    154   1.9       cgd procfs_statfs(mp, sbp, p)
    155   1.1        pk 	struct mount *mp;
    156   1.1        pk 	struct statfs *sbp;
    157   1.1        pk 	struct proc *p;
    158   1.1        pk {
    159  1.16   mycroft 
    160  1.16   mycroft 	sbp->f_bsize = PAGE_SIZE;
    161  1.14       cgd 	sbp->f_iosize = PAGE_SIZE;
    162   1.9       cgd 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
    163   1.4        pk 	sbp->f_bfree = 0;
    164   1.1        pk 	sbp->f_bavail = 0;
    165   1.9       cgd 	sbp->f_files = maxproc;			/* approx */
    166   1.9       cgd 	sbp->f_ffree = maxproc - nprocs;	/* approx */
    167  1.28      fvdl #ifdef COMPAT_09
    168  1.28      fvdl 	sbp->f_type = 10;
    169  1.28      fvdl #else
    170  1.28      fvdl 	sbp->f_type = 0;
    171  1.28      fvdl #endif
    172   1.9       cgd 	if (sbp != &mp->mnt_stat) {
    173   1.9       cgd 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
    174   1.9       cgd 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
    175   1.9       cgd 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
    176   1.9       cgd 	}
    177  1.22   mycroft 	strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
    178   1.9       cgd 	return (0);
    179   1.1        pk }
    180   1.1        pk 
    181  1.25  christos /*ARGSUSED*/
    182  1.25  christos int
    183   1.9       cgd procfs_quotactl(mp, cmds, uid, arg, p)
    184   1.1        pk 	struct mount *mp;
    185   1.1        pk 	int cmds;
    186   1.1        pk 	uid_t uid;
    187   1.1        pk 	caddr_t arg;
    188   1.1        pk 	struct proc *p;
    189   1.1        pk {
    190   1.9       cgd 
    191   1.9       cgd 	return (EOPNOTSUPP);
    192   1.1        pk }
    193   1.1        pk 
    194  1.25  christos /*ARGSUSED*/
    195  1.25  christos int
    196  1.25  christos procfs_sync(mp, waitfor, uc, p)
    197   1.1        pk 	struct mount *mp;
    198   1.1        pk 	int waitfor;
    199  1.25  christos 	struct ucred *uc;
    200  1.25  christos 	struct proc *p;
    201   1.1        pk {
    202   1.9       cgd 
    203   1.9       cgd 	return (0);
    204   1.1        pk }
    205   1.1        pk 
    206  1.25  christos /*ARGSUSED*/
    207  1.25  christos int
    208  1.16   mycroft procfs_vget(mp, ino, vpp)
    209  1.16   mycroft 	struct mount *mp;
    210  1.16   mycroft 	ino_t ino;
    211  1.16   mycroft 	struct vnode **vpp;
    212  1.16   mycroft {
    213  1.16   mycroft 
    214  1.16   mycroft 	return (EOPNOTSUPP);
    215  1.16   mycroft }
    216  1.16   mycroft 
    217  1.25  christos /*ARGSUSED*/
    218  1.25  christos int
    219  1.25  christos procfs_fhtovp(mp, fhp, mb, vpp, what, anon)
    220   1.9       cgd 	struct mount *mp;
    221   1.1        pk 	struct fid *fhp;
    222  1.25  christos 	struct mbuf *mb;
    223   1.1        pk 	struct vnode **vpp;
    224  1.25  christos 	int *what;
    225  1.25  christos 	struct ucred **anon;
    226   1.1        pk {
    227  1.16   mycroft 
    228  1.16   mycroft 	return (EINVAL);
    229   1.1        pk }
    230   1.1        pk 
    231  1.25  christos /*ARGSUSED*/
    232  1.25  christos int
    233   1.9       cgd procfs_vptofh(vp, fhp)
    234   1.1        pk 	struct vnode *vp;
    235   1.1        pk 	struct fid *fhp;
    236   1.1        pk {
    237  1.16   mycroft 
    238  1.16   mycroft 	return (EINVAL);
    239   1.1        pk }
    240   1.1        pk 
    241  1.25  christos void
    242   1.9       cgd procfs_init()
    243   1.1        pk {
    244   1.1        pk }
    245   1.9       cgd 
    246  1.28      fvdl int
    247  1.28      fvdl procfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    248  1.28      fvdl 	int *name;
    249  1.28      fvdl 	u_int namelen;
    250  1.28      fvdl 	void *oldp;
    251  1.28      fvdl 	size_t *oldlenp;
    252  1.28      fvdl 	void *newp;
    253  1.28      fvdl 	size_t newlen;
    254  1.28      fvdl 	struct proc *p;
    255  1.28      fvdl {
    256  1.28      fvdl 	return (EOPNOTSUPP);
    257  1.28      fvdl }
    258  1.28      fvdl 
    259  1.27   thorpej extern struct vnodeopv_desc procfs_vnodeop_opv_desc;
    260  1.27   thorpej 
    261  1.27   thorpej struct vnodeopv_desc *procfs_vnodeopv_descs[] = {
    262  1.27   thorpej 	&procfs_vnodeop_opv_desc,
    263  1.27   thorpej 	NULL,
    264  1.27   thorpej };
    265  1.27   thorpej 
    266   1.9       cgd struct vfsops procfs_vfsops = {
    267  1.12       cgd 	MOUNT_PROCFS,
    268   1.9       cgd 	procfs_mount,
    269   1.9       cgd 	procfs_start,
    270   1.9       cgd 	procfs_unmount,
    271   1.9       cgd 	procfs_root,
    272   1.9       cgd 	procfs_quotactl,
    273   1.9       cgd 	procfs_statfs,
    274   1.9       cgd 	procfs_sync,
    275  1.16   mycroft 	procfs_vget,
    276   1.9       cgd 	procfs_fhtovp,
    277   1.9       cgd 	procfs_vptofh,
    278   1.9       cgd 	procfs_init,
    279  1.28      fvdl 	procfs_sysctl,
    280  1.27   thorpej 	NULL,				/* vfs_mountroot */
    281  1.27   thorpej 	procfs_vnodeopv_descs,
    282   1.9       cgd };
    283