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

Cache object: 05c5f808471b5ed1c2ab9e268b85402b


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