[BACK]Return to unixdev.c CVS log [TXT][DIR] Up to [local] / sys / lib / libsa

Annotation of sys/lib/libsa/unixdev.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: unixdev.c,v 1.7 2003/08/11 06:23:09 deraadt Exp $     */
                      2:
                      3: /*
                      4:  * Copyright (c) 1996-1998 Michael Shalayeff
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     17:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     18:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     19:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     20:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     21:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     22:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     23:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     24:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     25:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     26:  * SUCH DAMAGE.
                     27:  *
                     28:  */
                     29:
                     30: #include <sys/param.h>
                     31: #include <sys/types.h>
                     32: #include <sys/time.h>
                     33: #include <sys/syscall.h>
                     34: #define open uopen
                     35: #include <sys/fcntl.h>
                     36: #include <dev/cons.h>
                     37: #undef open
                     38: #include "libsa.h"
                     39: #include <lib/libsa/unixdev.h>
                     40:
                     41: int
                     42: unixstrategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
                     43:     size_t *rsize)
                     44: {
                     45:        int     rc = 0;
                     46:
                     47: #ifdef UNIX_DEBUG
                     48:        printf("unixstrategy: %s %d bytes @ %d\n",
                     49:            (rw==F_READ?"reading":"writing"), size, blk);
                     50: #endif
                     51:        if ((rc = ulseek((int)devdata, blk * DEV_BSIZE, 0)) >= 0)
                     52:                rc = (rw==F_READ) ? uread((int)devdata, buf, size) :
                     53:                    uwrite((int)devdata, buf, size);
                     54:
                     55:        if (rc >= 0) {
                     56:                *rsize = (size_t)rc;
                     57:                rc = 0;
                     58:        } else
                     59:                rc = errno;
                     60:
                     61:        return rc;
                     62: }
                     63:
                     64: int
                     65: unixopen(struct open_file *f, ...)
                     66: {
                     67:        char **file, *p = NULL;
                     68:        va_list ap;
                     69:        int fd;
                     70:
                     71:        va_start(ap, f);
                     72:        file = va_arg(ap, char **);
                     73:        va_end(ap);
                     74:
                     75: #ifdef UNIX_DEBUG
                     76:        printf("unixopen: %s\n", *file);
                     77: #endif
                     78:
                     79:        if (strncmp("/dev/", *file, 5) == 0) {
                     80:                /* p = strchr(p + 5, '/') */
                     81:                for (p = *file + 5; *p != '\0' && *p != '/'; p++)
                     82:                        ;
                     83:                if (*p == '/')
                     84:                        *p = '\0';
                     85:        }
                     86:
                     87:        f->f_devdata = (void *)(fd = uopen(*file, O_RDWR, 0));
                     88:
                     89:        *file = p;
                     90:        if (p != NULL)
                     91:                *p = '/';
                     92:
                     93:        return fd < 0 ? -1 : 0;
                     94: }
                     95:
                     96: int
                     97: unixclose(struct open_file *f)
                     98: {
                     99:        return uclose((int)f->f_devdata);
                    100: }
                    101:
                    102: int
                    103: unixioctl(struct open_file *f, u_long cmd, void *data)
                    104: {
                    105:        return uioctl((int)f->f_devdata, cmd, data);
                    106: }
                    107:
                    108: off_t
                    109: ulseek(int fd, off_t off, int wh)
                    110: {
                    111:        return __syscall((quad_t)SYS_lseek, fd, 0, off, wh);
                    112: }
                    113:
                    114:
                    115: void
                    116: unix_probe(struct consdev *cn)
                    117: {
                    118:        cn->cn_pri = CN_INTERNAL;
                    119:        cn->cn_dev = makedev(0,0);
                    120:        printf("ux%d ", minor(cn->cn_dev));
                    121: }
                    122:
                    123: void
                    124: unix_init(struct consdev *cn)
                    125: {
                    126: }
                    127:
                    128: void
                    129: unix_putc(dev_t dev, int c)
                    130: {
                    131:        uwrite(1, &c, 1);
                    132: }
                    133:
                    134: int
                    135: unix_getc(dev_t dev)
                    136: {
                    137:        if (dev & 0x80) {
                    138:                struct timeval tv;
                    139:                fd_set fdset;
                    140:                int rc;
                    141:
                    142:                tv.tv_sec = 0;
                    143:                tv.tv_usec = 100000;
                    144:                FD_ZERO(&fdset);
                    145:                FD_SET(0, &fdset);
                    146:
                    147:                if ((rc = syscall(SYS_select, 1, &fdset, NULL, NULL, &tv)) <= 0)
                    148:                        return 0;
                    149:                else
                    150:                        return 1;
                    151:        } else {
                    152:                char c;
                    153:
                    154:                return uread(0, &c, 1)<1? -1: c;
                    155:        }
                    156: }
                    157:
                    158: time_t
                    159: getsecs(void)
                    160: {
                    161:        return 1;
                    162: }
                    163:
                    164: void
                    165: time_print(void)
                    166: {
                    167: }
                    168:
                    169: void
                    170: atexit(void)
                    171: {
                    172: }
                    173:
                    174: int
                    175: cnspeed(dev_t dev, int sp)
                    176: {
                    177:        return 9600;
                    178: }
                    179:
                    180: void
                    181: __main(void)
                    182: {
                    183: }

CVSweb