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-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 /*
    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/param.h>
   30 #include <sys/systm.h>
   31 #include <sys/namei.h>
   32 #include <sys/proc.h>
   33 #include <sys/file.h>
   34 #include <sys/stat.h>
   35 #include <sys/filedesc.h>
   36 #include <sys/ioctl.h>
   37 #include <sys/kernel.h>
   38 #include <sys/mount.h>
   39 #include <sys/malloc.h>
   40 #include <sys/vnode.h>
   41 #include <sys/sysctl.h>
   42 #include <sys/sysproto.h>
   43 
   44 #include <vm/vm.h>
   45 
   46 #include <i386/ibcs2/ibcs2_types.h>
   47 #include <i386/ibcs2/ibcs2_fcntl.h>
   48 #include <i386/ibcs2/ibcs2_signal.h>
   49 #include <i386/ibcs2/ibcs2_stat.h>
   50 #include <i386/ibcs2/ibcs2_statfs.h>
   51 #include <i386/ibcs2/ibcs2_proto.h>
   52 #include <i386/ibcs2/ibcs2_ustat.h>
   53 #include <i386/ibcs2/ibcs2_util.h>
   54 #include <i386/ibcs2/ibcs2_utsname.h>
   55 
   56 static void bsd_stat2ibcs_stat __P((struct stat *, struct ibcs2_stat *));
   57 static int  cvt_statfs         __P((struct statfs *, caddr_t, int));
   58 
   59 static void
   60 bsd_stat2ibcs_stat(st, st4)
   61         struct stat *st;
   62         struct ibcs2_stat *st4;
   63 {
   64         bzero(st4, sizeof(*st4));
   65         st4->st_dev  = (ibcs2_dev_t)st->st_dev;
   66         st4->st_ino  = (ibcs2_ino_t)st->st_ino;
   67         st4->st_mode = (ibcs2_mode_t)st->st_mode;
   68         st4->st_nlink= (ibcs2_nlink_t)st->st_nlink;
   69         st4->st_uid  = (ibcs2_uid_t)st->st_uid;
   70         st4->st_gid  = (ibcs2_gid_t)st->st_gid;
   71         st4->st_rdev = (ibcs2_dev_t)st->st_rdev;
   72         if (st->st_size < (quad_t)1 << 32)
   73                 st4->st_size = (ibcs2_off_t)st->st_size;
   74         else
   75                 st4->st_size = -2;
   76         st4->st_atim = (ibcs2_time_t)st->st_atime;
   77         st4->st_mtim = (ibcs2_time_t)st->st_mtime;
   78         st4->st_ctim = (ibcs2_time_t)st->st_ctime;
   79 }
   80 
   81 static int
   82 cvt_statfs(sp, buf, len)
   83         struct statfs *sp;
   84         caddr_t buf;
   85         int len;
   86 {
   87         struct ibcs2_statfs ssfs;
   88 
   89         bzero(&ssfs, sizeof ssfs);
   90         ssfs.f_fstyp = 0;
   91         ssfs.f_bsize = sp->f_bsize;
   92         ssfs.f_frsize = 0;
   93         ssfs.f_blocks = sp->f_blocks;
   94         ssfs.f_bfree = sp->f_bfree;
   95         ssfs.f_files = sp->f_files;
   96         ssfs.f_ffree = sp->f_ffree;
   97         ssfs.f_fname[0] = 0;
   98         ssfs.f_fpack[0] = 0;
   99         return copyout((caddr_t)&ssfs, buf, len);
  100 }       
  101 
  102 int
  103 ibcs2_statfs(p, uap, retval)
  104         struct proc *p;
  105         struct ibcs2_statfs_args *uap;
  106         int *retval;
  107 {
  108         register struct mount *mp;
  109         register struct statfs *sp;
  110         int error;
  111         struct nameidata nd;
  112         caddr_t sg = stackgap_init();
  113 
  114         CHECKALTEXIST(p, &sg, SCARG(uap, path));
  115         NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
  116         if (error = namei(&nd))
  117                 return (error);
  118         mp = nd.ni_vp->v_mount;
  119         sp = &mp->mnt_stat;
  120         vrele(nd.ni_vp);
  121         if (error = VFS_STATFS(mp, sp, p))
  122                 return (error);
  123         sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
  124         return cvt_statfs(sp, (caddr_t)SCARG(uap, buf), SCARG(uap, len));
  125 }
  126 
  127 int
  128 ibcs2_fstatfs(p, uap, retval)
  129         struct proc *p;
  130         struct ibcs2_fstatfs_args *uap;
  131         int *retval;
  132 {
  133         struct file *fp;
  134         struct mount *mp;
  135         register struct statfs *sp;
  136         int error;
  137 
  138         if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
  139                 return (error);
  140         mp = ((struct vnode *)fp->f_data)->v_mount;
  141         sp = &mp->mnt_stat;
  142         if (error = VFS_STATFS(mp, sp, p))
  143                 return (error);
  144         sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
  145         return cvt_statfs(sp, (caddr_t)SCARG(uap, buf), SCARG(uap, len));
  146 }
  147 
  148 int
  149 ibcs2_stat(p, uap, retval)
  150         struct proc *p;
  151         struct ibcs2_stat_args *uap;
  152         int *retval;
  153 {
  154         struct stat st;
  155         struct ibcs2_stat ibcs2_st;
  156         struct stat_args cup;
  157         int error;
  158         caddr_t sg = stackgap_init();
  159 
  160         CHECKALTEXIST(p, &sg, SCARG(uap, path));
  161         SCARG(&cup, path) = SCARG(uap, path);
  162         SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
  163 
  164         if (error = stat(p, &cup, retval))
  165                 return error;
  166 
  167         if (error = copyin(SCARG(&cup, ub), &st, sizeof(st)))
  168                 return error;
  169         bsd_stat2ibcs_stat(&st, &ibcs2_st);
  170         return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st),
  171                        ibcs2_stat_len);
  172 }
  173 
  174 int
  175 ibcs2_lstat(p, uap, retval)
  176         struct proc *p;
  177         struct ibcs2_lstat_args *uap;
  178         int *retval;
  179 {
  180         struct stat st;
  181         struct ibcs2_stat ibcs2_st;
  182         struct lstat_args cup;
  183         int error;
  184         caddr_t sg = stackgap_init();
  185 
  186         CHECKALTEXIST(p, &sg, SCARG(uap, path));
  187         SCARG(&cup, path) = SCARG(uap, path);
  188         SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
  189 
  190         if (error = lstat(p, &cup, retval))
  191                 return error;
  192 
  193         if (error = copyin(SCARG(&cup, ub), &st, sizeof(st)))
  194                 return error;
  195         bsd_stat2ibcs_stat(&st, &ibcs2_st);
  196         return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st),
  197                        ibcs2_stat_len);
  198 }
  199 
  200 int
  201 ibcs2_fstat(p, uap, retval)
  202         struct proc *p;
  203         struct ibcs2_fstat_args *uap;
  204         int *retval;
  205 {
  206         struct stat st;
  207         struct ibcs2_stat ibcs2_st;
  208         struct fstat_args cup;
  209         int error;
  210         caddr_t sg = stackgap_init();
  211 
  212         SCARG(&cup, fd) = SCARG(uap, fd);
  213         SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
  214 
  215         if (error = fstat(p, &cup, retval))
  216                 return error;
  217 
  218         if (error = copyin(SCARG(&cup, sb), &st, sizeof(st)))
  219                 return error;
  220         bsd_stat2ibcs_stat(&st, &ibcs2_st);
  221         return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st),
  222                        ibcs2_stat_len);
  223 }
  224 
  225 int
  226 ibcs2_utssys(p, uap, retval)
  227         struct proc *p;
  228         struct ibcs2_utssys_args *uap;
  229         int *retval;
  230 {
  231         switch (SCARG(uap, flag)) {
  232         case 0:                 /* uname(2) */
  233         {
  234                 char machine_name[9], *p;
  235                 struct ibcs2_utsname sut;
  236                 bzero(&sut, ibcs2_utsname_len);
  237 
  238                 strncpy(sut.sysname, IBCS2_UNAME_SYSNAME, sizeof(sut.sysname));
  239                 strncpy(sut.release, IBCS2_UNAME_RELEASE, sizeof(sut.release));
  240                 strncpy(sut.version, IBCS2_UNAME_VERSION, sizeof(sut.version));
  241                 strncpy(machine_name, hostname, sizeof(machine_name));
  242                 p = index(machine_name, '.');
  243                 if ( p )
  244                         *p = '\0';
  245                 strncpy(sut.nodename, machine_name, sizeof(sut.nodename));
  246                 strncpy(sut.machine, machine, sizeof(sut.machine));
  247                 sut.sysname[sizeof(sut.sysname)-1] = '\0';
  248                 sut.release[sizeof(sut.release)-1] = '\0';
  249                 sut.version[sizeof(sut.version)-1] = '\0';
  250                 sut.nodename[sizeof(sut.nodename)-1] = '\0';
  251                 sut.machine[sizeof(sut.machine)-1] = '\0';
  252 
  253                 DPRINTF(("IBCS2 uname: sys=%s rel=%s ver=%s node=%s mach=%s\n",
  254                          sut.sysname, sut.release, sut.version, sut.nodename,
  255                          sut.machine));
  256                 return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, a1),
  257                                ibcs2_utsname_len);
  258         }
  259 
  260         case 2:                 /* ustat(2) */
  261         {
  262                 return ENOSYS;  /* XXX - TODO */
  263         }
  264 
  265         default:
  266                 return ENOSYS;
  267         }
  268 }

Cache object: 1a53b814976a427d57e326ccd0844169


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