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

Annotation of sys/compat/svr4/svr4_stat.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: svr4_stat.c,v 1.27 2005/08/07 00:18:33 deraadt Exp $   */
        !             2: /*     $NetBSD: svr4_stat.c,v 1.21 1996/04/22 01:16:07 christos Exp $   */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1994 Christos Zoulas
        !             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/unistd.h>
        !            43:
        !            44: #include <sys/time.h>
        !            45: #include <sys/ucred.h>
        !            46: #include <uvm/uvm_extern.h>
        !            47: #include <sys/sysctl.h>
        !            48:
        !            49: #include <sys/syscallargs.h>
        !            50:
        !            51: #include <compat/svr4/svr4_types.h>
        !            52: #include <compat/svr4/svr4_signal.h>
        !            53: #include <compat/svr4/svr4_syscallargs.h>
        !            54: #include <compat/svr4/svr4_util.h>
        !            55: #include <compat/svr4/svr4_stat.h>
        !            56: #include <compat/svr4/svr4_ustat.h>
        !            57: #include <compat/svr4/svr4_fuser.h>
        !            58: #include <compat/svr4/svr4_utsname.h>
        !            59: #include <compat/svr4/svr4_systeminfo.h>
        !            60: #include <compat/svr4/svr4_time.h>
        !            61: #include <compat/svr4/svr4_socket.h>
        !            62:
        !            63: #ifdef __sparc__
        !            64: /*
        !            65:  * Solaris-2.4 on the sparc has the old stat call using the new
        !            66:  * stat data structure...
        !            67:  */
        !            68: # define SVR4_NO_OSTAT
        !            69: #endif
        !            70:
        !            71: static void bsd_to_svr4_xstat(struct stat *, struct svr4_xstat *);
        !            72: static void bsd_to_svr4_stat64(struct stat *, struct svr4_stat64 *);
        !            73: int svr4_ustat(struct proc *, void *, register_t *);
        !            74: static int svr4_to_bsd_pathconf(int);
        !            75:
        !            76: /*
        !            77:  * SVR4 uses named pipes as named sockets, so we tell programs
        !            78:  * that sockets are named pipes with mode 0
        !            79:  */
        !            80: #define BSD_TO_SVR4_MODE(mode) (S_ISSOCK(mode) ? S_IFIFO : (mode))
        !            81:
        !            82:
        !            83: #ifndef SVR4_NO_OSTAT
        !            84: static void bsd_to_svr4_stat(struct stat *, struct svr4_stat *);
        !            85:
        !            86: static void
        !            87: bsd_to_svr4_stat(st, st4)
        !            88:        struct stat             *st;
        !            89:        struct svr4_stat        *st4;
        !            90: {
        !            91:        bzero(st4, sizeof(*st4));
        !            92:        st4->st_dev = bsd_to_svr4_odev_t(st->st_dev);
        !            93:        st4->st_ino = st->st_ino;
        !            94:        st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
        !            95:        st4->st_nlink = st->st_nlink;
        !            96:        st4->st_uid = st->st_uid;
        !            97:        st4->st_gid = st->st_gid;
        !            98:        st4->st_rdev = bsd_to_svr4_odev_t(st->st_rdev);
        !            99:        st4->st_size = st->st_size;
        !           100:        st4->st_atim = st->st_atimespec.tv_sec;
        !           101:        st4->st_mtim = st->st_mtimespec.tv_sec;
        !           102:        st4->st_ctim = st->st_ctimespec.tv_sec;
        !           103: }
        !           104: #endif
        !           105:
        !           106:
        !           107: static void
        !           108: bsd_to_svr4_xstat(st, st4)
        !           109:        struct stat             *st;
        !           110:        struct svr4_xstat       *st4;
        !           111: {
        !           112:        bzero(st4, sizeof(*st4));
        !           113:        st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
        !           114:        st4->st_ino = st->st_ino;
        !           115:        st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
        !           116:        st4->st_nlink = st->st_nlink;
        !           117:        st4->st_uid = st->st_uid;
        !           118:        st4->st_gid = st->st_gid;
        !           119:        st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
        !           120:        st4->st_size = st->st_size;
        !           121:        st4->st_atim = st->st_atimespec;
        !           122:        st4->st_mtim = st->st_mtimespec;
        !           123:        st4->st_ctim = st->st_ctimespec;
        !           124:        st4->st_blksize = st->st_blksize;
        !           125:        st4->st_blocks = st->st_blocks;
        !           126:        strlcpy(st4->st_fstype, "unknown", sizeof st4->st_fstype);
        !           127: }
        !           128:
        !           129: static void
        !           130: bsd_to_svr4_stat64(st, st4)
        !           131:        struct stat             *st;
        !           132:        struct svr4_stat64      *st4;
        !           133: {
        !           134:        bzero(st4, sizeof(*st4));
        !           135:        st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
        !           136:        st4->st_ino = st->st_ino;
        !           137:        st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
        !           138:        st4->st_nlink = st->st_nlink;
        !           139:        st4->st_uid = st->st_uid;
        !           140:        st4->st_gid = st->st_gid;
        !           141:        st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
        !           142:        st4->st_size = st->st_size;
        !           143:        st4->st_atim = st->st_atimespec;
        !           144:        st4->st_mtim = st->st_mtimespec;
        !           145:        st4->st_ctim = st->st_ctimespec;
        !           146:        st4->st_blksize = st->st_blksize;
        !           147:        st4->st_blocks = st->st_blocks;
        !           148:        strlcpy(st4->st_fstype, "unknown", sizeof st4->st_fstype);
        !           149: }
        !           150:
        !           151:
        !           152: int
        !           153: svr4_sys_stat(p, v, retval)
        !           154:        register struct proc *p;
        !           155:        void *v;
        !           156:        register_t *retval;
        !           157: {
        !           158:        struct svr4_sys_stat_args *uap = v;
        !           159: #ifdef SVR4_NO_OSTAT
        !           160:        struct svr4_sys_xstat_args cup;
        !           161:
        !           162:        SCARG(&cup, two) = 2;
        !           163:        SCARG(&cup, path) = SCARG(uap, path);
        !           164:        SCARG(&cup, ub) = (struct svr4_xstat *) SCARG(uap, ub);
        !           165:        return svr4_sys_xstat(p, &cup, retval);
        !           166: #else
        !           167:        struct stat             st;
        !           168:        struct svr4_stat        svr4_st;
        !           169:        struct sys_stat_args    cup;
        !           170:        int                     error;
        !           171:
        !           172:        caddr_t sg = stackgap_init(p->p_emul);
        !           173:        SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
        !           174:        SVR4_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           175:
        !           176:        SCARG(&cup, path) = SCARG(uap, path);
        !           177:
        !           178:
        !           179:        if ((error = sys_stat(p, &cup, retval)) != 0)
        !           180:                return error;
        !           181:
        !           182:        if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
        !           183:                return error;
        !           184:
        !           185:        bsd_to_svr4_stat(&st, &svr4_st);
        !           186:
        !           187:        if (S_ISSOCK(st.st_mode))
        !           188:                (void) svr4_add_socket(p, SCARG(uap, path), &st);
        !           189:
        !           190:        if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0)
        !           191:                return error;
        !           192:
        !           193:        return 0;
        !           194: #endif
        !           195: }
        !           196:
        !           197: int
        !           198: svr4_sys_lstat(p, v, retval)
        !           199:        register struct proc *p;
        !           200:        void *v;
        !           201:        register_t *retval;
        !           202: {
        !           203:        struct svr4_sys_lstat_args *uap = v;
        !           204: #ifdef SVR4_NO_OSTAT
        !           205:        struct svr4_sys_lxstat_args cup;
        !           206:
        !           207:        SCARG(&cup, two) = 2;
        !           208:        SCARG(&cup, path) = SCARG(uap, path);
        !           209:        SCARG(&cup, ub) = (struct svr4_xstat *) SCARG(uap, ub);
        !           210:        return svr4_sys_lxstat(p, &cup, retval);
        !           211: #else
        !           212:        struct stat             st;
        !           213:        struct svr4_stat        svr4_st;
        !           214:        struct sys_lstat_args   cup;
        !           215:        int                     error;
        !           216:
        !           217:        caddr_t sg = stackgap_init(p->p_emul);
        !           218:        SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
        !           219:        SVR4_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           220:
        !           221:        SCARG(&cup, path) = SCARG(uap, path);
        !           222:
        !           223:        if ((error = sys_lstat(p, &cup, retval)) != 0)
        !           224:                return error;
        !           225:
        !           226:        if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
        !           227:                return error;
        !           228:
        !           229:        bsd_to_svr4_stat(&st, &svr4_st);
        !           230:
        !           231:        if (S_ISSOCK(st.st_mode))
        !           232:                (void) svr4_add_socket(p, SCARG(uap, path), &st);
        !           233:
        !           234:        if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0)
        !           235:                return error;
        !           236:
        !           237:        return 0;
        !           238: #endif
        !           239: }
        !           240:
        !           241: int
        !           242: svr4_sys_fstat(p, v, retval)
        !           243:        register struct proc *p;
        !           244:        void *v;
        !           245:        register_t *retval;
        !           246: {
        !           247:        struct svr4_sys_fstat_args *uap = v;
        !           248: #ifdef SVR4_NO_OSTAT
        !           249:        struct svr4_sys_fxstat_args cup;
        !           250:
        !           251:        SCARG(&cup, two) = 2;
        !           252:        SCARG(&cup, fd) = SCARG(uap, fd);
        !           253:        SCARG(&cup, sb) = (struct svr4_xstat *) SCARG(uap, sb);
        !           254:        return svr4_sys_fxstat(p, &cup, retval);
        !           255: #else
        !           256:        struct stat             st;
        !           257:        struct svr4_stat        svr4_st;
        !           258:        struct sys_fstat_args   cup;
        !           259:        int                     error;
        !           260:
        !           261:        caddr_t sg = stackgap_init(p->p_emul);
        !           262:
        !           263:        SCARG(&cup, fd) = SCARG(uap, fd);
        !           264:        SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(struct stat));
        !           265:
        !           266:        if ((error = sys_fstat(p, &cup, retval)) != 0)
        !           267:                return error;
        !           268:
        !           269:        if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
        !           270:                return error;
        !           271:
        !           272:        bsd_to_svr4_stat(&st, &svr4_st);
        !           273:
        !           274:        if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0)
        !           275:                return error;
        !           276:
        !           277:        return 0;
        !           278: #endif
        !           279: }
        !           280:
        !           281:
        !           282: int
        !           283: svr4_sys_xstat(p, v, retval)
        !           284:        register struct proc *p;
        !           285:        void *v;
        !           286:        register_t *retval;
        !           287: {
        !           288:        struct svr4_sys_xstat_args *uap = v;
        !           289:        struct stat             st;
        !           290:        struct svr4_xstat       svr4_st;
        !           291:        struct sys_stat_args    cup;
        !           292:        int                     error;
        !           293:
        !           294:        caddr_t sg = stackgap_init(p->p_emul);
        !           295:        SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
        !           296:        SVR4_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           297:
        !           298:        SCARG(&cup, path) = SCARG(uap, path);
        !           299:
        !           300:        if ((error = sys_stat(p, &cup, retval)) != 0)
        !           301:                return error;
        !           302:
        !           303:        if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
        !           304:                return error;
        !           305:
        !           306:        bsd_to_svr4_xstat(&st, &svr4_st);
        !           307:
        !           308:        if (S_ISSOCK(st.st_mode))
        !           309:                (void) svr4_add_socket(p, SCARG(uap, path), &st);
        !           310:
        !           311:        if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0)
        !           312:                return error;
        !           313:
        !           314:        return 0;
        !           315: }
        !           316:
        !           317: int
        !           318: svr4_sys_lxstat(p, v, retval)
        !           319:        register struct proc *p;
        !           320:        void *v;
        !           321:        register_t *retval;
        !           322: {
        !           323:        struct svr4_sys_lxstat_args *uap = v;
        !           324:        struct stat             st;
        !           325:        struct svr4_xstat       svr4_st;
        !           326:        struct sys_lstat_args   cup;
        !           327:        int                     error;
        !           328:
        !           329:        caddr_t sg = stackgap_init(p->p_emul);
        !           330:        SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
        !           331:        SVR4_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           332:
        !           333:        SCARG(&cup, path) = SCARG(uap, path);
        !           334:
        !           335:        if ((error = sys_lstat(p, &cup, retval)) != 0)
        !           336:                return error;
        !           337:
        !           338:        if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
        !           339:                return error;
        !           340:
        !           341:        bsd_to_svr4_xstat(&st, &svr4_st);
        !           342:
        !           343:        if (S_ISSOCK(st.st_mode))
        !           344:                (void) svr4_add_socket(p, SCARG(uap, path), &st);
        !           345:
        !           346:        if ((error = copyout(&svr4_st, SCARG(uap, ub), sizeof svr4_st)) != 0)
        !           347:                return error;
        !           348:
        !           349:        return 0;
        !           350: }
        !           351:
        !           352: int
        !           353: svr4_sys_fxstat(p, v, retval)
        !           354:        register struct proc *p;
        !           355:        void *v;
        !           356:        register_t *retval;
        !           357: {
        !           358:        struct svr4_sys_fxstat_args *uap = v;
        !           359:        struct stat             st;
        !           360:        struct svr4_xstat       svr4_st;
        !           361:        struct sys_fstat_args   cup;
        !           362:        int                     error;
        !           363:
        !           364:        caddr_t sg = stackgap_init(p->p_emul);
        !           365:
        !           366:        SCARG(&cup, fd) = SCARG(uap, fd);
        !           367:        SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(struct stat));
        !           368:
        !           369:        if ((error = sys_fstat(p, &cup, retval)) != 0)
        !           370:                return error;
        !           371:
        !           372:        if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
        !           373:                return error;
        !           374:
        !           375:        bsd_to_svr4_xstat(&st, &svr4_st);
        !           376:
        !           377:        if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0)
        !           378:                return error;
        !           379:
        !           380:        return 0;
        !           381: }
        !           382:
        !           383:
        !           384: int
        !           385: svr4_sys_stat64(p, v, retval)
        !           386:        struct proc *p;
        !           387:        void *v;
        !           388:        register_t *retval;
        !           389: {
        !           390:        struct svr4_sys_stat64_args *uap = v;
        !           391:        struct stat             st;
        !           392:        struct svr4_stat64      svr4_st;
        !           393:        struct sys_stat_args    cup;
        !           394:        int                     error;
        !           395:
        !           396:        caddr_t sg = stackgap_init(p->p_emul);
        !           397:
        !           398:        SCARG(&cup, path) = SCARG(uap, path);
        !           399:        SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
        !           400:
        !           401:        if ((error = sys_stat(p, &cup, retval)) != 0)
        !           402:                return error;
        !           403:
        !           404:        if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
        !           405:                return error;
        !           406:
        !           407:        bsd_to_svr4_stat64(&st, &svr4_st);
        !           408:
        !           409:        if (S_ISSOCK(st.st_mode))
        !           410:                (void) svr4_add_socket(p, SCARG(uap, path), &st);
        !           411:
        !           412:        if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0)
        !           413:                return error;
        !           414:
        !           415:        return 0;
        !           416: }
        !           417:
        !           418:
        !           419: int
        !           420: svr4_sys_lstat64(p, v, retval)
        !           421:        struct proc *p;
        !           422:        void *v;
        !           423:        register_t *retval;
        !           424: {
        !           425:        struct svr4_sys_lstat64_args *uap = v;
        !           426:        struct stat             st;
        !           427:        struct svr4_stat64      svr4_st;
        !           428:        struct sys_lstat_args   cup;
        !           429:        int                     error;
        !           430:
        !           431:        caddr_t sg = stackgap_init(p->p_emul);
        !           432:
        !           433:        SCARG(&cup, path) = SCARG(uap, path);
        !           434:        SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(struct stat));
        !           435:
        !           436:        if ((error = sys_lstat(p, &cup, retval)) != 0)
        !           437:                return error;
        !           438:
        !           439:        if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
        !           440:                return error;
        !           441:
        !           442:        bsd_to_svr4_stat64(&st, &svr4_st);
        !           443:
        !           444:        if (S_ISSOCK(st.st_mode))
        !           445:                (void) svr4_add_socket(p, SCARG(uap, path), &st);
        !           446:
        !           447:        if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0)
        !           448:                return error;
        !           449:
        !           450:        return 0;
        !           451: }
        !           452:
        !           453:
        !           454: int
        !           455: svr4_sys_fstat64(p, v, retval)
        !           456:        register struct proc *p;
        !           457:        void *v;
        !           458:        register_t *retval;
        !           459: {
        !           460:        struct svr4_sys_fstat64_args *uap = v;
        !           461:        struct stat             st;
        !           462:        struct svr4_stat64      svr4_st;
        !           463:        struct sys_fstat_args   cup;
        !           464:        int                     error;
        !           465:
        !           466:        caddr_t sg = stackgap_init(p->p_emul);
        !           467:
        !           468:        SCARG(&cup, fd) = SCARG(uap, fd);
        !           469:        SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(struct stat));
        !           470:
        !           471:        if ((error = sys_fstat(p, &cup, retval)) != 0)
        !           472:                return error;
        !           473:
        !           474:        if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
        !           475:                return error;
        !           476:
        !           477:        bsd_to_svr4_stat64(&st, &svr4_st);
        !           478:
        !           479:        if ((error = copyout(&svr4_st, SCARG(uap, sb), sizeof svr4_st)) != 0)
        !           480:                return error;
        !           481:
        !           482:        return 0;
        !           483: }
        !           484:
        !           485:
        !           486: struct svr4_ustat_args {
        !           487:        syscallarg(svr4_dev_t)          dev;
        !           488:        syscallarg(struct svr4_ustat *) name;
        !           489: };
        !           490:
        !           491: int
        !           492: svr4_ustat(p, v, retval)
        !           493:        register struct proc *p;
        !           494:        void *v;
        !           495:        register_t *retval;
        !           496: {
        !           497:        struct svr4_ustat_args /* {
        !           498:                syscallarg(svr4_dev_t)          dev;
        !           499:                syscallarg(struct svr4_ustat *) name;
        !           500:        } */ *uap = v;
        !           501:        struct svr4_ustat       us;
        !           502:        int                     error;
        !           503:
        !           504:        bzero(&us, sizeof us);
        !           505:
        !           506:        /*
        !           507:         * XXX: should set f_tfree and f_tinode at least
        !           508:         * How do we translate dev -> fstat? (and then to svr4_ustat)
        !           509:         */
        !           510:        if ((error = copyout(&us, SCARG(uap, name), sizeof us)) != 0)
        !           511:                return (error);
        !           512:
        !           513:        return 0;
        !           514: }
        !           515:
        !           516:
        !           517:
        !           518: int
        !           519: svr4_sys_uname(p, v, retval)
        !           520:        register struct proc *p;
        !           521:        void *v;
        !           522:        register_t *retval;
        !           523: {
        !           524:        struct svr4_sys_uname_args *uap = v;
        !           525:        struct svr4_utsname     *sut;
        !           526:        extern char hostname[], machine[];
        !           527:        const char *cp;
        !           528:        char *dp, *ep;
        !           529:        int error;
        !           530:
        !           531:        sut = malloc(sizeof(*sut), M_TEMP, M_WAITOK);
        !           532:        bzero(sut, sizeof(*sut));
        !           533:        strlcpy(sut->sysname, ostype, sizeof(sut->sysname));
        !           534:        strlcpy(sut->nodename, hostname, sizeof(sut->nodename));
        !           535:        strlcpy(sut->release, osrelease, sizeof(sut->release));
        !           536:
        !           537:        dp = sut->version;
        !           538:        ep = &sut->version[sizeof(sut->version) - 1];
        !           539:        for (cp = version; *cp && *cp != '('; cp++)
        !           540:                ;
        !           541:        for (cp++; *cp && *cp != ')' && dp < ep; cp++)
        !           542:                *dp++ = *cp;
        !           543:        for (; *cp && *cp != '#'; cp++)
        !           544:                ;
        !           545:        for (; *cp && *cp != ':' && dp < ep; cp++)
        !           546:                *dp++ = *cp;
        !           547:        *dp = '\0';
        !           548:
        !           549:        strlcpy(sut->machine, machine, sizeof(sut->machine));
        !           550:
        !           551:        error = copyout(sut, SCARG(uap, name), sizeof(struct svr4_utsname));
        !           552:        free(sut, M_TEMP);
        !           553:        return (error);
        !           554: }
        !           555:
        !           556: int
        !           557: svr4_sys_systeminfo(p, v, retval)
        !           558:        register struct proc *p;
        !           559:        void *v;
        !           560:        register_t *retval;
        !           561: {
        !           562:        struct svr4_sys_systeminfo_args *uap = v;
        !           563:        const char *str;
        !           564:        int name;
        !           565:        int error;
        !           566:        long len;
        !           567:        extern char hostname[], machine[], domainname[];
        !           568: #ifdef __sparc__
        !           569:        extern char *cpu_class;
        !           570: #endif
        !           571:
        !           572:        u_int rlen = SCARG(uap, len);
        !           573:
        !           574:        switch (SCARG(uap, what)) {
        !           575:        case SVR4_SI_SYSNAME:
        !           576:                str = ostype;
        !           577:                break;
        !           578:
        !           579:        case SVR4_SI_HOSTNAME:
        !           580:                str = hostname;
        !           581:                break;
        !           582:
        !           583:        case SVR4_SI_RELEASE:
        !           584:                str = osrelease;
        !           585:                break;
        !           586:
        !           587:        case SVR4_SI_VERSION:
        !           588:                str = version;
        !           589:                break;
        !           590:
        !           591:        case SVR4_SI_MACHINE:
        !           592:                str = machine;
        !           593:                break;
        !           594:
        !           595:        case SVR4_SI_ARCHITECTURE:
        !           596:                str = machine;
        !           597:                break;
        !           598:
        !           599:        case SVR4_SI_HW_SERIAL:
        !           600:                str = "0";
        !           601:                break;
        !           602:
        !           603:        case SVR4_SI_HW_PROVIDER:
        !           604:                str = ostype;
        !           605:                break;
        !           606:
        !           607:        case SVR4_SI_SRPC_DOMAIN:
        !           608:                str = domainname;
        !           609:                break;
        !           610:
        !           611:        case SVR4_SI_PLATFORM:
        !           612: #ifdef __sparc__
        !           613:                str = cpu_class;
        !           614: #else
        !           615:                str = machine;
        !           616: #endif
        !           617:                break;
        !           618:
        !           619:        case SVR4_SI_KERB_REALM:
        !           620:                str = "unsupported";
        !           621:                break;
        !           622:
        !           623:        case SVR4_SI_SET_HOSTNAME:
        !           624:                if ((error = suser(p, 0)) != 0)
        !           625:                        return error;
        !           626:                name = KERN_HOSTNAME;
        !           627:                return kern_sysctl(&name, 1, 0, 0, SCARG(uap, buf), rlen, p);
        !           628:
        !           629:        case SVR4_SI_SET_SRPC_DOMAIN:
        !           630:                if ((error = suser(p, 0)) != 0)
        !           631:                        return error;
        !           632:                name = KERN_DOMAINNAME;
        !           633:                return kern_sysctl(&name, 1, 0, 0, SCARG(uap, buf), rlen, p);
        !           634:
        !           635:        case SVR4_SI_SET_KERB_REALM:
        !           636:                return 0;
        !           637:
        !           638:        default:
        !           639:                DPRINTF(("Bad systeminfo command %d\n", SCARG(uap, what)));
        !           640:                return ENOSYS;
        !           641:        }
        !           642:
        !           643:        /* on success, sysinfo() returns byte count including \0 */
        !           644:        /* result is not diminished if user buffer was too small */
        !           645:        len = strlen(str) + 1;
        !           646:        *retval = len;
        !           647:
        !           648:        /* nothing to copy if user buffer is empty */
        !           649:        if (rlen == 0)
        !           650:                return 0;
        !           651:
        !           652:        if (len > rlen) {
        !           653:                char nul = 0;
        !           654:
        !           655:                /* if str overruns buffer, put NUL in last place */
        !           656:                len = rlen - 1;
        !           657:                if (copyout(&nul, SCARG(uap, buf), sizeof(char)) != 0)
        !           658:                        return EFAULT;
        !           659:        }
        !           660:
        !           661:        return copyout(str, SCARG(uap, buf), len);
        !           662: }
        !           663:
        !           664:
        !           665: int
        !           666: svr4_sys_utssys(p, v, retval)
        !           667:        register struct proc *p;
        !           668:        void *v;
        !           669:        register_t *retval;
        !           670: {
        !           671:        struct svr4_sys_utssys_args *uap = v;
        !           672:
        !           673:        switch (SCARG(uap, sel)) {
        !           674:        case 0:         /* uname(2)  */
        !           675:                {
        !           676:                        struct svr4_sys_uname_args ua;
        !           677:                        SCARG(&ua, name) = SCARG(uap, a1);
        !           678:                        return svr4_sys_uname(p, &ua, retval);
        !           679:                }
        !           680:
        !           681:        case 2:         /* ustat(2)  */
        !           682:                {
        !           683:                        struct svr4_ustat_args ua;
        !           684:                        SCARG(&ua, dev) = (svr4_dev_t) SCARG(uap, a2);
        !           685:                        SCARG(&ua, name) = SCARG(uap, a1);
        !           686:                        return svr4_ustat(p, &ua, retval);
        !           687:                }
        !           688:
        !           689:        case 3:         /* fusers(2) */
        !           690:                return ENOSYS;
        !           691:
        !           692:        default:
        !           693:                return ENOSYS;
        !           694:        }
        !           695:        return ENOSYS;
        !           696: }
        !           697:
        !           698:
        !           699: int
        !           700: svr4_sys_utime(p, v, retval)
        !           701:        register struct proc *p;
        !           702:        void *v;
        !           703:        register_t *retval;
        !           704: {
        !           705:        struct svr4_sys_utime_args *uap = v;
        !           706:        struct svr4_utimbuf ub;
        !           707:        struct timeval tbuf[2];
        !           708:        struct sys_utimes_args ap;
        !           709:        int error;
        !           710:        caddr_t sg = stackgap_init(p->p_emul);
        !           711:
        !           712:        SCARG(&ap, tptr) = stackgap_alloc(&sg, sizeof(tbuf));
        !           713:        SVR4_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           714:        SCARG(&ap, path) = SCARG(uap, path);
        !           715:        if (SCARG(uap, ubuf) != NULL) {
        !           716:                if ((error = copyin(SCARG(uap, ubuf), &ub, sizeof(ub))) != 0)
        !           717:                        return error;
        !           718:                tbuf[0].tv_sec = ub.actime;
        !           719:                tbuf[0].tv_usec = 0;
        !           720:                tbuf[1].tv_sec = ub.modtime;
        !           721:                tbuf[1].tv_usec = 0;
        !           722:                error = copyout(tbuf, (struct timeval *)SCARG(&ap, tptr), sizeof(tbuf));
        !           723:                if (error)
        !           724:                        return error;
        !           725:        }
        !           726:        else
        !           727:                SCARG(&ap, tptr) = NULL;
        !           728:        return sys_utimes(p, &ap, retval);
        !           729: }
        !           730:
        !           731:
        !           732: int
        !           733: svr4_sys_utimes(p, v, retval)
        !           734:        register struct proc *p;
        !           735:        void *v;
        !           736:        register_t *retval;
        !           737: {
        !           738:        struct svr4_sys_utimes_args *uap = v;
        !           739:        caddr_t sg = stackgap_init(p->p_emul);
        !           740:        SVR4_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           741:        return sys_utimes(p, uap, retval);
        !           742: }
        !           743:
        !           744:
        !           745: static int
        !           746: svr4_to_bsd_pathconf(name)
        !           747:        int name;
        !           748: {
        !           749:        switch (name) {
        !           750:        case SVR4_PC_LINK_MAX:
        !           751:                return _PC_LINK_MAX;
        !           752:
        !           753:        case SVR4_PC_MAX_CANON:
        !           754:                return _PC_MAX_CANON;
        !           755:
        !           756:        case SVR4_PC_MAX_INPUT:
        !           757:                return _PC_MAX_INPUT;
        !           758:
        !           759:        case SVR4_PC_NAME_MAX:
        !           760:                return _PC_NAME_MAX;
        !           761:
        !           762:        case SVR4_PC_PATH_MAX:
        !           763:                return _PC_PATH_MAX;
        !           764:
        !           765:        case SVR4_PC_PIPE_BUF:
        !           766:                return _PC_PIPE_BUF;
        !           767:
        !           768:        case SVR4_PC_NO_TRUNC:
        !           769:                return _PC_NO_TRUNC;
        !           770:
        !           771:        case SVR4_PC_VDISABLE:
        !           772:                return _PC_VDISABLE;
        !           773:
        !           774:        case SVR4_PC_CHOWN_RESTRICTED:
        !           775:                return _PC_CHOWN_RESTRICTED;
        !           776:
        !           777:        case SVR4_PC_ASYNC_IO:
        !           778:        case SVR4_PC_PRIO_IO:
        !           779:        case SVR4_PC_SYNC_IO:
        !           780:                /* Not supported */
        !           781:                return 0;
        !           782:
        !           783:        default:
        !           784:                /* Invalid */
        !           785:                return -1;
        !           786:        }
        !           787: }
        !           788:
        !           789:
        !           790: int
        !           791: svr4_sys_pathconf(p, v, retval)
        !           792:        register struct proc *p;
        !           793:        void *v;
        !           794:        register_t *retval;
        !           795: {
        !           796:        struct svr4_sys_pathconf_args *uap = v;
        !           797:        caddr_t sg = stackgap_init(p->p_emul);
        !           798:
        !           799:        SVR4_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           800:
        !           801:        SCARG(uap, name) = svr4_to_bsd_pathconf(SCARG(uap, name));
        !           802:
        !           803:        switch (SCARG(uap, name)) {
        !           804:        case -1:
        !           805:                *retval = -1;
        !           806:                return EINVAL;
        !           807:        case 0:
        !           808:                *retval = 0;
        !           809:                return 0;
        !           810:        default:
        !           811:                return sys_pathconf(p, uap, retval);
        !           812:        }
        !           813: }
        !           814:
        !           815: int
        !           816: svr4_sys_fpathconf(p, v, retval)
        !           817:        register struct proc *p;
        !           818:        void *v;
        !           819:        register_t *retval;
        !           820: {
        !           821:        struct svr4_sys_fpathconf_args *uap = v;
        !           822:
        !           823:        SCARG(uap, name) = svr4_to_bsd_pathconf(SCARG(uap, name));
        !           824:
        !           825:        switch (SCARG(uap, name)) {
        !           826:        case -1:
        !           827:                *retval = -1;
        !           828:                return EINVAL;
        !           829:        case 0:
        !           830:                *retval = 0;
        !           831:                return 0;
        !           832:        default:
        !           833:                return sys_fpathconf(p, uap, retval);
        !           834:        }
        !           835: }

CVSweb