vserver 1.9.3
[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 <errno.h>
9 #include <unistd.h>
10 #include "chan_user.h"
11 #include "user_util.h"
12 #include "user.h"
13 #include "os.h"
14
15 struct tty_chan {
16         char *dev;
17         int raw;
18         struct termios tt;
19 };
20
21 void *tty_chan_init(char *str, int device, struct chan_opts *opts)
22 {
23         struct tty_chan *data;
24
25         if(*str != ':'){
26                 printk("tty_init : channel type 'tty' must specify "
27                        "a device\n");
28                 return(NULL);
29         }
30         str++;
31
32         data = um_kmalloc(sizeof(*data));
33         if(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, err;
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                 CATCH_EINTR(err = tcgetattr(fd, &data->tt));
50                 if(err)
51                         return(err);
52
53                 err = raw(fd);
54                 if(err)
55                         return(err);
56         }
57
58         *dev_out = data->dev;
59         return(fd);
60 }
61
62 int tty_console_write(int fd, const char *buf, int n, void *d)
63 {
64         struct tty_chan *data = d;
65
66         return(generic_console_write(fd, buf, n, &data->tt));
67 }
68
69 struct chan_ops tty_ops = {
70         .type           = "tty",
71         .init           = tty_chan_init,
72         .open           = tty_open,
73         .close          = generic_close,
74         .read           = generic_read,
75         .write          = generic_write,
76         .console_write  = tty_console_write,
77         .window_size    = generic_window_size,
78         .free           = generic_free,
79         .winch          = 0,
80 };
81
82 /*
83  * Overrides for Emacs so that we follow Linus's tabbing style.
84  * Emacs will notice this stuff at the end of the file and automatically
85  * adjust the settings for this buffer only.  This must remain at the end
86  * of the file.
87  * ---------------------------------------------------------------------------
88  * Local variables:
89  * c-file-style: "linux"
90  * End:
91  */