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/irix/irix_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: irix_stat.c,v 1.24 2008/04/28 20:23:42 martin Exp $ */
    2 
    3 /*-
    4  * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Emmanuel Dreyfus.
    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  *
   19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   29  * POSSIBILITY OF SUCH DAMAGE.
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __KERNEL_RCSID(0, "$NetBSD: irix_stat.c,v 1.24 2008/04/28 20:23:42 martin Exp $");
   34 
   35 #include <sys/errno.h>
   36 #include <sys/types.h>
   37 #include <sys/signal.h>
   38 #include <sys/param.h>
   39 #include <sys/filedesc.h>
   40 #include <sys/proc.h>
   41 #include <sys/mount.h>
   42 #include <sys/namei.h>
   43 #include <sys/stdint.h>
   44 #include <sys/stat.h>
   45 #include <sys/systm.h>
   46 #include <sys/syscallargs.h>
   47 #include <sys/vfs_syscalls.h>
   48 
   49 #include <compat/common/compat_util.h>
   50 
   51 #include <compat/svr4/svr4_types.h>
   52 
   53 #include <compat/irix/irix_types.h>
   54 #include <compat/irix/irix_signal.h>
   55 #include <compat/irix/irix_syscall.h>
   56 #include <compat/irix/irix_syscallargs.h>
   57 
   58 static void bsd_to_irix_stat(struct stat *, struct irix_stat *);
   59 static void bsd_to_irix_stat64(struct stat *, struct irix_stat64 *);
   60 
   61 static void
   62 bsd_to_irix_stat(struct stat *bsp, struct irix_stat *isp)
   63 {
   64         memset(isp, 0, sizeof(*isp));
   65         isp->ist_dev = (irix_dev_t)bsd_to_svr4_dev_t(bsp->st_dev);
   66         isp->ist_ino = bsp->st_ino;
   67         isp->ist_mode = bsp->st_mode;   /* XXX translate it */
   68         isp->ist_nlink = bsp->st_nlink;
   69         isp->ist_uid = bsp->st_uid;
   70         isp->ist_gid = bsp->st_gid;
   71         if ((bsp->st_mode & S_IFMT) == S_IFBLK ||
   72             (bsp->st_mode & S_IFMT) == S_IFCHR)
   73                 isp->ist_rdev = (irix_dev_t)bsd_to_svr4_dev_t(bsp->st_rdev);
   74         else
   75                 isp->ist_rdev = 0;
   76         isp->ist_size = bsp->st_size;
   77         isp->ist_atim.tv_sec = bsp->st_atimespec.tv_sec;
   78         isp->ist_atim.tv_nsec = bsp->st_atimespec.tv_nsec;
   79         isp->ist_mtim.tv_sec = bsp->st_mtimespec.tv_sec;
   80         isp->ist_mtim.tv_nsec = bsp->st_mtimespec.tv_nsec;
   81         isp->ist_ctim.tv_sec = bsp->st_ctimespec.tv_sec;
   82         isp->ist_ctim.tv_nsec = bsp->st_ctimespec.tv_nsec;
   83         isp->ist_size = bsp->st_size;
   84         isp->ist_blocks = bsp->st_blocks;
   85         isp->ist_blksize = bsp->st_blksize;
   86         strlcpy(isp->ist_fstype, "unknown", sizeof(isp->ist_fstype));
   87 
   88         return;
   89 }
   90 
   91 static void
   92 bsd_to_irix_stat64(struct stat *bsp, struct irix_stat64 *isp)
   93 {
   94         memset(isp, 0, sizeof(*isp));
   95         isp->ist_dev = (irix_dev_t)bsd_to_svr4_dev_t(bsp->st_dev);
   96         isp->ist_ino = bsp->st_ino;
   97         isp->ist_mode = bsp->st_mode;   /* XXX translate it */
   98         isp->ist_nlink = bsp->st_nlink;
   99         isp->ist_uid = bsp->st_uid;
  100         isp->ist_gid = bsp->st_gid;
  101         if ((bsp->st_mode & S_IFMT) == S_IFBLK ||
  102             (bsp->st_mode & S_IFMT) == S_IFCHR)
  103                 isp->ist_rdev = (irix_dev_t)bsd_to_svr4_dev_t(bsp->st_rdev);
  104         else
  105                 isp->ist_rdev = 0;
  106         isp->ist_size = bsp->st_size;
  107         isp->ist_atim.tv_sec = bsp->st_atimespec.tv_sec;
  108         isp->ist_atim.tv_nsec = bsp->st_atimespec.tv_nsec;
  109         isp->ist_mtim.tv_sec = bsp->st_mtimespec.tv_sec;
  110         isp->ist_mtim.tv_nsec = bsp->st_mtimespec.tv_nsec;
  111         isp->ist_ctim.tv_sec = bsp->st_ctimespec.tv_sec;
  112         isp->ist_ctim.tv_nsec = bsp->st_ctimespec.tv_nsec;
  113         isp->ist_size = bsp->st_size;
  114         isp->ist_blocks = bsp->st_blocks;
  115         isp->ist_blksize = bsp->st_blksize;
  116         strlcpy(isp->ist_fstype, "unknown", sizeof(isp->ist_fstype));
  117 
  118         return;
  119 }
  120 
  121 static int
  122 convert_irix_stat(struct stat *st, void *buf, int stat_version)
  123 {
  124         switch (stat_version) {
  125         case IRIX__STAT_VER: {
  126                 struct irix_stat ist;
  127 
  128                 bsd_to_irix_stat(st, &ist);
  129                 return copyout(&ist, buf, sizeof (ist));
  130         }
  131         case IRIX__STAT64_VER: {
  132                 struct irix_stat64 ist;
  133 
  134                 bsd_to_irix_stat64(st, &ist);
  135                 return copyout(&ist, buf, sizeof (ist));
  136         }
  137         case IRIX__R3_STAT_VER:
  138         default:
  139                 printf("Warning: unimplemented irix_sys_?stat() version %d\n",
  140                     stat_version);
  141                 return EINVAL;
  142         }
  143 }
  144 
  145 int
  146 irix_sys_xstat(struct lwp *l, const struct irix_sys_xstat_args *uap, register_t *retval)
  147 {
  148         /* {
  149                 syscallarg(const int) version;
  150                 syscallarg(const char *) path;
  151                 syscallarg(struct stat *) buf;
  152         } */
  153         struct stat st;
  154         int error;
  155 
  156         error = do_sys_stat(SCARG(uap, path), FOLLOW, &st);
  157         if (error != 0)
  158                 return error;
  159 
  160         return convert_irix_stat(&st, SCARG(uap, buf), SCARG(uap, version));
  161 }
  162 
  163 int
  164 irix_sys_lxstat(struct lwp *l, const struct irix_sys_lxstat_args *uap, register_t *retval)
  165 {
  166         /* {
  167                 syscallarg(const int) version;
  168                 syscallarg(const char *) path;
  169                 syscallarg(struct stat *) buf;
  170         } */
  171         struct stat st;
  172         int error;
  173 
  174         error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &st);
  175         if (error != 0)
  176                 return error;
  177         return convert_irix_stat(&st, SCARG(uap, buf), SCARG(uap, version));
  178 }
  179 
  180 int
  181 irix_sys_fxstat(struct lwp *l, const struct irix_sys_fxstat_args *uap, register_t *retval)
  182 {
  183         /* {
  184                 syscallarg(const int) version;
  185                 syscallarg(const int) fd;
  186                 syscallarg(struct stat *) buf;
  187         } */
  188         struct stat st;
  189         int error;
  190 
  191         error = do_sys_fstat(SCARG(uap, fd), &st);
  192         if (error != 0)
  193                 return error;
  194         return convert_irix_stat(&st, SCARG(uap, buf), SCARG(uap, version));
  195 }

Cache object: 524439a304d15d3f6d0f996fdecfcd1d


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