Annotation of Net2/kern/kern_subr.c, revision 1.1.1.2

1.1       root        1: /*
                      2:  * Copyright (c) 1982, 1986, 1991 Regents of the University of California.
                      3:  * All rights reserved. 
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. All advertising materials mentioning features or use of this software
                     14:  *    must display the following acknowledgement:
                     15:  *     This product includes software developed by the University of
                     16:  *     California, Berkeley and its contributors.
                     17:  * 4. Neither the name of the University nor the names of its contributors
                     18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     31:  * SUCH DAMAGE.
                     32:  *
                     33:  *     @(#)kern_subr.c 7.7 (Berkeley) 4/15/91
                     34:  */
1.1.1.2 ! root       35: static char rcsid[] = "$Header: /usr/bill/working/sys/kern/RCS/kern_subr.c,v 1.3 92/01/21 21:29:28 william Exp $";
1.1       root       36: 
                     37: #include "param.h"
                     38: #include "systm.h"
                     39: #include "proc.h"
                     40: 
                     41: uiomove(cp, n, uio)
                     42:        register caddr_t cp;
                     43:        register int n;
                     44:        register struct uio *uio;
                     45: {
                     46:        register struct iovec *iov;
                     47:        u_int cnt;
                     48:        int error = 0;
                     49: 
                     50: 
                     51: #ifdef DIAGNOSTIC
                     52:        if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
                     53:                panic("uiomove: mode");
                     54:        if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
                     55:                panic("uiomove proc");
                     56: #endif
                     57:        while (n > 0 && uio->uio_resid) {
                     58:                iov = uio->uio_iov;
                     59:                cnt = iov->iov_len;
                     60:                if (cnt == 0) {
                     61:                        uio->uio_iov++;
                     62:                        uio->uio_iovcnt--;
                     63:                        continue;
                     64:                }
                     65:                if (cnt > n)
                     66:                        cnt = n;
                     67:                switch (uio->uio_segflg) {
                     68: 
                     69:                case UIO_USERSPACE:
                     70:                case UIO_USERISPACE:
                     71:                        if (uio->uio_rw == UIO_READ)
                     72:                                error = copyout(cp, iov->iov_base, cnt);
                     73:                        else
                     74:                                error = copyin(iov->iov_base, cp, cnt);
                     75:                        if (error)
                     76:                                return (error);
                     77:                        break;
                     78: 
                     79:                case UIO_SYSSPACE:
                     80:                        if (uio->uio_rw == UIO_READ)
                     81:                                bcopy((caddr_t)cp, iov->iov_base, cnt);
                     82:                        else
                     83:                                bcopy(iov->iov_base, (caddr_t)cp, cnt);
                     84:                        break;
                     85:                }
                     86:                iov->iov_base += cnt;
                     87:                iov->iov_len -= cnt;
                     88:                uio->uio_resid -= cnt;
                     89:                uio->uio_offset += cnt;
                     90:                cp += cnt;
                     91:                n -= cnt;
                     92:        }
                     93:        return (error);
                     94: }
                     95: 
1.1.1.2 ! root       96: uioapply(func, arg1, arg2, uio)
        !            97:        int (*func)() ;
        !            98:        register struct uio *uio;
        !            99: {
        !           100:        register struct iovec *iov;
        !           101:        u_int cnt, cnt1;
        !           102:        int error = 0;
        !           103: 
        !           104: 
        !           105: /*#ifdef DIAGNOSTIC*/
        !           106:        if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
        !           107:                panic("uioapply: mode");
        !           108:        if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
        !           109:                panic("uioapply proc");
        !           110: /*#endif*/
        !           111:        while (uio->uio_resid) {
        !           112:                iov = uio->uio_iov;
        !           113:                cnt = iov->iov_len;
        !           114:                if (cnt == 0) {
        !           115:                        uio->uio_iov++;
        !           116:                        uio->uio_iovcnt--;
        !           117:                        continue;
        !           118:                }
        !           119:                cnt1 = cnt;
        !           120:                error = (*func)(arg1, arg2, uio->uio_offset, uio->uio_rw,
        !           121:                        iov->iov_base, &cnt1, uio->uio_procp);
        !           122:                cnt -= cnt1;
        !           123:                iov->iov_base += cnt;
        !           124:                iov->iov_len -= cnt;
        !           125:                uio->uio_resid -= cnt;
        !           126:                uio->uio_offset += cnt;
        !           127:                if (error || cnt1)
        !           128:                        return (error);
        !           129:        }
        !           130:        return (0);
        !           131: }
        !           132: 
1.1       root      133: /*
                    134:  * Give next character to user as result of read.
                    135:  */
                    136: ureadc(c, uio)
                    137:        register int c;
                    138:        register struct uio *uio;
                    139: {
                    140:        register struct iovec *iov;
                    141: 
                    142: again:
                    143:        if (uio->uio_iovcnt == 0)
                    144:                panic("ureadc");
                    145:        iov = uio->uio_iov;
                    146:        if (iov->iov_len <= 0 || uio->uio_resid <= 0) {
                    147:                uio->uio_iovcnt--;
                    148:                uio->uio_iov++;
                    149:                goto again;
                    150:        }
                    151:        switch (uio->uio_segflg) {
                    152: 
                    153:        case UIO_USERSPACE:
                    154:                if (subyte(iov->iov_base, c) < 0)
                    155:                        return (EFAULT);
                    156:                break;
                    157: 
                    158:        case UIO_SYSSPACE:
                    159:                *iov->iov_base = c;
                    160:                break;
                    161: 
                    162:        case UIO_USERISPACE:
                    163:                if (suibyte(iov->iov_base, c) < 0)
                    164:                        return (EFAULT);
                    165:                break;
                    166:        }
                    167:        iov->iov_base++;
                    168:        iov->iov_len--;
                    169:        uio->uio_resid--;
                    170:        uio->uio_offset++;
                    171:        return (0);
                    172: }
                    173: 
                    174: strcat(src, append)
                    175:        register char *src, *append;
                    176: {
                    177: 
                    178:        for (; *src; ++src)
                    179:                ;
                    180:        while (*src++ = *append++)
                    181:                ;
                    182: }
                    183: 
                    184: strcpy(to, from)
                    185:        register char *to, *from;
                    186: {
                    187: 
                    188:        for (; *from = *to; ++from, ++to)
                    189:                ;
                    190: }
                    191: 
                    192: strncpy(to, from, cnt)
                    193:        register char *to, *from;
                    194:        register int cnt;
                    195: {
                    196: 
                    197:        for (; cnt && (*to = *from); --cnt, ++from, ++to)
                    198:                ;
                    199:        *to = '\0';
                    200: }
                    201: 
                    202: #ifndef lint   /* unused except by ct.c, other oddities XXX */
                    203: /*
                    204:  * Get next character written in by user from uio.
                    205:  */
                    206: uwritec(uio)
                    207:        struct uio *uio;
                    208: {
                    209:        register struct iovec *iov;
                    210:        register int c;
                    211: 
                    212:        if (uio->uio_resid <= 0)
                    213:                return (-1);
                    214: again:
                    215:        if (uio->uio_iovcnt <= 0)
                    216:                panic("uwritec");
                    217:        iov = uio->uio_iov;
                    218:        if (iov->iov_len == 0) {
                    219:                uio->uio_iov++;
                    220:                if (--uio->uio_iovcnt == 0)
                    221:                        return (-1);
                    222:                goto again;
                    223:        }
                    224:        switch (uio->uio_segflg) {
                    225: 
                    226:        case UIO_USERSPACE:
                    227:                c = fubyte(iov->iov_base);
                    228:                break;
                    229: 
                    230:        case UIO_SYSSPACE:
                    231:                c = *(u_char *) iov->iov_base;
                    232:                break;
                    233: 
                    234:        case UIO_USERISPACE:
                    235:                c = fuibyte(iov->iov_base);
                    236:                break;
                    237:        }
                    238:        if (c < 0)
                    239:                return (-1);
                    240:        iov->iov_base++;
                    241:        iov->iov_len--;
                    242:        uio->uio_resid--;
                    243:        uio->uio_offset++;
                    244:        return (c);
                    245: }
                    246: #endif /* notdef */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.