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/compat/osf1/osf1_mount.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 /*      $NetBSD: osf1_mount.c,v 1.45 2008/06/24 11:18:15 ad Exp $       */
    2 
    3 /*
    4  * Copyright (c) 1999 Christopher G. Demetriou.  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  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 3. All advertising materials mentioning features or use of this software
   15  *    must display the following acknowledgement:
   16  *      This product includes software developed by Christopher G. Demetriou
   17  *      for the NetBSD Project.
   18  * 4. The name of the author may not be used to endorse or promote products
   19  *    derived from this software without specific prior written permission
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   31  */
   32 
   33 /*
   34  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
   35  * All rights reserved.
   36  *
   37  * Author: Chris G. Demetriou
   38  *
   39  * Permission to use, copy, modify and distribute this software and
   40  * its documentation is hereby granted, provided that both the copyright
   41  * notice and this permission notice appear in all copies of the
   42  * software, derivative works or modified versions, and any portions
   43  * thereof, and that both notices appear in supporting documentation.
   44  *
   45  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   46  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
   47  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   48  *
   49  * Carnegie Mellon requests users of this software to return to
   50  *
   51  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   52  *  School of Computer Science
   53  *  Carnegie Mellon University
   54  *  Pittsburgh PA 15213-3890
   55  *
   56  * any improvements or extensions that they make and grant Carnegie the
   57  * rights to redistribute these changes.
   58  */
   59 
   60 #include <sys/cdefs.h>
   61 __KERNEL_RCSID(0, "$NetBSD: osf1_mount.c,v 1.45 2008/06/24 11:18:15 ad Exp $");
   62 
   63 #if defined(_KERNEL_OPT)
   64 #include "fs_nfs.h"
   65 #endif
   66 
   67 #include <sys/param.h>
   68 #include <sys/systm.h>
   69 #include <sys/namei.h>
   70 #include <sys/proc.h>
   71 #include <sys/file.h>
   72 #include <sys/filedesc.h>
   73 #include <sys/kernel.h>
   74 #include <sys/mount.h>
   75 #include <sys/vnode.h>
   76 #include <sys/syscallargs.h>
   77 
   78 #include <compat/osf1/osf1.h>
   79 #include <compat/osf1/osf1_syscallargs.h>
   80 #include <compat/common/compat_util.h>
   81 #include <compat/osf1/osf1_cvt.h>
   82 
   83 #include <net/if.h>
   84 #include <netinet/in.h>
   85 
   86 #include <nfs/rpcv2.h>
   87 #include <nfs/nfsproto.h>
   88 #include <nfs/nfs.h>
   89 #include <nfs/nfsmount.h>
   90 
   91 #include <ufs/ufs/quota.h>
   92 #include <ufs/ufs/ufsmount.h>
   93 
   94 #include <machine/vmparam.h>
   95 
   96 #define OSF1_MNT_WAIT           0x1
   97 #define OSF1_MNT_NOWAIT         0x2
   98 
   99 #define OSF1_MNT_FORCE          0x1
  100 #define OSF1_MNT_NOFORCE        0x2
  101 
  102 /* acceptable flags for various calls */
  103 #define OSF1_GETFSSTAT_FLAGS    (OSF1_MNT_WAIT|OSF1_MNT_NOWAIT)
  104 #define OSF1_MOUNT_FLAGS        0xffffffff                      /* XXX */
  105 #define OSF1_UNMOUNT_FLAGS      (OSF1_MNT_FORCE|OSF1_MNT_NOFORCE)
  106 
  107 
  108 static int      osf1_mount_mfs(struct lwp *, const struct osf1_sys_mount_args *);
  109 static int      osf1_mount_nfs(struct lwp *, const struct osf1_sys_mount_args *);
  110 
  111 int
  112 osf1_sys_fstatfs(struct lwp *l, const struct osf1_sys_fstatfs_args *uap, register_t *retval)
  113 {
  114         file_t *fp;
  115         struct mount *mp;
  116         struct statvfs *sp;
  117         struct osf1_statfs osfs;
  118         int error;
  119 
  120         /* fd_getvnode() will use the descriptor for us */
  121         if ((error = fd_getvnode(SCARG(uap, fd), &fp)))
  122                 return (error);
  123         mp = ((struct vnode *)fp->f_data)->v_mount;
  124         sp = &mp->mnt_stat;
  125         if ((error = VFS_STATVFS(mp, sp)))
  126                 goto out;
  127         sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
  128         osf1_cvt_statfs_from_native(sp, &osfs);
  129         error = copyout(&osfs, SCARG(uap, buf), min(sizeof osfs,
  130             SCARG(uap, len)));
  131  out:
  132         fd_putfile(SCARG(uap, fd));
  133         return (error);
  134 }
  135 
  136 int
  137 osf1_sys_getfsstat(struct lwp *l, const struct osf1_sys_getfsstat_args *uap, register_t *retval)
  138 {
  139         struct mount *mp, *nmp;
  140         struct statvfs *sp;
  141         struct osf1_statfs osfs;
  142         char *osf_sfsp;
  143         long count, maxcount, error;
  144 
  145         if (SCARG(uap, flags) & ~OSF1_GETFSSTAT_FLAGS)
  146                 return (EINVAL);
  147 
  148         maxcount = SCARG(uap, bufsize) / sizeof(struct osf1_statfs);
  149         osf_sfsp = (void *)SCARG(uap, buf);
  150         mutex_enter(&mountlist_lock);
  151         for (count = 0, mp = mountlist.cqh_first; mp != (void *)&mountlist;
  152             mp = nmp) {
  153                 if (vfs_busy(mp, &nmp)) {
  154                         continue;
  155                 }
  156                 if (osf_sfsp && count < maxcount) {
  157                         sp = &mp->mnt_stat;
  158                         /*
  159                          * If OSF1_MNT_NOWAIT is specified, do not refresh the
  160                          * fsstat cache.  OSF1_MNT_WAIT overrides
  161                          * OSF1_MNT_NOWAIT.
  162                          */
  163                         if (((SCARG(uap, flags) & OSF1_MNT_NOWAIT) == 0 ||
  164                             (SCARG(uap, flags) & OSF1_MNT_WAIT)) &&
  165                             (error = VFS_STATVFS(mp, sp)) == 0) {
  166                                 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
  167                                 osf1_cvt_statfs_from_native(sp, &osfs);
  168                                 if ((error = copyout(&osfs, osf_sfsp,
  169                                     sizeof (struct osf1_statfs)))) {
  170                                         vfs_unbusy(mp, false, NULL);
  171                                         return (error);
  172                                 }
  173                                 osf_sfsp += sizeof (struct osf1_statfs);
  174                         }
  175                 }
  176                 count++;
  177                 vfs_unbusy(mp, false, &nmp);
  178         }
  179         mutex_exit(&mountlist_lock);
  180         if (osf_sfsp && count > maxcount)
  181                 *retval = maxcount;
  182         else
  183                 *retval = count;
  184         return (0);
  185 }
  186 
  187 int
  188 osf1_sys_mount(struct lwp *l, const struct osf1_sys_mount_args *uap, register_t *retval)
  189 {
  190 
  191         if (SCARG(uap, flags) & ~OSF1_MOUNT_FLAGS)
  192                 return (EINVAL);
  193 
  194         /* XXX - xlate flags */
  195 
  196         switch (SCARG(uap, type)) {
  197         case OSF1_MOUNT_NFS:
  198                 return osf1_mount_nfs(l, uap);
  199                 break;
  200 
  201         case OSF1_MOUNT_MFS:
  202                 return osf1_mount_mfs(l, uap);
  203 
  204         default:
  205                 return (EINVAL);
  206         }
  207 }
  208 
  209 int
  210 osf1_sys_statfs(struct lwp *l, const struct osf1_sys_statfs_args *uap, register_t *retval)
  211 {
  212         struct mount *mp;
  213         struct statvfs *sp;
  214         struct osf1_statfs osfs;
  215         int error;
  216         struct nameidata nd;
  217 
  218         NDINIT(&nd, LOOKUP, FOLLOW | TRYEMULROOT, UIO_USERSPACE,
  219             SCARG(uap, path));
  220         if ((error = namei(&nd)))
  221                 return (error);
  222         mp = nd.ni_vp->v_mount;
  223         sp = &mp->mnt_stat;
  224         vrele(nd.ni_vp);
  225         if ((error = VFS_STATVFS(mp, sp)))
  226                 return (error);
  227         sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
  228         osf1_cvt_statfs_from_native(sp, &osfs);
  229         return copyout(&osfs, SCARG(uap, buf), min(sizeof osfs,
  230             SCARG(uap, len)));
  231 }
  232 
  233 int
  234 osf1_sys_unmount(struct lwp *l, const struct osf1_sys_unmount_args *uap, register_t *retval)
  235 {
  236         struct sys_unmount_args a;
  237 
  238         SCARG(&a, path) = SCARG(uap, path);
  239 
  240         if (SCARG(uap, flags) & ~OSF1_UNMOUNT_FLAGS)
  241                 return (EINVAL);
  242         SCARG(&a, flags) = 0;
  243         if ((SCARG(uap, flags) & OSF1_MNT_FORCE) &&
  244             (SCARG(uap, flags) & OSF1_MNT_NOFORCE) == 0)
  245                 SCARG(&a, flags) |= MNT_FORCE;
  246 
  247         return sys_unmount(l, &a, retval);
  248 }
  249 
  250 static int
  251 osf1_mount_mfs(struct lwp *l, const struct osf1_sys_mount_args *uap)
  252 {
  253         struct osf1_mfs_args osf_ma;
  254         struct mfs_args bsd_ma;
  255         int error;
  256         register_t dummy;
  257 
  258         if ((error = copyin(SCARG(uap, data), &osf_ma, sizeof osf_ma)))
  259                 return error;
  260 
  261         memset(&bsd_ma, 0, sizeof bsd_ma);
  262         bsd_ma.fspec = osf_ma.name;
  263         /* XXX export args */
  264         bsd_ma.base = osf_ma.base;
  265         bsd_ma.size = osf_ma.size;
  266 
  267         return do_sys_mount(l, vfs_getopsbyname("mfs"), NULL, SCARG(uap, path),
  268             SCARG(uap, flags), &bsd_ma, UIO_SYSSPACE, sizeof bsd_ma, &dummy);
  269 }
  270 
  271 static int
  272 osf1_mount_nfs(struct lwp *l, const struct osf1_sys_mount_args *uap)
  273 {
  274         struct osf1_nfs_args osf_na;
  275         struct nfs_args bsd_na;
  276         int error;
  277         unsigned long leftovers;
  278         register_t dummy;
  279 
  280         if ((error = copyin(SCARG(uap, data), &osf_na, sizeof osf_na)))
  281                 return error;
  282 
  283         memset(&bsd_na, 0, sizeof bsd_na);
  284         bsd_na.addr = (struct sockaddr *)osf_na.addr;
  285         bsd_na.addrlen = sizeof (struct sockaddr_in);
  286         bsd_na.fh = osf_na.fh;
  287 
  288         /* translate flags */
  289         bsd_na.flags = emul_flags_translate(osf1_nfs_mount_flags_xtab,
  290             osf_na.flags, &leftovers);
  291         if (leftovers & OSF1_NFSMNT_HOSTNAME) {
  292                 leftovers &= ~OSF1_NFSMNT_HOSTNAME;
  293                 bsd_na.hostname = osf_na.hostname;
  294         } else {
  295                 /* XXX FILL IN HOST NAME WITH IPADDR? */
  296         }
  297         if (leftovers & OSF1_NFSMNT_TCP) {
  298                 leftovers &= ~OSF1_NFSMNT_TCP;
  299                 bsd_na.sotype = SOCK_DGRAM;
  300                 bsd_na.proto = 0;
  301         } else {
  302                 bsd_na.sotype = SOCK_STREAM;
  303                 bsd_na.proto = 0;
  304         }
  305         if (leftovers != 0)
  306                 return (EINVAL);
  307 
  308         /* copy structure elements based on flags */
  309         if (bsd_na.flags & NFSMNT_WSIZE)
  310                 bsd_na.wsize = osf_na.wsize;
  311         if (bsd_na.flags & NFSMNT_RSIZE)
  312                 bsd_na.rsize = osf_na.rsize;
  313         if (bsd_na.flags & NFSMNT_TIMEO)
  314                 bsd_na.timeo = osf_na.timeo;
  315         if (bsd_na.flags & NFSMNT_RETRANS)
  316                 bsd_na.retrans = osf_na.retrans;
  317 
  318         return do_sys_mount(l, vfs_getopsbyname("nfs"), NULL, SCARG(uap, path),
  319             SCARG(uap, flags), &bsd_na, UIO_SYSSPACE, sizeof bsd_na, &dummy);
  320 
  321         return 0;
  322 }

Cache object: 6e65f4f56d55176729757989147b23a3


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