2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
14 #include "chan_user.h"
15 #include "kern_constants.h"
17 #include "um_malloc.h"
21 void (*announce)(char *dev_name, int dev);
25 char dev_name[sizeof("/dev/pts/0123456\0")];
28 static void *pty_chan_init(char *str, int device, const struct chan_opts *opts)
30 struct pty_chan *data;
32 data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
36 *data = ((struct pty_chan) { .announce = opts->announce,
42 static int pts_open(int input, int output, int primary, void *d,
45 struct pty_chan *data = d;
52 printk(UM_KERN_ERR "open_pts : Failed to open pts\n");
57 CATCH_EINTR(err = tcgetattr(fd, &data->tt));
67 sprintf(data->dev_name, "%s", dev);
68 *dev_out = data->dev_name;
71 (*data->announce)(dev, data->dev);
80 static int getmaster(char *line)
83 char *pty, *bank, *cp;
86 pty = &line[strlen("/dev/ptyp")];
87 for (bank = "pqrs"; *bank; bank++) {
88 line[strlen("/dev/pty")] = *bank;
90 /* Did we hit the end ? */
91 if ((stat(line, &buf) < 0) && (errno == ENOENT))
94 for (cp = "0123456789abcdef"; *cp; cp++) {
96 master = open(line, O_RDWR);
98 char *tp = &line[strlen("/dev/")];
100 /* verify slave side is usable */
102 err = access(line, R_OK | W_OK);
111 printk(UM_KERN_ERR "getmaster - no usable host pty devices\n");
115 static int pty_open(int input, int output, int primary, void *d,
118 struct pty_chan *data = d;
120 char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
135 (*data->announce)(dev, data->dev);
137 sprintf(data->dev_name, "%s", dev);
138 *dev_out = data->dev_name;
143 const struct chan_ops pty_ops = {
145 .init = pty_chan_init,
147 .close = generic_close,
148 .read = generic_read,
149 .write = generic_write,
150 .console_write = generic_console_write,
151 .window_size = generic_window_size,
152 .free = generic_free,
156 const struct chan_ops pts_ops = {
158 .init = pty_chan_init,
160 .close = generic_close,
161 .read = generic_read,
162 .write = generic_write,
163 .console_write = generic_console_write,
164 .window_size = generic_window_size,
165 .free = generic_free,