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/i386/ibcs2/ibcs2_stat.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  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 Scott Bartram
    3  * Copyright (c) 1995 Steven Wallace
    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  * 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. The name of the author may not be used to endorse or promote products
   15  *    derived from this software without specific prior written permission
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   27  */
   28 
   29 #include <sys/cdefs.h>
   30 __FBSDID("$FreeBSD: releng/11.2/sys/i386/ibcs2/ibcs2_stat.c 331722 2018-03-29 02:50:57Z eadler $");
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/namei.h>
   35 #include <sys/fcntl.h>
   36 #include <sys/file.h>
   37 #include <sys/stat.h>
   38 #include <sys/filedesc.h>
   39 #include <sys/jail.h>
   40 #include <sys/kernel.h>
   41 #include <sys/malloc.h>
   42 #include <sys/mount.h>
   43 #include <sys/malloc.h>
   44 #include <sys/vnode.h>
   45 #include <sys/syscallsubr.h>
   46 #include <sys/sysctl.h>
   47 #include <sys/sysproto.h>
   48 
   49 #include <i386/ibcs2/ibcs2_signal.h>
   50 #include <i386/ibcs2/ibcs2_stat.h>
   51 #include <i386/ibcs2/ibcs2_statfs.h>
   52 #include <i386/ibcs2/ibcs2_proto.h>
   53 #include <i386/ibcs2/ibcs2_util.h>
   54 #include <i386/ibcs2/ibcs2_utsname.h>
   55 
   56 
   57 static void bsd_stat2ibcs_stat(struct stat *, struct ibcs2_stat *);
   58 static int  cvt_statfs(struct statfs *, caddr_t, int);
   59 
   60 static void
   61 bsd_stat2ibcs_stat(st, st4)
   62         struct stat *st;
   63         struct ibcs2_stat *st4;
   64 {
   65         bzero(st4, sizeof(*st4));
   66         st4->st_dev  = (ibcs2_dev_t)st->st_dev;
   67         st4->st_ino  = (ibcs2_ino_t)st->st_ino;
   68         st4->st_mode = (ibcs2_mode_t)st->st_mode;
   69         st4->st_nlink= (ibcs2_nlink_t)st->st_nlink;
   70         st4->st_uid  = (ibcs2_uid_t)st->st_uid;
   71         st4->st_gid  = (ibcs2_gid_t)st->st_gid;
   72         st4->st_rdev = (ibcs2_dev_t)st->st_rdev;
   73         if (st->st_size < (quad_t)1 << 32)
   74                 st4->st_size = (ibcs2_off_t)st->st_size;
   75         else
   76                 st4->st_size = -2;
   77         st4->st_atim = (ibcs2_time_t)st->st_atim.tv_sec;
   78         st4->st_mtim = (ibcs2_time_t)st->st_mtim.tv_sec;
   79         st4->st_ctim = (ibcs2_time_t)st->st_ctim.tv_sec;
   80 }
   81 
   82 static int
   83 cvt_statfs(sp, buf, len)
   84         struct statfs *sp;
   85         caddr_t buf;
   86         int len;
   87 {
   88         struct ibcs2_statfs ssfs;
   89 
   90         if (len < 0)
   91                 return (EINVAL);
   92         else if (len > sizeof(ssfs))
   93                 len = sizeof(ssfs);
   94         bzero(&ssfs, sizeof ssfs);
   95         ssfs.f_fstyp = 0;
   96         ssfs.f_bsize = sp->f_bsize;
   97         ssfs.f_frsize = 0;
   98         ssfs.f_blocks = sp->f_blocks;
   99         ssfs.f_bfree = sp->f_bfree;
  100         ssfs.f_files = sp->f_files;
  101         ssfs.f_ffree = sp->f_ffree;
  102         ssfs.f_fname[0] = 0;
  103         ssfs.f_fpack[0] = 0;
  104         return copyout((caddr_t)&ssfs, buf, len);
  105 }       
  106 
  107 int
  108 ibcs2_statfs(td, uap)
  109         struct thread *td;
  110         struct ibcs2_statfs_args *uap;
  111 {
  112         struct statfs *sf;
  113         char *path;
  114         int error;
  115 
  116         CHECKALTEXIST(td, uap->path, &path);
  117         sf = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
  118         error = kern_statfs(td, path, UIO_SYSSPACE, sf);
  119         free(path, M_TEMP);
  120         if (error == 0)
  121                 error = cvt_statfs(sf, (caddr_t)uap->buf, uap->len);
  122         free(sf, M_STATFS);
  123         return (error);
  124 }
  125 
  126 int
  127 ibcs2_fstatfs(td, uap)
  128         struct thread *td;
  129         struct ibcs2_fstatfs_args *uap;
  130 {
  131         struct statfs *sf;
  132         int error;
  133 
  134         sf = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
  135         error = kern_fstatfs(td, uap->fd, sf);
  136         if (error == 0)
  137                 error = cvt_statfs(sf, (caddr_t)uap->buf, uap->len);
  138         free(sf, M_STATFS);
  139         return (error);
  140 }
  141 
  142 int
  143 ibcs2_stat(td, uap)
  144         struct thread *td;
  145         struct ibcs2_stat_args *uap;
  146 {
  147         struct ibcs2_stat ibcs2_st;
  148         struct stat st;
  149         char *path;
  150         int error;
  151 
  152         CHECKALTEXIST(td, uap->path, &path);
  153 
  154         error = kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &st, NULL);
  155         free(path, M_TEMP);
  156         if (error)
  157                 return (error);
  158         bsd_stat2ibcs_stat(&st, &ibcs2_st);
  159         return copyout((caddr_t)&ibcs2_st, (caddr_t)uap->st,
  160                        ibcs2_stat_len);
  161 }
  162 
  163 int
  164 ibcs2_lstat(td, uap)
  165         struct thread *td;
  166         struct ibcs2_lstat_args *uap;
  167 {
  168         struct ibcs2_stat ibcs2_st;
  169         struct stat st;
  170         char *path;
  171         int error;
  172 
  173         CHECKALTEXIST(td, uap->path, &path);
  174 
  175         error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path,
  176             UIO_SYSSPACE, &st, NULL);
  177         free(path, M_TEMP);
  178         if (error)
  179                 return (error);
  180         bsd_stat2ibcs_stat(&st, &ibcs2_st);
  181         return copyout((caddr_t)&ibcs2_st, (caddr_t)uap->st,
  182                        ibcs2_stat_len);
  183 }
  184 
  185 int
  186 ibcs2_fstat(td, uap)
  187         struct thread *td;
  188         struct ibcs2_fstat_args *uap;
  189 {
  190         struct ibcs2_stat ibcs2_st;
  191         struct stat st;
  192         int error;
  193 
  194         error = kern_fstat(td, uap->fd, &st);
  195         if (error)
  196                 return (error);
  197         bsd_stat2ibcs_stat(&st, &ibcs2_st);
  198         return copyout((caddr_t)&ibcs2_st, (caddr_t)uap->st,
  199                        ibcs2_stat_len);
  200 }
  201 
  202 int
  203 ibcs2_utssys(td, uap)
  204         struct thread *td;
  205         struct ibcs2_utssys_args *uap;
  206 {
  207         switch (uap->flag) {
  208         case 0:                 /* uname(2) */
  209         {
  210                 char machine_name[9], *p;
  211                 struct ibcs2_utsname sut;
  212                 bzero(&sut, ibcs2_utsname_len);
  213 
  214                 strncpy(sut.sysname,
  215                         IBCS2_UNAME_SYSNAME, sizeof(sut.sysname) - 1);
  216                 strncpy(sut.release,
  217                         IBCS2_UNAME_RELEASE, sizeof(sut.release) - 1);
  218                 strncpy(sut.version,
  219                         IBCS2_UNAME_VERSION, sizeof(sut.version) - 1);
  220                 getcredhostname(td->td_ucred, machine_name,
  221                     sizeof(machine_name) - 1);
  222                 p = strchr(machine_name, '.');
  223                 if ( p )
  224                         *p = '\0';
  225                 strncpy(sut.nodename, machine_name, sizeof(sut.nodename) - 1);
  226                 strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
  227 
  228                 DPRINTF(("IBCS2 uname: sys=%s rel=%s ver=%s node=%s mach=%s\n",
  229                          sut.sysname, sut.release, sut.version, sut.nodename,
  230                          sut.machine));
  231                 return copyout((caddr_t)&sut, (caddr_t)uap->a1,
  232                                ibcs2_utsname_len);
  233         }
  234 
  235         case 2:                 /* ustat(2) */
  236         {
  237                 return ENOSYS;  /* XXX - TODO */
  238         }
  239 
  240         default:
  241                 return ENOSYS;
  242         }
  243 }

Cache object: 55e47915d10169332be24d09bca960a2


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