2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
3 * Licensed under the GPL
12 #include "chan_user.h"
13 #include "um_malloc.h"
16 #include "kern_constants.h"
22 char str[sizeof("1234567890\0")];
25 static void *fd_init(char *str, int device, const struct chan_opts *opts)
32 printk(UM_KERN_ERR "fd_init : channel type 'fd' must specify a "
37 n = strtoul(str, &end, 0);
38 if ((*end != '\0') || (end == str)) {
39 printk(UM_KERN_ERR "fd_init : couldn't parse file descriptor "
44 data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
48 *data = ((struct fd_chan) { .fd = n,
53 static int fd_open(int input, int output, int primary, void *d, char **dev_out)
55 struct fd_chan *data = d;
58 if (data->raw && isatty(data->fd)) {
59 CATCH_EINTR(err = tcgetattr(data->fd, &data->tt));
67 sprintf(data->str, "%d", data->fd);
72 static void fd_close(int fd, void *d)
74 struct fd_chan *data = d;
77 if (!data->raw || !isatty(fd))
80 CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
82 printk(UM_KERN_ERR "Failed to restore terminal state - "
83 "errno = %d\n", -err);
87 const struct chan_ops fd_ops = {
93 .write = generic_write,
94 .console_write = generic_console_write,
95 .window_size = generic_window_size,