root/miscfs/procfs/procfs_vfsops.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. procfs_mount
  2. procfs_unmount
  3. procfs_root
  4. procfs_start
  5. procfs_statfs

    1 /*      $OpenBSD: procfs_vfsops.c,v 1.25 2007/06/18 08:30:07 jasper Exp $       */
    2 /*      $NetBSD: procfs_vfsops.c,v 1.25 1996/02/09 22:40:53 christos Exp $      */
    3 
    4 /*
    5  * Copyright (c) 1993 Jan-Simon Pendry
    6  * Copyright (c) 1993
    7  *      The Regents of the University of California.  All rights reserved.
    8  *
    9  * This code is derived from software contributed to Berkeley by
   10  * Jan-Simon Pendry.
   11  *
   12  * Redistribution and use in source and binary forms, with or without
   13  * modification, are permitted provided that the following conditions
   14  * are met:
   15  * 1. Redistributions of source code must retain the above copyright
   16  *    notice, this list of conditions and the following disclaimer.
   17  * 2. Redistributions in binary form must reproduce the above copyright
   18  *    notice, this list of conditions and the following disclaimer in the
   19  *    documentation and/or other materials provided with the distribution.
   20  * 3. Neither the name of the University nor the names of its contributors
   21  *    may be used to endorse or promote products derived from this software
   22  *    without specific prior written permission.
   23  *
   24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   34  * SUCH DAMAGE.
   35  *
   36  *      @(#)procfs_vfsops.c     8.5 (Berkeley) 6/15/94
   37  */
   38 
   39 /*
   40  * procfs VFS interface
   41  */
   42 
   43 #include <sys/param.h>
   44 #include <sys/time.h>
   45 #include <sys/kernel.h>
   46 #include <sys/systm.h>
   47 #include <sys/proc.h>
   48 #include <sys/buf.h>
   49 #include <sys/syslog.h>
   50 #include <sys/mount.h>
   51 #include <sys/signalvar.h>
   52 #include <sys/vnode.h>
   53 #include <sys/malloc.h>
   54 
   55 #include <miscfs/procfs/procfs.h>
   56 
   57 #include <uvm/uvm_extern.h>
   58 
   59 int     procfs_mount(struct mount *, const char *, void *,
   60                           struct nameidata *, struct proc *);
   61 int     procfs_start(struct mount *, int, struct proc *);
   62 int     procfs_unmount(struct mount *, int, struct proc *);
   63 int     procfs_statfs(struct mount *, struct statfs *, struct proc *);
   64 /*
   65  * VFS Operations.
   66  *
   67  * mount system call
   68  */
   69 /* ARGSUSED */
   70 int
   71 procfs_mount(struct mount *mp, const char *path, void *data, struct nameidata *ndp,
   72     struct proc *p)
   73 {
   74         size_t size;
   75         struct procfsmount *pmnt;
   76         struct procfs_args args;
   77         int error;
   78 
   79         if (UIO_MX & (UIO_MX-1)) {
   80                 log(LOG_ERR, "procfs: invalid directory entry size");
   81                 return (EINVAL);
   82         }
   83 
   84         if (mp->mnt_flag & MNT_UPDATE)
   85                 return (EOPNOTSUPP);
   86 
   87         if (data != NULL) {
   88                 error = copyin(data, &args, sizeof args);
   89                 if (error != 0)
   90                         return (error);
   91 
   92                 if (args.version != PROCFS_ARGSVERSION)
   93                         return (EINVAL);
   94         } else
   95                 args.flags = 0;
   96 
   97         mp->mnt_flag |= MNT_LOCAL;
   98         pmnt = (struct procfsmount *) malloc(sizeof(struct procfsmount),
   99             M_MISCFSMNT, M_WAITOK);
  100 
  101         mp->mnt_data = pmnt;
  102         vfs_getnewfsid(mp);
  103 
  104         (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
  105         bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
  106         bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
  107         bcopy("procfs", mp->mnt_stat.f_mntfromname, sizeof("procfs"));
  108         bcopy(&args, &mp->mnt_stat.mount_info.procfs_args, sizeof(args));
  109 
  110 #ifdef notyet
  111         pmnt->pmnt_exechook = exechook_establish(procfs_revoke_vnodes, mp);
  112 #endif
  113         pmnt->pmnt_flags = args.flags;
  114 
  115         return (0);
  116 }
  117 
  118 /*
  119  * unmount system call
  120  */
  121 int
  122 procfs_unmount(struct mount *mp, int mntflags, struct proc *p)
  123 {
  124         int error;
  125         extern int doforce;
  126         int flags = 0;
  127 
  128         if (mntflags & MNT_FORCE) {
  129                 /* procfs can never be rootfs so don't check for it */
  130                 if (!doforce)
  131                         return (EINVAL);
  132                 flags |= FORCECLOSE;
  133         }
  134 
  135         if ((error = vflush(mp, 0, flags)) != 0)
  136                 return (error);
  137 
  138         free(VFSTOPROC(mp), M_MISCFSMNT);
  139         mp->mnt_data = 0;
  140 
  141         return (0);
  142 }
  143 
  144 int
  145 procfs_root(struct mount *mp, struct vnode **vpp)
  146 {
  147         int error;
  148 
  149         error = procfs_allocvp(mp, vpp, 0, Proot);
  150         if (error)
  151                 return (error);
  152         vn_lock(*vpp, LK_EXCLUSIVE, curproc);
  153 
  154         return (0);
  155 }
  156 
  157 /* ARGSUSED */
  158 int
  159 procfs_start(struct mount *mp, int flags, struct proc *p)
  160 {
  161 
  162         return (0);
  163 }
  164 
  165 /*
  166  * Get file system statistics.
  167  */
  168 int
  169 procfs_statfs(struct mount *mp, struct statfs *sbp, struct proc *p)
  170 {
  171         struct vmtotal  vmtotals;
  172 
  173         uvm_total(&vmtotals);
  174         sbp->f_bsize = PAGE_SIZE;
  175         sbp->f_iosize = PAGE_SIZE;
  176         sbp->f_blocks = vmtotals.t_vm;
  177         sbp->f_bfree = vmtotals.t_vm - vmtotals.t_avm;
  178         sbp->f_bavail = 0;
  179         sbp->f_files = maxproc;                 /* approx */
  180         sbp->f_ffree = maxproc - nprocs;        /* approx */
  181         if (sbp != &mp->mnt_stat) {
  182                 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
  183                 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
  184                 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
  185                 bcopy(&mp->mnt_stat.mount_info.procfs_args,
  186                     &sbp->mount_info.procfs_args, sizeof(struct procfs_args));
  187         }
  188         strncpy(sbp->f_fstypename, mp->mnt_vfc->vfc_name, MFSNAMELEN);
  189         return (0);
  190 }
  191 
  192 
  193 #define procfs_sync ((int (*)(struct mount *, int, struct ucred *, \
  194                                   struct proc *))nullop)
  195 
  196 #define procfs_fhtovp ((int (*)(struct mount *, struct fid *, \
  197             struct vnode **))eopnotsupp)
  198 #define procfs_quotactl ((int (*)(struct mount *, int, uid_t, caddr_t, \
  199             struct proc *))eopnotsupp)
  200 #define procfs_sysctl ((int (*)(int *, u_int, void *, size_t *, void *, \
  201             size_t, struct proc *))eopnotsupp)
  202 #define procfs_vget ((int (*)(struct mount *, ino_t, struct vnode **)) \
  203             eopnotsupp)
  204 #define procfs_vptofh ((int (*)(struct vnode *, struct fid *))eopnotsupp)
  205 #define procfs_checkexp ((int (*)(struct mount *, struct mbuf *,        \
  206         int *, struct ucred **))eopnotsupp)
  207 
  208 const struct vfsops procfs_vfsops = {
  209         procfs_mount,
  210         procfs_start,
  211         procfs_unmount,
  212         procfs_root,
  213         procfs_quotactl,
  214         procfs_statfs,
  215         procfs_sync,
  216         procfs_vget,
  217         procfs_fhtovp,
  218         procfs_vptofh,
  219         procfs_init,
  220         procfs_sysctl,
  221         procfs_checkexp
  222 };

/* [<][>][^][v][top][bottom][index][help] */