2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
14 #include "chan_user.h"
17 #include "kern_constants.h"
18 #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);
76 static int getmaster(char *line)
79 char *pty, *bank, *cp;
82 pty = &line[strlen("/dev/ptyp")];
83 for (bank = "pqrs"; *bank; bank++) {
84 line[strlen("/dev/pty")] = *bank;
86 /* Did we hit the end ? */
87 if ((stat(line, &buf) < 0) && (errno == ENOENT))
90 for (cp = "0123456789abcdef"; *cp; cp++) {
92 master = open(line, O_RDWR);
94 char *tp = &line[strlen("/dev/")];
96 /* verify slave side is usable */
98 err = access(line, R_OK | W_OK);
107 printk(UM_KERN_ERR "getmaster - no usable host pty devices\n");
111 static int pty_open(int input, int output, int primary, void *d,
114 struct pty_chan *data = d;
116 char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
129 (*data->announce)(dev, data->dev);
131 sprintf(data->dev_name, "%s", dev);
132 *dev_out = data->dev_name;
137 const struct chan_ops pty_ops = {
139 .init = pty_chan_init,
141 .close = generic_close,
142 .read = generic_read,
143 .write = generic_write,
144 .console_write = generic_console_write,
145 .window_size = generic_window_size,
146 .free = generic_free,
150 const struct chan_ops pts_ops = {
152 .init = pty_chan_init,
154 .close = generic_close,
155 .read = generic_read,
156 .write = generic_write,
157 .console_write = generic_console_write,
158 .window_size = generic_window_size,
159 .free = generic_free,