root/compat/osf1/osf1_file.c

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

DEFINITIONS

This source file includes following definitions.
  1. osf1_sys_access
  2. osf1_sys_execve
  3. osf1_sys_lstat
  4. osf1_sys_mknod
  5. osf1_sys_open
  6. osf1_sys_pathconf
  7. osf1_sys_stat
  8. osf1_sys_truncate
  9. osf1_sys_utimes

    1 /* $OpenBSD: osf1_file.c,v 1.1 2000/08/04 15:47:55 ericj Exp $ */
    2 /* $NetBSD: osf1_file.c,v 1.6 2000/06/06 19:04:17 soren Exp $ */
    3 
    4 /*
    5  * Copyright (c) 1999 Christopher G. Demetriou.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. All advertising materials mentioning features or use of this software
   16  *    must display the following acknowledgement:
   17  *      This product includes software developed by Christopher G. Demetriou
   18  *      for the NetBSD Project.
   19  * 4. The name of the author may not be used to endorse or promote products
   20  *    derived from this software without specific prior written permission
   21  *
   22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   32  */
   33 
   34 /*
   35  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
   36  * All rights reserved.
   37  *
   38  * Author: Chris G. Demetriou
   39  * 
   40  * Permission to use, copy, modify and distribute this software and
   41  * its documentation is hereby granted, provided that both the copyright
   42  * notice and this permission notice appear in all copies of the
   43  * software, derivative works or modified versions, and any portions
   44  * thereof, and that both notices appear in supporting documentation.
   45  * 
   46  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
   47  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
   48  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   49  * 
   50  * Carnegie Mellon requests users of this software to return to
   51  *
   52  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   53  *  School of Computer Science
   54  *  Carnegie Mellon University
   55  *  Pittsburgh PA 15213-3890
   56  *
   57  * any improvements or extensions that they make and grant Carnegie the
   58  * rights to redistribute these changes.
   59  */
   60 
   61 #include <sys/param.h>
   62 #include <sys/systm.h>
   63 #include <sys/namei.h>
   64 #include <sys/proc.h>
   65 #include <sys/file.h>
   66 #include <sys/stat.h>
   67 #include <sys/filedesc.h>
   68 #include <sys/kernel.h>
   69 #include <sys/malloc.h>
   70 #include <sys/mman.h>
   71 #include <sys/mount.h>
   72 #include <sys/signal.h>
   73 #include <sys/signalvar.h>
   74 #include <sys/reboot.h>
   75 #include <sys/syscallargs.h>
   76 #include <sys/exec.h>
   77 #include <sys/vnode.h>
   78 #include <sys/socketvar.h>
   79 #include <sys/resource.h>
   80 #include <sys/resourcevar.h>
   81 #include <sys/wait.h>
   82 
   83 #include <compat/osf1/osf1.h>
   84 #include <compat/osf1/osf1_syscallargs.h>
   85 #include <compat/osf1/osf1_util.h>
   86 #include <compat/osf1/osf1_cvt.h>
   87 
   88 int
   89 osf1_sys_access(p, v, retval)
   90         struct proc *p;
   91         void *v;
   92         register_t *retval;
   93 {
   94         struct osf1_sys_access_args *uap = v;
   95         struct sys_access_args a;
   96         unsigned long leftovers;
   97         caddr_t sg;
   98 
   99         sg = stackgap_init(p->p_emul);
  100         OSF1_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  101 
  102         SCARG(&a, path) = SCARG(uap, path);
  103 
  104         /* translate flags */
  105         SCARG(&a, flags) = emul_flags_translate(osf1_access_flags_xtab,
  106             SCARG(uap, flags), &leftovers);
  107         if (leftovers != 0)
  108                 return (EINVAL);
  109 
  110         return sys_access(p, &a, retval);
  111 }
  112 
  113 int
  114 osf1_sys_execve(p, v, retval)
  115         struct proc *p;
  116         void *v;
  117         register_t *retval;
  118 {
  119         struct osf1_sys_execve_args *uap = v;
  120         struct sys_execve_args ap;
  121         caddr_t sg;
  122 
  123         sg = stackgap_init(p->p_emul);
  124         OSF1_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  125 
  126         SCARG(&ap, path) = SCARG(uap, path);
  127         SCARG(&ap, argp) = SCARG(uap, argp);
  128         SCARG(&ap, envp) = SCARG(uap, envp);
  129 
  130         return sys_execve(p, &ap, retval);
  131 }
  132 
  133 /*
  134  * Get file status; this version does not follow links.
  135  */
  136 /* ARGSUSED */
  137 int
  138 osf1_sys_lstat(p, v, retval)
  139         struct proc *p;
  140         void *v;
  141         register_t *retval;
  142 {
  143         struct osf1_sys_lstat_args *uap = v;
  144         struct stat sb;
  145         struct osf1_stat osb;
  146         int error;
  147         struct nameidata nd;
  148         caddr_t sg;
  149 
  150         sg = stackgap_init(p->p_emul);
  151         OSF1_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  152 
  153         NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE,
  154             SCARG(uap, path), p);
  155         if ((error = namei(&nd)))
  156                 return (error);
  157         error = vn_stat(nd.ni_vp, &sb, p);
  158         vput(nd.ni_vp);
  159         if (error)
  160                 return (error);
  161         osf1_cvt_stat_from_native(&sb, &osb);
  162         error = copyout((caddr_t)&osb, (caddr_t)SCARG(uap, ub), sizeof (osb));
  163         return (error);
  164 }
  165 
  166 int
  167 osf1_sys_mknod(p, v, retval)
  168         struct proc *p;
  169         void *v;
  170         register_t *retval;
  171 {
  172         struct osf1_sys_mknod_args *uap = v;
  173         struct sys_mknod_args a;
  174         caddr_t sg;
  175 
  176         sg = stackgap_init(p->p_emul);
  177         OSF1_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  178 
  179         SCARG(&a, path) = SCARG(uap, path);
  180         SCARG(&a, mode) = SCARG(uap, mode);
  181         SCARG(&a, dev) = osf1_cvt_dev_to_native(SCARG(uap, dev));
  182 
  183         return sys_mknod(p, &a, retval);
  184 }
  185 
  186 int
  187 osf1_sys_open(p, v, retval)
  188         struct proc *p;
  189         void *v;
  190         register_t *retval;
  191 {
  192         struct osf1_sys_open_args *uap = v;
  193         struct sys_open_args a;
  194         char *path;
  195         caddr_t sg;
  196         unsigned long leftovers;
  197 #ifdef SYSCALL_DEBUG
  198         char pnbuf[1024];
  199 
  200         if (scdebug &&
  201             copyinstr(SCARG(uap, path), pnbuf, sizeof pnbuf, NULL) == 0)
  202                 printf("osf1_open: open: %s\n", pnbuf);
  203 #endif
  204 
  205         sg = stackgap_init(p->p_emul);
  206 
  207         /* translate flags */
  208         SCARG(&a, flags) = emul_flags_translate(osf1_open_flags_xtab,
  209             SCARG(uap, flags), &leftovers);
  210         if (leftovers != 0)
  211                 return (EINVAL);
  212 
  213         /* copy mode, no translation necessary */
  214         SCARG(&a, mode) = SCARG(uap, mode);
  215 
  216         /* pick appropriate path */
  217         path = SCARG(uap, path);
  218         if (SCARG(&a, flags) & O_CREAT)
  219                 OSF1_CHECK_ALT_CREAT(p, &sg, path);
  220         else
  221                 OSF1_CHECK_ALT_EXIST(p, &sg, path);
  222         SCARG(&a, path) = path;
  223 
  224         return sys_open(p, &a, retval);
  225 }
  226 
  227 int
  228 osf1_sys_pathconf(p, v, retval)
  229         struct proc *p;
  230         void *v;
  231         register_t *retval;
  232 {
  233         struct osf1_sys_pathconf_args *uap = v;
  234         struct sys_pathconf_args a;
  235         caddr_t sg;
  236         int error;
  237 
  238         sg = stackgap_init(p->p_emul);
  239 
  240         OSF1_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  241         SCARG(&a, path) = SCARG(uap, path);
  242 
  243         error = osf1_cvt_pathconf_name_to_native(SCARG(uap, name),
  244             &SCARG(&a, name));
  245 
  246         if (error == 0)
  247                 error = sys_pathconf(p, &a, retval);
  248 
  249         return (error);
  250 }
  251 
  252 /*
  253  * Get file status; this version follows links.
  254  */
  255 /* ARGSUSED */
  256 int
  257 osf1_sys_stat(p, v, retval)
  258         struct proc *p;
  259         void *v;
  260         register_t *retval;
  261 {
  262         struct osf1_sys_stat_args *uap = v;
  263         struct stat sb;
  264         struct osf1_stat osb;
  265         int error;
  266         struct nameidata nd;
  267         caddr_t sg;
  268 
  269         sg = stackgap_init(p->p_emul);
  270         OSF1_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  271 
  272         NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
  273             SCARG(uap, path), p);
  274         if ((error = namei(&nd)))
  275                 return (error);
  276         error = vn_stat(nd.ni_vp, &sb, p);
  277         vput(nd.ni_vp);
  278         if (error)
  279                 return (error);
  280         osf1_cvt_stat_from_native(&sb, &osb);
  281         error = copyout((caddr_t)&osb, (caddr_t)SCARG(uap, ub), sizeof (osb));
  282         return (error);
  283 }
  284 
  285 int
  286 osf1_sys_truncate(p, v, retval)
  287         struct proc *p;
  288         void *v;
  289         register_t *retval;
  290 {
  291         struct osf1_sys_truncate_args *uap = v;
  292         struct sys_truncate_args a;
  293         caddr_t sg;
  294 
  295         sg = stackgap_init(p->p_emul);
  296         OSF1_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  297 
  298         SCARG(&a, path) = SCARG(uap, path);
  299         SCARG(&a, pad) = 0;
  300         SCARG(&a, length) = SCARG(uap, length);
  301 
  302         return sys_truncate(p, &a, retval);
  303 }
  304 
  305 int
  306 osf1_sys_utimes(p, v, retval)
  307         struct proc *p;
  308         void *v;
  309         register_t *retval;
  310 {
  311         struct osf1_sys_utimes_args *uap = v;
  312         struct sys_utimes_args a;
  313         struct osf1_timeval otv;
  314         struct timeval tv;
  315         caddr_t sg;
  316         int error;
  317 
  318         sg = stackgap_init(p->p_emul);
  319 
  320         OSF1_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  321         SCARG(&a, path) = SCARG(uap, path);
  322 
  323         error = 0;
  324         if (SCARG(uap, tptr) == NULL)
  325                 SCARG(&a, tptr) = NULL;
  326         else {
  327                 SCARG(&a, tptr) = stackgap_alloc(&sg, sizeof tv);
  328 
  329                 /* get the OSF/1 timeval argument */
  330                 error = copyin((caddr_t)SCARG(uap, tptr),
  331                     (caddr_t)&otv, sizeof otv);
  332                 if (error == 0) {
  333 
  334                         /* fill in and copy out the NetBSD timeval */
  335                         memset(&tv, 0, sizeof tv);
  336                         tv.tv_sec = otv.tv_sec;
  337                         tv.tv_usec = otv.tv_usec;
  338 
  339                         error = copyout((caddr_t)&tv,
  340                             (caddr_t)SCARG(&a, tptr), sizeof tv);
  341                 }
  342         }
  343 
  344         if (error == 0)
  345                 error = sys_utimes(p, &a, retval);
  346 
  347         return (error);
  348 }

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