1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
11 #include "chan_user.h"
13 #include <um_malloc.h>
19 char str
[sizeof("1234567890\0")];
22 static void *fd_init(char *str
, int device
, const struct chan_opts
*opts
)
29 printk(UM_KERN_ERR
"fd_init : channel type 'fd' must specify a "
34 n
= strtoul(str
, &end
, 0);
35 if ((*end
!= '\0') || (end
== str
)) {
36 printk(UM_KERN_ERR
"fd_init : couldn't parse file descriptor "
41 data
= uml_kmalloc(sizeof(*data
), UM_GFP_KERNEL
);
45 *data
= ((struct fd_chan
) { .fd
= n
,
50 static int fd_open(int input
, int output
, int primary
, void *d
, char **dev_out
)
52 struct fd_chan
*data
= d
;
55 if (data
->raw
&& isatty(data
->fd
)) {
56 CATCH_EINTR(err
= tcgetattr(data
->fd
, &data
->tt
));
64 sprintf(data
->str
, "%d", data
->fd
);
69 static void fd_close(int fd
, void *d
)
71 struct fd_chan
*data
= d
;
74 if (!data
->raw
|| !isatty(fd
))
77 CATCH_EINTR(err
= tcsetattr(fd
, TCSAFLUSH
, &data
->tt
));
79 printk(UM_KERN_ERR
"Failed to restore terminal state - "
80 "errno = %d\n", -err
);
84 const struct chan_ops fd_ops
= {
90 .write
= generic_write
,
91 .console_write
= generic_console_write
,
92 .window_size
= generic_window_size
,