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

Cache object: dce609a0629b6f9ec48e14238aee2129


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