[BACK]Return to ibcs2_stat.c CVS log [TXT][DIR] Up to [local] / sys / compat / ibcs2

Annotation of sys/compat/ibcs2/ibcs2_stat.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: ibcs2_stat.c,v 1.13 2004/07/09 23:52:02 millert Exp $ */
                      2: /*     $NetBSD: ibcs2_stat.c,v 1.5 1996/05/03 17:05:32 christos Exp $  */
                      3:
                      4: /*
                      5:  * Copyright (c) 1995 Scott Bartram
                      6:  * All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. The name of the author may not be used to endorse or promote products
                     17:  *    derived from this software without specific prior written permission
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     20:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     21:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     22:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     23:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     24:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     25:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     26:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     27:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     28:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     29:  */
                     30:
                     31: #include <sys/param.h>
                     32: #include <sys/systm.h>
                     33: #include <sys/namei.h>
                     34: #include <sys/proc.h>
                     35: #include <sys/file.h>
                     36: #include <sys/stat.h>
                     37: #include <sys/filedesc.h>
                     38: #include <sys/ioctl.h>
                     39: #include <sys/kernel.h>
                     40: #include <sys/mount.h>
                     41: #include <sys/malloc.h>
                     42: #include <sys/vnode.h>
                     43: #include <sys/syscallargs.h>
                     44:
                     45: #include <uvm/uvm_extern.h>
                     46:
                     47: #include <compat/ibcs2/ibcs2_types.h>
                     48: #include <compat/ibcs2/ibcs2_fcntl.h>
                     49: #include <compat/ibcs2/ibcs2_signal.h>
                     50: #include <compat/ibcs2/ibcs2_stat.h>
                     51: #include <compat/ibcs2/ibcs2_statfs.h>
                     52: #include <compat/ibcs2/ibcs2_syscallargs.h>
                     53: #include <compat/ibcs2/ibcs2_ustat.h>
                     54: #include <compat/ibcs2/ibcs2_util.h>
                     55: #include <compat/ibcs2/ibcs2_utsname.h>
                     56:
                     57: static void bsd_stat2ibcs_stat(struct stat43 *, 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 stat43 *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:        st4->st_size = (ibcs2_off_t)st->st_size;
                     74:        st4->st_atim = (ibcs2_time_t)st->st_atime;
                     75:        st4->st_mtim = (ibcs2_time_t)st->st_mtime;
                     76:        st4->st_ctim = (ibcs2_time_t)st->st_ctime;
                     77: }
                     78:
                     79: static int
                     80: cvt_statfs(sp, buf, len)
                     81:        struct statfs *sp;
                     82:        caddr_t buf;
                     83:        int len;
                     84: {
                     85:        struct ibcs2_statfs ssfs;
                     86:
                     87:        if (len < 0)
                     88:                return (EINVAL);
                     89:        if (len > sizeof(ssfs))
                     90:                len = sizeof(ssfs);
                     91:
                     92:        bzero(&ssfs, sizeof ssfs);
                     93:        ssfs.f_fstyp = 0;
                     94:        ssfs.f_bsize = sp->f_bsize;
                     95:        ssfs.f_frsize = 0;
                     96:        ssfs.f_blocks = sp->f_blocks;
                     97:        ssfs.f_bfree = sp->f_bfree;
                     98:        ssfs.f_files = sp->f_files;
                     99:        ssfs.f_ffree = sp->f_ffree;
                    100:        ssfs.f_fname[0] = 0;
                    101:        ssfs.f_fpack[0] = 0;
                    102:        return copyout((caddr_t)&ssfs, buf, len);
                    103: }
                    104:
                    105: int
                    106: ibcs2_sys_statfs(p, v, retval)
                    107:        struct proc *p;
                    108:        void *v;
                    109:        register_t *retval;
                    110: {
                    111:        struct ibcs2_sys_statfs_args /* {
                    112:                syscallarg(char *) path;
                    113:                syscallarg(struct ibcs2_statfs *) buf;
                    114:                syscallarg(int) len;
                    115:                syscallarg(int) fstype;
                    116:        } */ *uap = v;
                    117:        register struct mount *mp;
                    118:        register struct statfs *sp;
                    119:        int error;
                    120:        struct nameidata nd;
                    121:        caddr_t sg = stackgap_init(p->p_emul);
                    122:
                    123:        IBCS2_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
                    124:        NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
                    125:        if ((error = namei(&nd)) != 0)
                    126:                return (error);
                    127:        mp = nd.ni_vp->v_mount;
                    128:        sp = &mp->mnt_stat;
                    129:        vrele(nd.ni_vp);
                    130:        if ((error = VFS_STATFS(mp, sp, p)) != 0)
                    131:                return (error);
                    132:        sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
                    133:        return cvt_statfs(sp, (caddr_t)SCARG(uap, buf), SCARG(uap, len));
                    134: }
                    135:
                    136: int
                    137: ibcs2_sys_fstatfs(p, v, retval)
                    138:        struct proc *p;
                    139:        void *v;
                    140:        register_t *retval;
                    141: {
                    142:        struct ibcs2_sys_fstatfs_args /* {
                    143:                syscallarg(int) fd;
                    144:                syscallarg(struct ibcs2_statfs *) buf;
                    145:                syscallarg(int) len;
                    146:                syscallarg(int) fstype;
                    147:        } */ *uap = v;
                    148:        struct file *fp;
                    149:        struct mount *mp;
                    150:        register struct statfs *sp;
                    151:        int error;
                    152:
                    153:        if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
                    154:                return (error);
                    155:        mp = ((struct vnode *)fp->f_data)->v_mount;
                    156:        sp = &mp->mnt_stat;
                    157:        error = VFS_STATFS(mp, sp, p);
                    158:        FRELE(fp);
                    159:        if (error)
                    160:                return (error);
                    161:        sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
                    162:        return cvt_statfs(sp, (caddr_t)SCARG(uap, buf), SCARG(uap, len));
                    163: }
                    164:
                    165: int
                    166: ibcs2_sys_stat(p, v, retval)
                    167:        struct proc *p;
                    168:        void *v;
                    169:        register_t *retval;
                    170: {
                    171:        struct ibcs2_sys_stat_args /* {
                    172:                syscallarg(char *) path;
                    173:                syscallarg(struct ibcs2_stat *) st;
                    174:        } */ *uap = v;
                    175:        struct stat43 st;
                    176:        struct ibcs2_stat ibcs2_st;
                    177:        struct compat_43_sys_stat_args cup;
                    178:        int error;
                    179:        caddr_t sg = stackgap_init(p->p_emul);
                    180:
                    181:        SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
                    182:        IBCS2_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
                    183:        SCARG(&cup, path) = SCARG(uap, path);
                    184:
                    185:        if ((error = compat_43_sys_stat(p, &cup, retval)) != 0)
                    186:                return error;
                    187:        if ((error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
                    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_sys_lstat(p, v, retval)
                    196:        struct proc *p;
                    197:        void *v;
                    198:        register_t *retval;
                    199: {
                    200:        struct ibcs2_sys_lstat_args /* {
                    201:                syscallarg(char *) path;
                    202:                syscallarg(struct ibcs2_stat *) st;
                    203:        } */ *uap = v;
                    204:        struct stat43 st;
                    205:        struct ibcs2_stat ibcs2_st;
                    206:        struct compat_43_sys_lstat_args cup;
                    207:        int error;
                    208:        caddr_t sg = stackgap_init(p->p_emul);
                    209:
                    210:        SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
                    211:        IBCS2_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
                    212:        SCARG(&cup, path) = SCARG(uap, path);
                    213:
                    214:        if ((error = compat_43_sys_lstat(p, &cup, retval)) != 0)
                    215:                return error;
                    216:        if ((error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
                    217:                return error;
                    218:        bsd_stat2ibcs_stat(&st, &ibcs2_st);
                    219:        return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st),
                    220:                       ibcs2_stat_len);
                    221: }
                    222:
                    223: int
                    224: ibcs2_sys_fstat(p, v, retval)
                    225:        struct proc *p;
                    226:        void *v;
                    227:        register_t *retval;
                    228: {
                    229:        struct ibcs2_sys_fstat_args /* {
                    230:                syscallarg(int) fd;
                    231:                syscallarg(struct ibcs2_stat *) st;
                    232:        } */ *uap = v;
                    233:        struct stat43 st;
                    234:        struct ibcs2_stat ibcs2_st;
                    235:        struct compat_43_sys_fstat_args cup;
                    236:        int error;
                    237:        caddr_t sg = stackgap_init(p->p_emul);
                    238:
                    239:        SCARG(&cup, fd) = SCARG(uap, fd);
                    240:        SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
                    241:        if ((error = compat_43_sys_fstat(p, &cup, retval)) != 0)
                    242:                return error;
                    243:        if ((error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
                    244:                return error;
                    245:        bsd_stat2ibcs_stat(&st, &ibcs2_st);
                    246:        return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st),
                    247:                       ibcs2_stat_len);
                    248: }
                    249:
                    250: int
                    251: ibcs2_sys_utssys(p, v, retval)
                    252:        struct proc *p;
                    253:        void *v;
                    254:        register_t *retval;
                    255: {
                    256:        struct ibcs2_sys_utssys_args /* {
                    257:                syscallarg(int) a1;
                    258:                syscallarg(int) a2;
                    259:                syscallarg(int) flag;
                    260:        } */ *uap = v;
                    261:
                    262:        switch (SCARG(uap, flag)) {
                    263:        case 0:                 /* uname(2) */
                    264:        {
                    265:                struct ibcs2_utsname sut;
                    266:                extern char machine[];
                    267:
                    268:                bzero(&sut, ibcs2_utsname_len);
                    269:                bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
                    270:                bcopy(hostname, sut.nodename, sizeof(sut.nodename));
                    271:                sut.nodename[sizeof(sut.nodename)-1] = '\0';
                    272:                bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
                    273:                strlcpy(sut.version, "1", sizeof(sut.version));
                    274:                bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
                    275:
                    276:                return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, a1),
                    277:                               ibcs2_utsname_len);
                    278:        }
                    279:
                    280:        case 2:                 /* ustat(2) */
                    281:        {
                    282:                return ENOSYS;  /* XXX - TODO */
                    283:        }
                    284:
                    285:        default:
                    286:                return ENOSYS;
                    287:        }
                    288: }

CVSweb