This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / arch / um / drivers / fd.c
1 /* 
2  * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <termios.h>
10 #include "user.h"
11 #include "user_util.h"
12 #include "chan_user.h"
13
14 struct fd_chan {
15         int fd;
16         int raw;
17         struct termios tt;
18         char str[sizeof("1234567890\0")];
19 };
20
21 void *fd_init(char *str, int device, struct chan_opts *opts)
22 {
23         struct fd_chan *data;
24         char *end;
25         int n;
26
27         if(*str != ':'){
28                 printk("fd_init : channel type 'fd' must specify a file "
29                        "descriptor\n");
30                 return(NULL);
31         }
32         str++;
33         n = strtoul(str, &end, 0);
34         if((*end != '\0') || (end == str)){
35                 printk("fd_init : couldn't parse file descriptor '%s'\n", str);
36                 return(NULL);
37         }
38         data = um_kmalloc(sizeof(*data));
39         if(data == NULL) return(NULL);
40         *data = ((struct fd_chan) { .fd         = n,
41                                     .raw        = opts->raw });
42         return(data);
43 }
44
45 int fd_open(int input, int output, int primary, void *d, char **dev_out)
46 {
47         struct fd_chan *data = d;
48
49         if(data->raw && isatty(data->fd)){
50                 tcgetattr(data->fd, &data->tt);
51                 raw(data->fd, 0);
52         }
53         sprintf(data->str, "%d", data->fd);
54         *dev_out = data->str;
55         return(data->fd);
56 }
57
58 void fd_close(int fd, void *d)
59 {
60         struct fd_chan *data = d;
61
62         if(data->raw && isatty(fd)){
63                 tcsetattr(fd, TCSAFLUSH, &data->tt);
64                 data->raw = 0;
65         }
66 }
67
68 int fd_console_write(int fd, const char *buf, int n, void *d)
69 {
70         struct fd_chan *data = d;
71
72         return(generic_console_write(fd, buf, n, &data->tt));
73 }
74
75 struct chan_ops fd_ops = {
76         .type           = "fd",
77         .init           = fd_init,
78         .open           = fd_open,
79         .close          = fd_close,
80         .read           = generic_read,
81         .write          = generic_write,
82         .console_write  = fd_console_write,
83         .window_size    = generic_window_size,
84         .free           = generic_free,
85         .winch          = 1,
86 };
87
88 /*
89  * Overrides for Emacs so that we follow Linus's tabbing style.
90  * Emacs will notice this stuff at the end of the file and automatically
91  * adjust the settings for this buffer only.  This must remain at the end
92  * of the file.
93  * ---------------------------------------------------------------------------
94  * Local variables:
95  * c-file-style: "linux"
96  * End:
97  */