2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
3 * Licensed under the GPL
11 #include "chan_user.h"
12 #include "kern_constants.h"
14 #include "um_malloc.h"
21 char str[sizeof("1234567890\0")];
24 static void *fd_init(char *str, int device, const struct chan_opts *opts)
31 printk(UM_KERN_ERR "fd_init : channel type 'fd' must specify a "
36 n = strtoul(str, &end, 0);
37 if ((*end != '\0') || (end == str)) {
38 printk(UM_KERN_ERR "fd_init : couldn't parse file descriptor "
43 data = uml_kmalloc(sizeof(*data), UM_GFP_KERNEL);
47 *data = ((struct fd_chan) { .fd = n,
52 static int fd_open(int input, int output, int primary, void *d, char **dev_out)
54 struct fd_chan *data = d;
57 if (data->raw && isatty(data->fd)) {
58 CATCH_EINTR(err = tcgetattr(data->fd, &data->tt));
66 sprintf(data->str, "%d", data->fd);
71 static void fd_close(int fd, void *d)
73 struct fd_chan *data = d;
76 if (!data->raw || !isatty(fd))
79 CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
81 printk(UM_KERN_ERR "Failed to restore terminal state - "
82 "errno = %d\n", -err);
86 const struct chan_ops fd_ops = {
92 .write = generic_write,
93 .console_write = generic_console_write,
94 .window_size = generic_window_size,