]>
Commit | Line | Data |
---|---|---|
108ffa8c | 1 | /* |
1da177e4 LT |
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 | ||
5e7672ec | 21 | static void *tty_chan_init(char *str, int device, const struct chan_opts *opts) |
1da177e4 LT |
22 | { |
23 | struct tty_chan *data; | |
24 | ||
25 | if(*str != ':'){ | |
26 | printk("tty_init : channel type 'tty' must specify " | |
27 | "a device\n"); | |
108ffa8c | 28 | return NULL; |
1da177e4 LT |
29 | } |
30 | str++; | |
31 | ||
32 | data = um_kmalloc(sizeof(*data)); | |
33 | if(data == NULL) | |
108ffa8c | 34 | return NULL; |
1da177e4 LT |
35 | *data = ((struct tty_chan) { .dev = str, |
36 | .raw = opts->raw }); | |
108ffa8c JD |
37 | |
38 | return data; | |
1da177e4 LT |
39 | } |
40 | ||
41 | static int tty_open(int input, int output, int primary, void *d, | |
42 | char **dev_out) | |
43 | { | |
44 | struct tty_chan *data = d; | |
45 | int fd, err; | |
46 | ||
47 | fd = os_open_file(data->dev, of_set_rw(OPENFLAGS(), input, output), 0); | |
108ffa8c JD |
48 | if(fd < 0) |
49 | return fd; | |
50 | ||
1da177e4 LT |
51 | if(data->raw){ |
52 | CATCH_EINTR(err = tcgetattr(fd, &data->tt)); | |
53 | if(err) | |
108ffa8c | 54 | return err; |
1da177e4 LT |
55 | |
56 | err = raw(fd); | |
57 | if(err) | |
108ffa8c | 58 | return err; |
1da177e4 LT |
59 | } |
60 | ||
61 | *dev_out = data->dev; | |
108ffa8c | 62 | return fd; |
1da177e4 LT |
63 | } |
64 | ||
5e7672ec | 65 | const struct chan_ops tty_ops = { |
1da177e4 LT |
66 | .type = "tty", |
67 | .init = tty_chan_init, | |
68 | .open = tty_open, | |
69 | .close = generic_close, | |
70 | .read = generic_read, | |
71 | .write = generic_write, | |
fd9bc53b | 72 | .console_write = generic_console_write, |
1da177e4 LT |
73 | .window_size = generic_window_size, |
74 | .free = generic_free, | |
75 | .winch = 0, | |
76 | }; |