=================================================================== RCS file: /cvs/prex-old/dev/gen/tty.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.2.1 diff -u -r1.1.1.1 -r1.1.1.1.2.1 --- prex-old/dev/gen/tty.c 2008/06/03 10:38:41 1.1.1.1 +++ prex-old/dev/gen/tty.c 2008/08/13 17:12:23 1.1.1.1.2.1 @@ -41,7 +41,6 @@ #include #include #include -#include #include #define FREAD 0x0001 @@ -74,8 +73,8 @@ */ #define ttyq_next(i) (((i) + 1) & (TTYQ_SIZE - 1)) #define ttyq_prev(i) (((i) - 1) & (TTYQ_SIZE - 1)) -#define ttyq_full(q) ((q)->count >= TTYQ_SIZE) -#define ttyq_empty(q) ((q)->count == 0) +#define ttyq_full(q) ((q)->tq_count >= TTYQ_SIZE) +#define ttyq_empty(q) ((q)->tq_count == 0) /* * Get a character from a queue. @@ -88,9 +87,9 @@ if (ttyq_empty(tq)) return -1; irq_lock(); - c = tq->buf[tq->head]; - tq->head = ttyq_next(tq->head); - tq->count--; + c = tq->tq_buf[tq->tq_head]; + tq->tq_head = ttyq_next(tq->tq_head); + tq->tq_count--; irq_unlock(); return c; } @@ -105,9 +104,9 @@ if (ttyq_full(tq)) return; irq_lock(); - tq->buf[tq->tail] = c; - tq->tail = ttyq_next(tq->tail); - tq->count++; + tq->tq_buf[tq->tq_tail] = c; + tq->tq_tail = ttyq_next(tq->tq_tail); + tq->tq_count++; irq_unlock(); } @@ -122,9 +121,9 @@ if (ttyq_empty(tq)) return -1; irq_lock(); - tq->tail = ttyq_prev(tq->tail); - c = tq->buf[tq->tail]; - tq->count--; + tq->tq_tail = ttyq_prev(tq->tq_tail); + c = tq->tq_buf[tq->tq_tail]; + tq->tq_count--; irq_unlock(); return c; } @@ -180,7 +179,7 @@ /* * Start output. */ -void +static void tty_start(struct tty *tp) { @@ -193,7 +192,7 @@ /* * Flush tty read and/or write queues, notifying anyone waiting. */ -void +static void tty_flush(struct tty *tp, int rw) { @@ -372,10 +371,10 @@ } /* - * Read + * Process a read call on a tty device. */ int -tty_read(struct tty *tp, char *buf, size_t *nbytes) +tty_read(struct tty *tp, char *buf, size_t *nbyte) { unsigned char *cc; struct tty_queue *qp; @@ -393,36 +392,40 @@ if (rc == SLP_INTR) return EINTR; } - while (count < *nbytes) { + while (count < *nbyte) { if ((c = ttyq_getc(qp)) == -1) break; - count++; if (c == cc[VEOF] && (lflag & ICANON)) break; - *buf = c; + count++; + if (umem_copyout(&c, buf, 1)) + return EFAULT; if ((lflag & ICANON) && (c == '\n' || c == cc[VEOL])) break; buf++; } - *nbytes = count; + *nbyte = count; return 0; } /* - * Write + * Process a write call on a tty device. */ int tty_write(struct tty *tp, char *buf, size_t *nbyte) { size_t remain, count = 0; + int c; remain = *nbyte; while (remain > 0) { - if (tp->t_outq.count >= TTYQ_HIWAT) { + if (tp->t_outq.tq_count >= TTYQ_HIWAT) { tty_start(tp); continue; } - tty_output(*buf, tp); + if (umem_copyin(buf, &c, 1)) + return EFAULT; + tty_output(c, tp); buf++; remain--; count++; @@ -449,7 +452,7 @@ case TIOCSETAW: case TIOCSETAF: tty_flush(tp, flags); - /* fallthrouth */ + /* FALLTHROUGH */ case TIOCSETA: if (umem_copyin(data, &tp->t_termios, sizeof(struct termios))) @@ -510,12 +513,12 @@ { /* We support only one tty device */ - if (tty_dev != NULL_DEVICE) + if (tty_dev != DEVICE_NULL) return -1; /* Create TTY device as an alias of the registered device. */ tty_dev = device_create(io, "tty", DF_CHR); - if (tty_dev == NULL_DEVICE) + if (tty_dev == DEVICE_NULL) return -1; /* Initialize tty */