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$
   35  */
   36 
   37 #include "opt_devfs.h"
   38 #include "opt_mac.h"
   39 
   40 #include <sys/param.h>
   41 #include <sys/systm.h>
   42 #include <sys/kernel.h>
   43 #include <sys/lock.h>
   44 #include <sys/mac.h>
   45 #include <sys/malloc.h>
   46 #include <sys/mount.h>
   47 #include <sys/proc.h>
   48 #include <sys/vnode.h>
   49 
   50 #include <fs/devfs/devfs.h>
   51 
   52 MALLOC_DEFINE(M_DEVFS, "DEVFS", "DEVFS data");
   53 
   54 static vfs_mount_t      devfs_mount;
   55 static vfs_unmount_t    devfs_unmount;
   56 static vfs_root_t       devfs_root;
   57 static vfs_statfs_t     devfs_statfs;
   58 
   59 /*
   60  * Mount the filesystem
   61  */
   62 static int
   63 devfs_mount(struct mount *mp, struct thread *td)
   64 {
   65         int error;
   66         struct devfs_mount *fmp;
   67         struct vnode *rvp;
   68 
   69         error = 0;
   70         /*
   71          * XXX: flag changes.
   72          */
   73         if (mp->mnt_flag & MNT_UPDATE)
   74                 return (EOPNOTSUPP);
   75 
   76         MALLOC(fmp, struct devfs_mount *, sizeof(struct devfs_mount),
   77             M_DEVFS, M_WAITOK | M_ZERO);
   78         MALLOC(fmp->dm_dirent, struct devfs_dirent **,
   79             sizeof(struct devfs_dirent *) * NDEVFSINO,
   80             M_DEVFS, M_WAITOK | M_ZERO);
   81         lockinit(&fmp->dm_lock, PVFS, "devfs", 0, LK_NOPAUSE);
   82 
   83         mp->mnt_flag |= MNT_LOCAL;
   84 #ifdef MAC
   85         mp->mnt_flag |= MNT_MULTILABEL;
   86 #endif
   87         fmp->dm_mount = mp;
   88         mp->mnt_data = (qaddr_t) fmp;
   89         vfs_getnewfsid(mp);
   90 
   91         fmp->dm_inode = DEVFSINOMOUNT;
   92 
   93         fmp->dm_rootdir = devfs_vmkdir("(root)", 6, NULL);
   94         fmp->dm_rootdir->de_inode = 2;
   95 #ifdef MAC
   96         mac_create_devfs_directory(mp, "", 0, fmp->dm_rootdir);
   97 #endif
   98         fmp->dm_basedir = fmp->dm_rootdir;
   99         devfs_rules_newmount(fmp, td);
  100 
  101         error = devfs_root(mp, &rvp, td);
  102         if (error) {
  103                 lockdestroy(&fmp->dm_lock);
  104                 FREE(fmp, M_DEVFS);
  105                 return (error);
  106         }
  107         VOP_UNLOCK(rvp, 0, td);
  108 
  109         bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
  110         bcopy("devfs", mp->mnt_stat.f_mntfromname, sizeof("devfs"));
  111         (void)devfs_statfs(mp, &mp->mnt_stat, td);
  112 
  113         return (0);
  114 }
  115 
  116 static int
  117 devfs_unmount(mp, mntflags, td)
  118         struct mount *mp;
  119         int mntflags;
  120         struct thread *td;
  121 {
  122         int error;
  123         int flags = 0;
  124         struct devfs_mount *fmp;
  125 
  126         fmp = VFSTODEVFS(mp);
  127         if (mntflags & MNT_FORCE)
  128                 flags |= FORCECLOSE;
  129         /* There is 1 extra root vnode reference from devfs_mount(). */
  130         error = vflush(mp, 1, flags, td);
  131         if (error)
  132                 return (error);
  133         devfs_purge(fmp->dm_rootdir);
  134         mp->mnt_data = 0;
  135         lockdestroy(&fmp->dm_lock);
  136         free(fmp->dm_dirent, M_DEVFS);
  137         free(fmp, M_DEVFS);
  138         return 0;
  139 }
  140 
  141 /* Return locked reference to root.  */
  142 
  143 static int
  144 devfs_root(mp, vpp, td)
  145         struct mount *mp;
  146         struct vnode **vpp;
  147         struct thread *td;
  148 {
  149         int error;
  150         struct vnode *vp;
  151         struct devfs_mount *dmp;
  152 
  153         dmp = VFSTODEVFS(mp);
  154         error = devfs_allocv(dmp->dm_rootdir, mp, &vp, td);
  155         if (error)
  156                 return (error);
  157         vp->v_vflag |= VV_ROOT;
  158         *vpp = vp;
  159         return (0);
  160 }
  161 
  162 static int
  163 devfs_statfs(mp, sbp, td)
  164         struct mount *mp;
  165         struct statfs *sbp;
  166         struct thread *td;
  167 {
  168 
  169         sbp->f_flags = 0;
  170         sbp->f_bsize = DEV_BSIZE;
  171         sbp->f_iosize = DEV_BSIZE;
  172         sbp->f_blocks = 2;              /* 1K to keep df happy */
  173         sbp->f_bfree = 0;
  174         sbp->f_bavail = 0;
  175         sbp->f_files = 0;
  176         sbp->f_ffree = 0;
  177         if (sbp != &mp->mnt_stat) {
  178                 sbp->f_type = mp->mnt_vfc->vfc_typenum;
  179                 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
  180                 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
  181                 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
  182         }
  183         return (0);
  184 }
  185 
  186 static struct vfsops devfs_vfsops = {
  187         .vfs_mount =            devfs_mount,
  188         .vfs_root =             devfs_root,
  189         .vfs_statfs =           devfs_statfs,
  190         .vfs_unmount =          devfs_unmount,
  191 };
  192 
  193 VFS_SET(devfs_vfsops, devfs, VFCF_SYNTHETIC);

Cache object: 635eca23659484b244cd481fcea7c803


[ 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.