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/xfs/xfs_vfsops-common.c

Version: -  FREEBSD  -  FREEBSD11  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1995 - 2002 Kungliga Tekniska Högskolan
    3  * (Royal Institute of Technology, Stockholm, Sweden).
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  *
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  *
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  *
   17  * 3. Neither the name of the Institute nor the names of its contributors
   18  *    may be used to endorse or promote products derived from this software
   19  *    without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
   25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   31  * SUCH DAMAGE.
   32  */
   33 
   34 #include <xfs/xfs_locl.h>
   35 
   36 RCSID("$arla: xfs_vfsops-common.c,v 1.40 2003/06/02 18:26:40 lha Exp $");
   37 
   38 /*
   39  * NNPFS vfs operations.
   40  */
   41 
   42 #include <xfs/xfs_common.h>
   43 #include <xfs/xfs_message.h>
   44 #include <xfs/xfs_fs.h>
   45 #include <xfs/xfs_dev.h>
   46 #include <xfs/xfs_deb.h>
   47 #include <xfs/xfs_syscalls.h>
   48 #include <xfs/xfs_vfsops.h>
   49 
   50 #ifdef HAVE_KERNEL_UDEV2DEV
   51 #define VA_RDEV_TO_DEV(x) udev2dev(x, 0) /* XXX what is the 0 */
   52 #else
   53 #define VA_RDEV_TO_DEV(x) x
   54 #endif
   55 
   56 
   57 struct xfs xfs[NNNPFS];
   58 
   59 /*
   60  * path and data is in system memory
   61  */
   62 
   63 int
   64 xfs_mount_common_sys(struct mount *mp,
   65                      const char *path,
   66                      void *data,
   67                      struct nameidata *ndp,
   68                      d_thread_t *p)
   69 {
   70     struct vnode *devvp;
   71     dev_t dev;
   72     int error;
   73     struct vattr vat;
   74 
   75     NNPFSDEB(XDEBVFOPS, ("xfs_mount: "
   76                        "struct mount mp = %lx path = '%s' data = '%s'\n",
   77                        (unsigned long)mp, path, (char *)data));
   78 
   79 #ifdef ARLA_KNFS
   80     NNPFSDEB(XDEBVFOPS, ("xfs_mount: mount flags = %x\n", mp->mnt_flag));
   81 
   82     /*
   83      * mountd(8) flushes all export entries when it starts
   84      * right now we ignore it (but should not)
   85      */
   86 
   87     if (mp->mnt_flag & MNT_UPDATE ||
   88         mp->mnt_flag & MNT_DELEXPORT) {
   89 
   90         NNPFSDEB(XDEBVFOPS, 
   91                ("xfs_mount: ignoring MNT_UPDATE or MNT_DELEXPORT\n"));
   92         return 0;
   93     }
   94 #endif
   95 
   96     NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, data, p);
   97     error = namei(ndp);
   98     if (error) {
   99         NNPFSDEB(XDEBVFOPS, ("namei failed, errno = %d\n", error));
  100         return error;
  101     }
  102 
  103     devvp = ndp->ni_vp;
  104 
  105     if (devvp->v_type != VCHR) {
  106         vput(devvp);
  107         NNPFSDEB(XDEBVFOPS, ("not VCHR (%d)\n", devvp->v_type));
  108         return ENXIO;
  109     }
  110 #if defined(__osf__)
  111     VOP_GETATTR(devvp, &vat, ndp->ni_cred, error);
  112 #elif defined(HAVE_FREEBSD_THREAD)
  113     error = VOP_GETATTR(devvp, &vat, p->td_proc->p_ucred, p);
  114 #else
  115     error = VOP_GETATTR(devvp, &vat, p->p_ucred, p);
  116 #endif
  117     vput(devvp);
  118     if (error) {
  119         NNPFSDEB(XDEBVFOPS, ("VOP_GETATTR failed, error = %d\n", error));
  120         return error;
  121     }
  122 
  123     dev = VA_RDEV_TO_DEV(vat.va_rdev);
  124 
  125     NNPFSDEB(XDEBVFOPS, ("dev = %d.%d\n", major(dev), minor(dev)));
  126 
  127     if (!xfs_is_xfs_dev (dev)) {
  128         NNPFSDEB(XDEBVFOPS, ("%s is not a xfs device\n", (char *)data));
  129         return ENXIO;
  130     }
  131 
  132     if (xfs[minor(dev)].status & NNPFS_MOUNTED)
  133         return EBUSY;
  134 
  135     xfs[minor(dev)].status = NNPFS_MOUNTED;
  136     xfs[minor(dev)].mp = mp;
  137     xfs[minor(dev)].root = 0;
  138     xfs[minor(dev)].nnodes = 0;
  139     xfs[minor(dev)].fd = minor(dev);
  140 
  141     nnfs_init_head(&xfs[minor(dev)].nodehead);
  142 
  143     VFS_TO_NNPFS(mp) = &xfs[minor(dev)];
  144 #if defined(HAVE_KERNEL_VFS_GETNEWFSID)
  145 #if defined(HAVE_TWO_ARGUMENT_VFS_GETNEWFSID)
  146     vfs_getnewfsid(mp, MOUNT_AFS);
  147 #else
  148     vfs_getnewfsid(mp);
  149 #endif /* HAVE_TWO_ARGUMENT_VFS_GETNEWFSID */
  150 #endif /* HAVE_KERNEL_VFS_GETNEWFSID */
  151 
  152     mp->mnt_stat.f_bsize = DEV_BSIZE;
  153 #ifndef __osf__
  154     mp->mnt_stat.f_iosize = DEV_BSIZE;
  155     mp->mnt_stat.f_owner = 0;
  156 #endif
  157     mp->mnt_stat.f_blocks = 4711 * 4711;
  158     mp->mnt_stat.f_bfree = 4711 * 4711;
  159     mp->mnt_stat.f_bavail = 4711 * 4711;
  160     mp->mnt_stat.f_files = 4711;
  161     mp->mnt_stat.f_ffree = 4711;
  162     mp->mnt_stat.f_flags = mp->mnt_flag;
  163 
  164 #ifdef __osf__
  165     mp->mnt_stat.f_fsid.val[0] = dev;
  166     mp->mnt_stat.f_fsid.val[1] = MOUNT_NNPFS;
  167         
  168     mp->m_stat.f_mntonname = malloc(strlen(path) + 1, M_PATHNAME, M_WAITOK);
  169     strcpy(mp->m_stat.f_mntonname, path);
  170 
  171     mp->m_stat.f_mntfromname = malloc(sizeof("arla"), M_PATHNAME, M_WAITOK);
  172     strcpy(mp->m_stat.f_mntfromname, "arla");
  173 #else /* __osf__ */
  174     strncpy(mp->mnt_stat.f_mntonname,
  175             path,
  176             sizeof(mp->mnt_stat.f_mntonname));
  177 
  178     strncpy(mp->mnt_stat.f_mntfromname,
  179             data,
  180             sizeof(mp->mnt_stat.f_mntfromname));
  181 
  182     strncpy(mp->mnt_stat.f_fstypename,
  183             "xfs",
  184             sizeof(mp->mnt_stat.f_fstypename));
  185 #endif /* __osf__ */
  186 
  187     return 0;
  188 }
  189 
  190 int
  191 xfs_mount_common(struct mount *mp,
  192                  const char *user_path,
  193                  void *user_data,
  194                  struct nameidata *ndp,
  195                  d_thread_t *p)
  196 {
  197     char *path = NULL;
  198     char *data = NULL;
  199     size_t count;
  200     int error = 0;
  201 
  202     data = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
  203     if (data == NULL) {
  204         error = ENOMEM;
  205         goto done;
  206     }
  207     path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
  208     if (path == NULL) {
  209         error = ENOMEM;
  210         goto done;
  211     }
  212 
  213     error = copyinstr(user_path, path, MAXPATHLEN, &count);
  214     if (error)
  215         goto done;      
  216 
  217     error = copyinstr(user_data, data, MAXPATHLEN, &count);
  218     if (error)
  219         goto done;
  220     error = xfs_mount_common_sys (mp, path, data, ndp, p);
  221 done:
  222     free(data, M_TEMP);
  223     free(path, M_TEMP);                 
  224     return(error);      
  225 }
  226 
  227 #ifdef HAVE_KERNEL_DOFORCE
  228 extern int doforce;
  229 #endif
  230 
  231 int
  232 xfs_unmount_common(struct mount *mp, int mntflags)
  233 {
  234     struct xfs *xfsp = VFS_TO_NNPFS(mp);
  235     int flags = 0;
  236     int error;
  237 
  238     if (mntflags & MNT_FORCE) {
  239 #ifdef HAVE_KERNEL_DOFORCE
  240         if (!doforce)
  241             return EINVAL;
  242 #endif
  243         flags |= FORCECLOSE;
  244     }
  245 
  246     error = free_all_xfs_nodes(xfsp, flags, 1);
  247     if (error)
  248         return error;
  249 
  250     xfsp->status = 0;
  251     NNPFS_TO_VFS(xfsp) = NULL;
  252     return 0;
  253 }
  254 
  255 int
  256 xfs_root_common(struct mount *mp, struct vnode **vpp,
  257                 d_thread_t *proc, struct ucred *cred)
  258 {
  259     struct xfs *xfsp = VFS_TO_NNPFS(mp);
  260     struct xfs_message_getroot msg;
  261     int error;
  262 
  263     do {
  264         if (xfsp->root != NULL) {
  265             *vpp = XNODE_TO_VNODE(xfsp->root);
  266             xfs_do_vget(*vpp, LK_EXCLUSIVE, proc);
  267             return 0;
  268         }
  269         msg.header.opcode = NNPFS_MSG_GETROOT;
  270         msg.cred.uid = cred->cr_uid;
  271         msg.cred.pag = xfs_get_pag(cred);
  272         error = xfs_message_rpc(xfsp->fd, &msg.header, sizeof(msg), proc);
  273         if (error == 0)
  274             error = ((struct xfs_message_wakeup *) & msg)->error;
  275     } while (error == 0);
  276     /*
  277      * Failed to get message through, need to pretend that all went well
  278      * and return a fake dead vnode to be able to unmount.
  279      */
  280 
  281     if ((error = xfs_make_dead_vnode(mp, vpp)))
  282         return error;
  283 
  284     NNPFS_MAKE_VROOT(*vpp);
  285     return 0;
  286 }

Cache object: fac91b000d0c7cab6e4106492ba441f6


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