2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
14 #include "chan_user.h"
16 #include <um_malloc.h>
19 void (*announce
)(char *dev_name
, int dev
);
23 char dev_name
[sizeof("/dev/pts/0123456\0")];
26 static void *pty_chan_init(char *str
, int device
, const struct chan_opts
*opts
)
28 struct pty_chan
*data
;
30 data
= uml_kmalloc(sizeof(*data
), UM_GFP_KERNEL
);
34 *data
= ((struct pty_chan
) { .announce
= opts
->announce
,
40 static int pts_open(int input
, int output
, int primary
, void *d
,
43 struct pty_chan
*data
= d
;
50 printk(UM_KERN_ERR
"open_pts : Failed to open pts\n");
55 CATCH_EINTR(err
= tcgetattr(fd
, &data
->tt
));
65 sprintf(data
->dev_name
, "%s", dev
);
66 *dev_out
= data
->dev_name
;
69 (*data
->announce
)(dev
, data
->dev
);
78 static int getmaster(char *line
)
81 char *pty
, *bank
, *cp
;
84 pty
= &line
[strlen("/dev/ptyp")];
85 for (bank
= "pqrs"; *bank
; bank
++) {
86 line
[strlen("/dev/pty")] = *bank
;
88 /* Did we hit the end ? */
89 if ((stat(line
, &buf
) < 0) && (errno
== ENOENT
))
92 for (cp
= "0123456789abcdef"; *cp
; cp
++) {
94 master
= open(line
, O_RDWR
);
96 char *tp
= &line
[strlen("/dev/")];
98 /* verify slave side is usable */
100 err
= access(line
, R_OK
| W_OK
);
109 printk(UM_KERN_ERR
"getmaster - no usable host pty devices\n");
113 static int pty_open(int input
, int output
, int primary
, void *d
,
116 struct pty_chan
*data
= d
;
118 char dev
[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
133 (*data
->announce
)(dev
, data
->dev
);
135 sprintf(data
->dev_name
, "%s", dev
);
136 *dev_out
= data
->dev_name
;
141 const struct chan_ops pty_ops
= {
143 .init
= pty_chan_init
,
145 .close
= generic_close
,
146 .read
= generic_read
,
147 .write
= generic_write
,
148 .console_write
= generic_console_write
,
149 .window_size
= generic_window_size
,
150 .free
= generic_free
,
154 const struct chan_ops pts_ops
= {
156 .init
= pty_chan_init
,
158 .close
= generic_close
,
159 .read
= generic_read
,
160 .write
= generic_write
,
161 .console_write
= generic_console_write
,
162 .window_size
= generic_window_size
,
163 .free
= generic_free
,