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/svr4/svr4_stat.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: svr4_stat.c,v 1.50.2.1 2004/04/21 03:12:23 jmc Exp $    */
    2 
    3 /*-
    4  * Copyright (c) 1994 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Christos Zoulas.
    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. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *        This product includes software developed by the NetBSD
   21  *        Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 __KERNEL_RCSID(0, "$NetBSD: svr4_stat.c,v 1.50.2.1 2004/04/21 03:12:23 jmc Exp $");
   41 
   42 #include <sys/param.h>
   43 #include <sys/systm.h>
   44 #include <sys/namei.h>
   45 #include <sys/proc.h>
   46 #include <sys/file.h>
   47 #include <sys/stat.h>
   48 #include <sys/filedesc.h>
   49 #include <sys/ioctl.h>
   50 #include <sys/kernel.h>
   51 #include <sys/mount.h>
   52 #include <sys/malloc.h>
   53 #include <sys/unistd.h>
   54 
   55 #include <sys/time.h>
   56 #include <sys/ucred.h>
   57 #include <uvm/uvm_extern.h>
   58 #include <sys/sysctl.h>
   59 
   60 #include <sys/sa.h>
   61 #include <sys/syscallargs.h>
   62 
   63 #include <compat/svr4/svr4_types.h>
   64 #include <compat/svr4/svr4_signal.h>
   65 #include <compat/svr4/svr4_lwp.h>
   66 #include <compat/svr4/svr4_ucontext.h>
   67 #include <compat/svr4/svr4_syscallargs.h>
   68 #include <compat/svr4/svr4_util.h>
   69 #include <compat/svr4/svr4_stat.h>
   70 #include <compat/svr4/svr4_ustat.h>
   71 #include <compat/svr4/svr4_fuser.h>
   72 #include <compat/svr4/svr4_utsname.h>
   73 #include <compat/svr4/svr4_systeminfo.h>
   74 #include <compat/svr4/svr4_time.h>
   75 #include <compat/svr4/svr4_socket.h>
   76 
   77 #ifdef __sparc__
   78 /* 
   79  * Solaris-2.4 on the sparc has the old stat call using the new
   80  * stat data structure...
   81  */
   82 # define SVR4_NO_OSTAT
   83 #endif
   84 
   85 static void bsd_to_svr4_xstat __P((struct stat *, struct svr4_xstat *));
   86 static void bsd_to_svr4_stat64 __P((struct stat *, struct svr4_stat64 *));
   87 int svr4_ustat __P((struct lwp *, void *, register_t *));
   88 static int svr4_to_bsd_pathconf __P((int));
   89 
   90 /*
   91  * SVR4 uses named pipes as named sockets, so we tell programs
   92  * that sockets are named pipes with mode 0
   93  */
   94 #define BSD_TO_SVR4_MODE(mode) (S_ISSOCK(mode) ? S_IFIFO : (mode))
   95 
   96 
   97 #ifndef SVR4_NO_OSTAT
   98 static void bsd_to_svr4_stat __P((struct stat *, struct svr4_stat *));
   99 
  100 static void
  101 bsd_to_svr4_stat(st, st4)
  102         struct stat             *st;
  103         struct svr4_stat        *st4;
  104 {
  105         memset(st4, 0, sizeof(*st4));
  106         st4->st_dev = bsd_to_svr4_odev_t(st->st_dev);
  107         st4->st_ino = st->st_ino;
  108         st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
  109         st4->st_nlink = st->st_nlink;
  110         st4->st_uid = st->st_uid;
  111         st4->st_gid = st->st_gid;
  112         st4->st_rdev = bsd_to_svr4_odev_t(st->st_rdev);
  113         st4->st_size = st->st_size;
  114         st4->st_atim = st->st_atimespec.tv_sec;
  115         st4->st_mtim = st->st_mtimespec.tv_sec;
  116         st4->st_ctim = st->st_ctimespec.tv_sec;
  117 }
  118 #endif
  119 
  120 
  121 static void
  122 bsd_to_svr4_xstat(st, st4)
  123         struct stat             *st;
  124         struct svr4_xstat       *st4;
  125 {
  126         memset(st4, 0, sizeof(*st4));
  127         st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
  128         st4->st_ino = st->st_ino;
  129         st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
  130         st4->st_nlink = st->st_nlink;
  131         st4->st_uid = st->st_uid;
  132         st4->st_gid = st->st_gid;
  133         st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
  134         st4->st_size = st->st_size;
  135         st4->st_atim.tv_sec = st->st_atimespec.tv_sec;
  136         st4->st_atim.tv_nsec = st->st_atimespec.tv_nsec;
  137         st4->st_mtim.tv_sec = st->st_mtimespec.tv_sec;
  138         st4->st_mtim.tv_nsec = st->st_mtimespec.tv_nsec;
  139         st4->st_ctim.tv_sec = st->st_ctimespec.tv_sec;
  140         st4->st_ctim.tv_nsec = st->st_ctimespec.tv_nsec;
  141         st4->st_blksize = st->st_blksize;
  142         st4->st_blocks = st->st_blocks;
  143         strlcpy(st4->st_fstype, "unknown", sizeof(st4->st_fstype));
  144 }
  145 
  146 
  147 static void
  148 bsd_to_svr4_stat64(st, st4)
  149         struct stat             *st;
  150         struct svr4_stat64      *st4;
  151 {
  152         memset(st4, 0, sizeof(*st4));
  153         st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
  154         st4->st_ino = st->st_ino;
  155         st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
  156         st4->st_nlink = st->st_nlink;
  157         st4->st_uid = st->st_uid;
  158         st4->st_gid = st->st_gid;
  159         st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
  160         st4->st_size = st->st_size;
  161         st4->st_atim.tv_sec = st->st_atimespec.tv_sec;
  162         st4->st_atim.tv_nsec = st->st_atimespec.tv_nsec;
  163         st4->st_mtim.tv_sec = st->st_mtimespec.tv_sec;
  164         st4->st_mtim.tv_nsec = st->st_mtimespec.tv_nsec;
  165         st4->st_ctim.tv_sec = st->st_ctimespec.tv_sec;
  166         st4->st_ctim.tv_nsec = st->st_ctimespec.tv_nsec;
  167         st4->st_blksize = st->st_blksize;
  168         st4->st_blocks = st->st_blocks;
  169         strlcpy(st4->st_fstype, "unknown", sizeof(st4->st_fstype));
  170 }
  171 
  172 
  173 int
  174 svr4_sys_stat(l, v, retval)
  175         struct lwp *l;
  176         void *v;
  177         register_t *retval;
  178 {
  179         struct svr4_sys_stat_args *uap = v;
  180 #ifdef SVR4_NO_OSTAT
  181         struct svr4_sys_xstat_args cup;
  182 
  183         SCARG(&cup, two) = 2;
  184         SCARG(&cup, path) = SCARG(uap, path);
  185         SCARG(&cup, ub) = (struct svr4_xstat *) SCARG(uap, ub);
  186         return svr4_sys_xstat(l, &cup, retval);
  187 #else
  188         struct proc *p = l->l_proc;
  189         struct stat             st;
  190         struct svr4_stat        svr4_st;
  191         struct sys___stat13_args        cup;
  192         int                     error;
  193 
  194         caddr_t sg = stackgap_init(p, 0);
  195         SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
  196         CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  197         SCARG(&cup, path) = SCARG(uap, path);
  198 
  199         if ((error = sys___stat13(l, &cup, retval)) != 0)
  200                 return error;
  201 
  202         if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
  203                 return error;
  204 
  205         bsd_to_svr4_stat(&st, &svr4_st);
  206 
  207         if (S_ISSOCK(st.st_mode))
  208                 (void) svr4_add_socket(p, SCARG(uap, path), &st);
  209 
  210         if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0)
  211                 return error;
  212 
  213         return 0;
  214 #endif
  215 }
  216 
  217 
  218 int
  219 svr4_sys_lstat(l, v, retval)
  220         struct lwp *l;
  221         void *v;
  222         register_t *retval;
  223 {
  224         struct svr4_sys_lstat_args *uap = v;
  225 #ifdef SVR4_NO_OSTAT
  226         struct svr4_sys_lxstat_args cup;
  227 
  228         SCARG(&cup, two) = 2;
  229         SCARG(&cup, path) = SCARG(uap, path);
  230         SCARG(&cup, ub) = (struct svr4_xstat *) SCARG(uap, ub);
  231         return svr4_sys_lxstat(l, &cup, retval);
  232 #else
  233         struct proc *p = l->l_proc;
  234         struct stat             st;
  235         struct svr4_stat        svr4_st;
  236         struct sys___lstat13_args       cup;
  237         int                     error;
  238 
  239         caddr_t sg = stackgap_init(p, 0);
  240         SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
  241         CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  242         SCARG(&cup, path) = SCARG(uap, path);
  243 
  244         if ((error = sys___lstat13(l, &cup, retval)) != 0)
  245                 return error;
  246 
  247         if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
  248                 return error;
  249 
  250         bsd_to_svr4_stat(&st, &svr4_st);
  251 
  252         if (S_ISSOCK(st.st_mode))
  253                 (void) svr4_add_socket(p, SCARG(uap, path), &st);
  254 
  255         if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0)
  256                 return error;
  257 
  258         return 0;
  259 #endif
  260 }
  261 
  262 
  263 int
  264 svr4_sys_fstat(l, v, retval)
  265         struct lwp *l;
  266         void *v;
  267         register_t *retval;
  268 {
  269         struct svr4_sys_fstat_args *uap = v;
  270 #ifdef SVR4_NO_OSTAT
  271         struct svr4_sys_fxstat_args cup;
  272 
  273         SCARG(&cup, two) = 2;
  274         SCARG(&cup, fd) = SCARG(uap, fd);
  275         SCARG(&cup, sb) = (struct svr4_xstat *) SCARG(uap, sb);
  276         return svr4_sys_fxstat(l, &cup, retval);
  277 #else
  278         struct proc *p = l->l_proc;
  279         struct stat             st;
  280         struct svr4_stat        svr4_st;
  281         struct sys___fstat13_args       cup;
  282         int                     error;
  283 
  284         caddr_t sg = stackgap_init(p, 0);
  285 
  286         SCARG(&cup, fd) = SCARG(uap, fd);
  287         SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(struct stat));
  288 
  289         if ((error = sys___fstat13(l, &cup, retval)) != 0)
  290                 return error;
  291 
  292         if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
  293                 return error;
  294 
  295         bsd_to_svr4_stat(&st, &svr4_st);
  296 
  297         if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0)
  298                 return error;
  299 
  300         return 0;
  301 #endif
  302 }
  303 
  304 
  305 int
  306 svr4_sys_xstat(l, v, retval)
  307         struct lwp *l;
  308         void *v;
  309         register_t *retval;
  310 {
  311         struct svr4_sys_xstat_args *uap = v;
  312         struct proc *p = l->l_proc;
  313         struct stat             st;
  314         struct svr4_xstat       svr4_st;
  315         struct sys___stat13_args        cup;
  316         int                     error;
  317 
  318         caddr_t sg = stackgap_init(p, 0);
  319 
  320         SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
  321         CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  322         SCARG(&cup, path) = SCARG(uap, path);
  323 
  324         if ((error = sys___stat13(l, &cup, retval)) != 0)
  325                 return error;
  326 
  327         if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
  328                 return error;
  329 
  330         bsd_to_svr4_xstat(&st, &svr4_st);
  331 
  332         if (S_ISSOCK(st.st_mode))
  333                 (void) svr4_add_socket(p, SCARG(uap, path), &st);
  334 
  335         if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0)
  336                 return error;
  337 
  338         return 0;
  339 }
  340 
  341 
  342 int
  343 svr4_sys_lxstat(l, v, retval)
  344         struct lwp *l;
  345         void *v;
  346         register_t *retval;
  347 {
  348         struct svr4_sys_lxstat_args *uap = v;
  349         struct proc *p = l->l_proc;
  350         struct stat             st;
  351         struct svr4_xstat       svr4_st;
  352         struct sys___lstat13_args       cup;
  353         int                     error;
  354 
  355         caddr_t sg = stackgap_init(p, 0);
  356 
  357         SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
  358         CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  359         SCARG(&cup, path) = SCARG(uap, path);
  360 
  361         if ((error = sys___lstat13(l, &cup, retval)) != 0)
  362                 return error;
  363 
  364         if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
  365                 return error;
  366 
  367         bsd_to_svr4_xstat(&st, &svr4_st);
  368 
  369         if (S_ISSOCK(st.st_mode))
  370                 (void) svr4_add_socket(p, SCARG(uap, path), &st);
  371 
  372         if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0)
  373                 return error;
  374 
  375         return 0;
  376 }
  377 
  378 
  379 int
  380 svr4_sys_fxstat(l, v, retval)
  381         struct lwp *l;
  382         void *v;
  383         register_t *retval;
  384 {
  385         struct svr4_sys_fxstat_args *uap = v;
  386         struct proc *p = l->l_proc;
  387         struct stat             st;
  388         struct svr4_xstat       svr4_st;
  389         struct sys___fstat13_args       cup;
  390         int                     error;
  391 
  392         caddr_t sg = stackgap_init(p, 0);
  393 
  394         SCARG(&cup, fd) = SCARG(uap, fd);
  395         SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(struct stat));
  396 
  397         if ((error = sys___fstat13(l, &cup, retval)) != 0)
  398                 return error;
  399 
  400         if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
  401                 return error;
  402 
  403         bsd_to_svr4_xstat(&st, &svr4_st);
  404 
  405         if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0)
  406                 return error;
  407 
  408         return 0;
  409 }
  410 
  411 
  412 int
  413 svr4_sys_stat64(l, v, retval)
  414         struct lwp *l;
  415         void *v;
  416         register_t *retval;
  417 {
  418         struct svr4_sys_stat64_args *uap = v;
  419         struct proc *p = l->l_proc;
  420         struct stat             st;
  421         struct svr4_stat64      svr4_st;
  422         struct sys___stat13_args        cup;
  423         int                     error;
  424 
  425         caddr_t sg = stackgap_init(p, 0);
  426 
  427         SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
  428         CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  429         SCARG(&cup, path) = SCARG(uap, path);
  430 
  431         if ((error = sys___stat13(l, &cup, retval)) != 0)
  432                 return error;
  433 
  434         if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
  435                 return error;
  436 
  437         bsd_to_svr4_stat64(&st, &svr4_st);
  438 
  439         if (S_ISSOCK(st.st_mode))
  440                 (void) svr4_add_socket(p, SCARG(uap, path), &st);
  441 
  442         if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0)
  443                 return error;
  444 
  445         return 0;
  446 }
  447 
  448 
  449 int
  450 svr4_sys_lstat64(l, v, retval)
  451         struct lwp *l;
  452         void *v;
  453         register_t *retval;
  454 {
  455         struct svr4_sys_lstat64_args *uap = v;
  456         struct proc *p = l->l_proc;
  457         struct stat             st;
  458         struct svr4_stat64      svr4_st;
  459         struct sys___lstat13_args       cup;
  460         int                     error;
  461 
  462         caddr_t sg = stackgap_init(p, 0);
  463 
  464         SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
  465         CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  466         SCARG(&cup, path) = SCARG(uap, path);
  467 
  468         if ((error = sys___lstat13(l, &cup, retval)) != 0)
  469                 return error;
  470 
  471         if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
  472                 return error;
  473 
  474         bsd_to_svr4_stat64(&st, &svr4_st);
  475 
  476         if (S_ISSOCK(st.st_mode))
  477                 (void) svr4_add_socket(p, SCARG(uap, path), &st);
  478 
  479         if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0)
  480                 return error;
  481 
  482         return 0;
  483 }
  484 
  485 
  486 int
  487 svr4_sys_fstat64(l, v, retval)
  488         struct lwp *l;
  489         void *v;
  490         register_t *retval;
  491 {
  492         struct svr4_sys_fstat64_args *uap = v;
  493         struct proc *p = l->l_proc;
  494         struct stat             st;
  495         struct svr4_stat64      svr4_st;
  496         struct sys___fstat13_args       cup;
  497         int                     error;
  498 
  499         caddr_t sg = stackgap_init(p, 0);
  500 
  501         SCARG(&cup, fd) = SCARG(uap, fd);
  502         SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(struct stat));
  503 
  504         if ((error = sys___fstat13(l, &cup, retval)) != 0)
  505                 return error;
  506 
  507         if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
  508                 return error;
  509 
  510         bsd_to_svr4_stat64(&st, &svr4_st);
  511 
  512         if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0)
  513                 return error;
  514 
  515         return 0;
  516 }
  517 
  518 
  519 struct svr4_ustat_args {
  520         syscallarg(svr4_dev_t)          dev;
  521         syscallarg(struct svr4_ustat *) name;
  522 };
  523 
  524 int
  525 svr4_ustat(l, v, retval)
  526         struct lwp *l;
  527         void *v;
  528         register_t *retval;
  529 {
  530         struct svr4_ustat_args /* {
  531                 syscallarg(svr4_dev_t)          dev;
  532                 syscallarg(struct svr4_ustat *) name;
  533         } */ *uap = v;
  534         struct svr4_ustat       us;
  535         int                     error;
  536 
  537         memset(&us, 0, sizeof us);
  538 
  539         /*
  540          * XXX: should set f_tfree and f_tinode at least
  541          * How do we translate dev -> fstat? (and then to svr4_ustat)
  542          */
  543         if ((error = copyout(&us, SCARG(uap, name), sizeof us)) != 0)
  544                 return (error);
  545 
  546         return 0;
  547 }
  548 
  549 
  550 
  551 int
  552 svr4_sys_uname(l, v, retval)
  553         struct lwp *l;
  554         void *v;
  555         register_t *retval;
  556 {
  557         struct svr4_sys_uname_args *uap = v;
  558         struct svr4_utsname     sut;
  559 
  560         memset(&sut, 0, sizeof(sut));
  561 
  562         strncpy(sut.sysname, ostype, sizeof(sut.sysname));
  563         sut.sysname[sizeof(sut.sysname) - 1] = '\0';
  564 
  565         strncpy(sut.nodename, hostname, sizeof(sut.nodename));
  566         sut.nodename[sizeof(sut.nodename) - 1] = '\0';
  567 
  568         strncpy(sut.release, osrelease, sizeof(sut.release));
  569         sut.release[sizeof(sut.release) - 1] = '\0';
  570 
  571         strncpy(sut.version, version, sizeof(sut.version));
  572         sut.version[sizeof(sut.version) - 1] = '\0';
  573 
  574         strncpy(sut.machine, machine, sizeof(sut.machine));
  575         sut.machine[sizeof(sut.machine) - 1] = '\0';
  576 
  577         return copyout((caddr_t) &sut, (caddr_t) SCARG(uap, name),
  578                        sizeof(struct svr4_utsname));
  579 }
  580 
  581 
  582 int
  583 svr4_sys_systeminfo(l, v, retval)
  584         struct lwp *l;
  585         void *v;
  586         register_t *retval;
  587 {
  588         struct svr4_sys_systeminfo_args *uap = v;
  589         const char *str = NULL;
  590         int name[2];
  591         int error;
  592         size_t len;
  593         char buf[256];
  594 
  595         u_int rlen = SCARG(uap, len);
  596 
  597         switch (SCARG(uap, what)) {
  598         case SVR4_SI_SYSNAME:
  599                 str = ostype;
  600                 break;
  601 
  602         case SVR4_SI_HOSTNAME:
  603                 str = hostname;
  604                 break;
  605 
  606         case SVR4_SI_RELEASE:
  607                 str = osrelease;
  608                 break;
  609 
  610         case SVR4_SI_VERSION:
  611                 str = version;
  612                 break;
  613 
  614         case SVR4_SI_MACHINE:
  615                 str = machine;
  616                 break;
  617 
  618         case SVR4_SI_ARCHITECTURE:
  619                 str = machine_arch;
  620                 break;
  621 
  622         case SVR4_SI_HW_SERIAL:
  623                 snprintf(buf, sizeof(buf), "%lu", hostid);
  624                 str = buf;
  625                 break;
  626 
  627         case SVR4_SI_HW_PROVIDER:
  628                 str = ostype;
  629                 break;
  630 
  631         case SVR4_SI_SRPC_DOMAIN:
  632                 str = domainname;
  633                 break;
  634 
  635         case SVR4_SI_PLATFORM:
  636 #ifdef __i386__
  637                 str = "i86pc";
  638 #elif __sparc__
  639                 str = "SUNW,SPARCstation-10";   /* XXX */
  640 #else
  641                 str = "unknown";
  642 #endif
  643                 break;
  644 
  645         case SVR4_SI_KERB_REALM:
  646                 str = "unsupported";
  647                 break;
  648 
  649         case SVR4_SI_SET_HOSTNAME:
  650                 name[1] = KERN_HOSTNAME;
  651                 break;
  652 
  653         case SVR4_SI_SET_SRPC_DOMAIN:
  654                 name[1] = KERN_DOMAINNAME;
  655                 break;
  656 
  657         case SVR4_SI_SET_KERB_REALM:
  658                 return 0;
  659 
  660         default:
  661                 DPRINTF(("Bad systeminfo command %d\n", SCARG(uap, what)));
  662                 return ENOSYS;
  663         }
  664 
  665         if (str) {
  666                 len = strlen(str) + 1;
  667                 if (len > rlen)
  668                         len = rlen;
  669 
  670                 if (SCARG(uap, buf)) {
  671                         error = copyout(str, SCARG(uap, buf), len);
  672                         if (error)
  673                                 return error;
  674                         /* make sure we are NULL terminated */
  675                         buf[0] = '\0';
  676                         error = copyout(buf, &(SCARG(uap, buf)[len - 1]), 1);
  677                 }
  678                 else
  679                         error = 0;
  680         }
  681         else {
  682                 /*
  683                  * looks redundant to do this, but actually it retrieves "len" 
  684                  */
  685                 error = copyinstr(SCARG(uap, buf), buf, sizeof(buf), &len);
  686                 if (error)
  687                         return error;
  688                 name[0] = CTL_KERN;
  689                 error = old_sysctl(&name[0], 2, 0, 0, SCARG(uap, buf), len, l);
  690         }
  691 
  692         *retval = len;
  693         return error;
  694 }
  695 
  696 
  697 int
  698 svr4_sys_utssys(l, v, retval)
  699         struct lwp *l;
  700         void *v;
  701         register_t *retval;
  702 {
  703         struct svr4_sys_utssys_args *uap = v;
  704 
  705         switch (SCARG(uap, sel)) {
  706         case 0:         /* uname(2)  */
  707                 {
  708                         struct svr4_sys_uname_args ua;
  709                         SCARG(&ua, name) = SCARG(uap, a1);
  710                         return svr4_sys_uname(l, &ua, retval);
  711                 }
  712 
  713         case 2:         /* ustat(2)  */
  714                 {
  715                         struct svr4_ustat_args ua;
  716                         SCARG(&ua, dev) = (svr4_dev_t) SCARG(uap, a2);
  717                         SCARG(&ua, name) = SCARG(uap, a1);
  718                         return svr4_ustat(l, &ua, retval);
  719                 }
  720 
  721         case 3:         /* fusers(2) */
  722                 return ENOSYS;
  723 
  724         default:
  725                 return ENOSYS;
  726         }
  727 }
  728 
  729 
  730 int
  731 svr4_sys_utime(l, v, retval)
  732         struct lwp *l;
  733         void *v;
  734         register_t *retval;
  735 {
  736         struct svr4_sys_utime_args *uap = v;
  737         struct proc *p = l->l_proc;
  738         struct svr4_utimbuf ub;
  739         struct timeval tbuf[2];
  740         struct sys_utimes_args ap;
  741         int error;
  742         void *ttp;
  743         caddr_t sg = stackgap_init(p, 0);
  744 
  745         ttp = stackgap_alloc(p, &sg, sizeof(tbuf));
  746         CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  747         SCARG(&ap, path) = SCARG(uap, path);
  748         if (SCARG(uap, ubuf) != NULL) {
  749                 if ((error = copyin(SCARG(uap, ubuf), &ub, sizeof(ub))) != 0)
  750                         return error;
  751                 tbuf[0].tv_sec = ub.actime;
  752                 tbuf[0].tv_usec = 0;
  753                 tbuf[1].tv_sec = ub.modtime;
  754                 tbuf[1].tv_usec = 0;
  755                 error = copyout(tbuf, ttp, sizeof(tbuf));
  756                 if (error)
  757                         return error;
  758                 SCARG(&ap, tptr) = ttp;
  759         }
  760         else
  761                 SCARG(&ap, tptr) = NULL;
  762         return sys_utimes(l, &ap, retval);
  763 }
  764 
  765 
  766 int
  767 svr4_sys_utimes(l, v, retval)
  768         struct lwp *l;
  769         void *v;
  770         register_t *retval;
  771 {
  772         struct svr4_sys_utimes_args *uap = v;
  773         struct proc *p = l->l_proc;
  774         caddr_t sg = stackgap_init(p, 0);
  775         CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  776         return sys_utimes(l, uap, retval);
  777 }
  778 
  779 
  780 static int
  781 svr4_to_bsd_pathconf(name)
  782         int name;
  783 {
  784         switch (name) {
  785         case SVR4_PC_LINK_MAX:
  786                 return _PC_LINK_MAX;
  787 
  788         case SVR4_PC_MAX_CANON:
  789                 return _PC_MAX_CANON;
  790 
  791         case SVR4_PC_MAX_INPUT:
  792                 return _PC_MAX_INPUT;
  793 
  794         case SVR4_PC_NAME_MAX:
  795                 return _PC_NAME_MAX;
  796 
  797         case SVR4_PC_PATH_MAX:
  798                 return _PC_PATH_MAX;
  799 
  800         case SVR4_PC_PIPE_BUF:
  801                 return _PC_PIPE_BUF;
  802 
  803         case SVR4_PC_NO_TRUNC:
  804                 return _PC_NO_TRUNC;
  805 
  806         case SVR4_PC_VDISABLE:
  807                 return _PC_VDISABLE;
  808 
  809         case SVR4_PC_CHOWN_RESTRICTED:
  810                 return _PC_CHOWN_RESTRICTED;
  811 
  812         case SVR4_PC_SYNC_IO:
  813                 return _PC_SYNC_IO;
  814 
  815         case SVR4_PC_FILESIZEBITS:
  816                 return _PC_FILESIZEBITS;
  817 
  818         case SVR4_PC_ASYNC_IO:
  819         case SVR4_PC_PRIO_IO:
  820                 /* Not supported */
  821                 return 0;
  822 
  823         default:
  824                 /* Invalid */
  825                 return -1;
  826         }
  827 }
  828 
  829 
  830 int
  831 svr4_sys_pathconf(l, v, retval)
  832         struct lwp *l;
  833         void *v;
  834         register_t *retval;
  835 {
  836         struct svr4_sys_pathconf_args *uap = v;
  837         struct proc *p = l->l_proc;
  838         caddr_t sg = stackgap_init(p, 0);
  839 
  840         CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
  841 
  842         SCARG(uap, name) = svr4_to_bsd_pathconf(SCARG(uap, name));
  843 
  844         switch (SCARG(uap, name)) {
  845         case -1:
  846                 *retval = -1;
  847                 return EINVAL;
  848         case 0:
  849                 *retval = 0;
  850                 return 0;
  851         default:
  852                 return sys_pathconf(l, uap, retval);
  853         }
  854 }
  855 
  856 
  857 int
  858 svr4_sys_fpathconf(l, v, retval)
  859         struct lwp *l;
  860         void *v;
  861         register_t *retval;
  862 {
  863         struct svr4_sys_fpathconf_args *uap = v;
  864 
  865         SCARG(uap, name) = svr4_to_bsd_pathconf(SCARG(uap, name));
  866 
  867         switch (SCARG(uap, name)) {
  868         case -1:
  869                 *retval = -1;
  870                 return EINVAL;
  871         case 0:
  872                 *retval = 0;
  873                 return 0;
  874         default:
  875                 return sys_fpathconf(l, uap, retval);
  876         }
  877 }

Cache object: eb18bbeab47197d65b191b63bf0aac23


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