ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / um / drivers / tty.c
1 /* 
2  * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include <stdio.h>
7 #include <termios.h>
8 #include <fcntl.h>
9 #include <errno.h>
10 #include <unistd.h>
11 #include "chan_user.h"
12 #include "user_util.h"
13 #include "user.h"
14 #include "os.h"
15
16 struct tty_chan {
17         char *dev;
18         int raw;
19         struct termios tt;
20 };
21
22 void *tty_chan_init(char *str, int device, struct chan_opts *opts)
23 {
24         struct tty_chan *data;
25
26         if(*str != ':'){
27                 printk("tty_init : channel type 'tty' must specify "
28                        "a device\n");
29                 return(NULL);
30         }
31         str++;
32
33         if((data = um_kmalloc(sizeof(*data))) == NULL) 
34                 return(NULL);
35         *data = ((struct tty_chan) { .dev       = str,
36                                      .raw       = opts->raw });
37                                      
38         return(data);
39 }
40
41 int tty_open(int input, int output, int primary, void *d, char **dev_out)
42 {
43         struct tty_chan *data = d;
44         int fd;
45
46         fd = os_open_file(data->dev, of_set_rw(OPENFLAGS(), input, output), 0);
47         if(fd < 0) return(fd);
48         if(data->raw){
49                 tcgetattr(fd, &data->tt);
50                 raw(fd, 0);
51         }
52
53         *dev_out = data->dev;
54         return(fd);
55 }
56
57 int tty_console_write(int fd, const char *buf, int n, void *d)
58 {
59         struct tty_chan *data = d;
60
61         return(generic_console_write(fd, buf, n, &data->tt));
62 }
63
64 struct chan_ops tty_ops = {
65         .type           = "tty",
66         .init           = tty_chan_init,
67         .open           = tty_open,
68         .close          = generic_close,
69         .read           = generic_read,
70         .write          = generic_write,
71         .console_write  = tty_console_write,
72         .window_size    = generic_window_size,
73         .free           = generic_free,
74         .winch          = 0,
75 };
76
77 /*
78  * Overrides for Emacs so that we follow Linus's tabbing style.
79  * Emacs will notice this stuff at the end of the file and automatically
80  * adjust the settings for this buffer only.  This must remain at the end
81  * of the file.
82  * ---------------------------------------------------------------------------
83  * Local variables:
84  * c-file-style: "linux"
85  * End:
86  */