uml: network formatting
[deliverable/linux.git] / arch / um / drivers / tty.c
CommitLineData
108ffa8c 1/*
e99525f9 2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
1da177e4
LT
3 * Licensed under the GPL
4 */
5
1da177e4 6#include <errno.h>
e99525f9
JD
7#include <fcntl.h>
8#include <termios.h>
1da177e4 9#include "chan_user.h"
e99525f9 10#include "kern_constants.h"
1da177e4 11#include "os.h"
c13e5690 12#include "um_malloc.h"
e99525f9 13#include "user.h"
1da177e4
LT
14
15struct tty_chan {
16 char *dev;
17 int raw;
18 struct termios tt;
19};
20
5e7672ec 21static void *tty_chan_init(char *str, int device, const struct chan_opts *opts)
1da177e4
LT
22{
23 struct tty_chan *data;
24
e99525f9
JD
25 if (*str != ':') {
26 printk(UM_KERN_ERR "tty_init : channel type 'tty' must specify "
1da177e4 27 "a device\n");
108ffa8c 28 return NULL;
1da177e4
LT
29 }
30 str++;
31
e4c4bf99 32 data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
e99525f9 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
41static int tty_open(int input, int output, int primary, void *d,
42 char **dev_out)
43{
44 struct tty_chan *data = d;
e99525f9
JD
45 int fd, err, mode = 0;
46
47 if (input && output)
48 mode = O_RDWR;
49 else if (input)
50 mode = O_RDONLY;
51 else if (output)
52 mode = O_WRONLY;
1da177e4 53
e99525f9
JD
54 fd = open(data->dev, mode);
55 if (fd < 0)
56 return -errno;
108ffa8c 57
e99525f9 58 if (data->raw) {
1da177e4 59 CATCH_EINTR(err = tcgetattr(fd, &data->tt));
e99525f9 60 if (err)
108ffa8c 61 return err;
1da177e4
LT
62
63 err = raw(fd);
e99525f9 64 if (err)
108ffa8c 65 return err;
1da177e4
LT
66 }
67
68 *dev_out = data->dev;
108ffa8c 69 return fd;
1da177e4
LT
70}
71
5e7672ec 72const struct chan_ops tty_ops = {
1da177e4
LT
73 .type = "tty",
74 .init = tty_chan_init,
75 .open = tty_open,
76 .close = generic_close,
77 .read = generic_read,
78 .write = generic_write,
fd9bc53b 79 .console_write = generic_console_write,
1da177e4
LT
80 .window_size = generic_window_size,
81 .free = generic_free,
82 .winch = 0,
83};
This page took 0.25973 seconds and 5 git commands to generate.