The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/fs/devfs/devfs_vfsops.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1992, 1993, 1995
    3  *      The Regents of the University of California.  All rights reserved.
    4  * Copyright (c) 2000
    5  *      Poul-Henning Kamp.  All rights reserved.
    6  *
    7  * This code is derived from software donated to Berkeley by
    8  * Jan-Simon Pendry.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Neither the name of the University nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)kernfs_vfsops.c     8.10 (Berkeley) 5/14/95
   32  * From: FreeBSD: src/sys/miscfs/kernfs/kernfs_vfsops.c 1.36
   33  *
   34  * $FreeBSD: releng/5.0/sys/fs/devfs/devfs_vfsops.c 107698 2002-12-09 03:44:28Z rwatson $
   35  */
   36 
   37 #include "opt_devfs.h"
   38 #include "opt_mac.h"
   39 #ifndef NODEVFS
   40 
   41 #include <sys/param.h>
   42 #include <sys/systm.h>
   43 #include <sys/kernel.h>
   44 #include <sys/lock.h>
   45 #include <sys/mac.h>
   46 #include <sys/malloc.h>
   47 #include <sys/mount.h>
   48 #include <sys/proc.h>
   49 #include <sys/vnode.h>
   50 
   51 #include <fs/devfs/devfs.h>
   52 
   53 MALLOC_DEFINE(M_DEVFS, "DEVFS", "DEVFS data");
   54 
   55 static vfs_nmount_t     devfs_nmount;
   56 static vfs_unmount_t    devfs_unmount;
   57 static vfs_root_t       devfs_root;
   58 static vfs_statfs_t     devfs_statfs;
   59 
   60 /*
   61  * Mount the filesystem
   62  */
   63 static int
   64 devfs_nmount(mp, ndp, td)
   65         struct mount *mp;
   66         struct nameidata *ndp;
   67         struct thread *td;
   68 {
   69         int error;
   70         struct devfs_mount *fmp;
   71         struct vnode *rvp;
   72 
   73         error = 0;
   74         /*
   75          * XXX: flag changes.
   76          */
   77         if (mp->mnt_flag & MNT_UPDATE)
   78                 return (EOPNOTSUPP);
   79 
   80         MALLOC(fmp, struct devfs_mount *, sizeof(struct devfs_mount),
   81             M_DEVFS, M_WAITOK | M_ZERO);
   82         MALLOC(fmp->dm_dirent, struct devfs_dirent **,
   83             sizeof(struct devfs_dirent *) * NDEVFSINO,
   84             M_DEVFS, M_WAITOK | M_ZERO);
   85         lockinit(&fmp->dm_lock, PVFS, "devfs", 0, LK_NOPAUSE);
   86 
   87         mp->mnt_flag |= MNT_LOCAL;
   88 #ifdef MAC
   89         mp->mnt_flag |= MNT_MULTILABEL;
   90 #endif
   91         fmp->dm_mount = mp;
   92         mp->mnt_data = (qaddr_t) fmp;
   93         vfs_getnewfsid(mp);
   94 
   95         fmp->dm_inode = DEVFSINOMOUNT;
   96 
   97         fmp->dm_rootdir = devfs_vmkdir("(root)", 6, NULL);
   98         fmp->dm_rootdir->de_inode = 2;
   99 #ifdef MAC
  100         mac_create_devfs_directory(mp, "", 0, fmp->dm_rootdir);
  101 #endif
  102         fmp->dm_basedir = fmp->dm_rootdir;
  103         devfs_rules_newmount(fmp, td);
  104 
  105         error = devfs_root(mp, &rvp);
  106         if (error) {
  107                 lockdestroy(&fmp->dm_lock);
  108                 FREE(fmp, M_DEVFS);
  109                 return (error);
  110         }
  111         VOP_UNLOCK(rvp, 0, td);
  112 
  113         bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
  114         bcopy("devfs", mp->mnt_stat.f_mntfromname, sizeof("devfs"));
  115         (void)devfs_statfs(mp, &mp->mnt_stat, td);
  116 
  117         return (0);
  118 }
  119 
  120 static int
  121 devfs_unmount(mp, mntflags, td)
  122         struct mount *mp;
  123         int mntflags;
  124         struct thread *td;
  125 {
  126         int error;
  127         int flags = 0;
  128         struct devfs_mount *fmp;
  129 
  130         fmp = VFSTODEVFS(mp);
  131         if (mntflags & MNT_FORCE)
  132                 flags |= FORCECLOSE;
  133         /* There is 1 extra root vnode reference from devfs_mount(). */
  134         error = vflush(mp, 1, flags);
  135         if (error)
  136                 return (error);
  137         devfs_purge(fmp->dm_rootdir);
  138         mp->mnt_data = 0;
  139         lockdestroy(&fmp->dm_lock);
  140         free(fmp->dm_dirent, M_DEVFS);
  141         free(fmp, M_DEVFS);
  142         return 0;
  143 }
  144 
  145 /* Return locked reference to root.  */
  146 
  147 static int
  148 devfs_root(mp, vpp)
  149         struct mount *mp;
  150         struct vnode **vpp;
  151 {
  152         int error;
  153         struct thread *td;
  154         struct vnode *vp;
  155         struct devfs_mount *dmp;
  156 
  157         td = curthread;                                 /* XXX */
  158         dmp = VFSTODEVFS(mp);
  159         error = devfs_allocv(dmp->dm_rootdir, mp, &vp, td);
  160         if (error)
  161                 return (error);
  162         vp->v_vflag |= VV_ROOT;
  163         *vpp = vp;
  164         return (0);
  165 }
  166 
  167 static int
  168 devfs_statfs(mp, sbp, td)
  169         struct mount *mp;
  170         struct statfs *sbp;
  171         struct thread *td;
  172 {
  173 
  174         sbp->f_flags = 0;
  175         sbp->f_bsize = DEV_BSIZE;
  176         sbp->f_iosize = DEV_BSIZE;
  177         sbp->f_blocks = 2;              /* 1K to keep df happy */
  178         sbp->f_bfree = 0;
  179         sbp->f_bavail = 0;
  180         sbp->f_files = 0;
  181         sbp->f_ffree = 0;
  182         if (sbp != &mp->mnt_stat) {
  183                 sbp->f_type = mp->mnt_vfc->vfc_typenum;
  184                 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
  185                 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
  186                 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
  187         }
  188         return (0);
  189 }
  190 
  191 static struct vfsops devfs_vfsops = {
  192         NULL,
  193         vfs_stdstart,
  194         devfs_unmount,
  195         devfs_root,
  196         vfs_stdquotactl,
  197         devfs_statfs,
  198         vfs_stdsync,
  199         vfs_stdvget,
  200         vfs_stdfhtovp,
  201         vfs_stdcheckexp,
  202         vfs_stdvptofh,
  203         vfs_stdinit,
  204         vfs_stduninit,
  205         vfs_stdextattrctl,
  206         devfs_nmount,
  207 };
  208 
  209 VFS_SET(devfs_vfsops, devfs, VFCF_SYNTHETIC);
  210 #endif

Cache object: 801cbfe21a2253edfe19484876f71a53


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.