2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
11 #include "chan_user.h"
13 #include "user_util.h"
14 #include "kern_util.h"
18 void (*announce
)(char *dev_name
, int dev
);
22 char dev_name
[sizeof("/dev/pts/0123456\0")];
25 static void *pty_chan_init(char *str
, int device
, struct chan_opts
*opts
)
27 struct pty_chan
*data
;
29 data
= um_kmalloc(sizeof(*data
));
30 if(data
== NULL
) return(NULL
);
31 *data
= ((struct pty_chan
) { .announce
= opts
->announce
,
37 static int pts_open(int input
, int output
, int primary
, void *d
,
40 struct pty_chan
*data
= d
;
46 printk("open_pts : Failed to open pts\n");
50 CATCH_EINTR(err
= tcgetattr(fd
, &data
->tt
));
60 sprintf(data
->dev_name
, "%s", dev
);
61 *dev_out
= data
->dev_name
;
63 (*data
->announce
)(dev
, data
->dev
);
67 static int getmaster(char *line
)
69 char *pty
, *bank
, *cp
;
72 pty
= &line
[strlen("/dev/ptyp")];
73 for (bank
= "pqrs"; *bank
; bank
++) {
74 line
[strlen("/dev/pty")] = *bank
;
76 if (os_stat_file(line
, NULL
) < 0)
78 for (cp
= "0123456789abcdef"; *cp
; cp
++) {
80 master
= os_open_file(line
, of_rdwr(OPENFLAGS()), 0);
82 char *tp
= &line
[strlen("/dev/")];
84 /* verify slave side is usable */
86 err
= os_access(line
, OS_ACC_RW_OK
);
88 if(err
== 0) return(master
);
89 (void) os_close_file(master
);
96 static int pty_open(int input
, int output
, int primary
, void *d
,
99 struct pty_chan
*data
= d
;
101 char dev
[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
113 if(data
->announce
) (*data
->announce
)(dev
, data
->dev
);
115 sprintf(data
->dev_name
, "%s", dev
);
116 *dev_out
= data
->dev_name
;
120 static int pty_console_write(int fd
, const char *buf
, int n
, void *d
)
122 struct pty_chan
*data
= d
;
124 return(generic_console_write(fd
, buf
, n
, &data
->tt
));
127 struct chan_ops pty_ops
= {
129 .init
= pty_chan_init
,
131 .close
= generic_close
,
132 .read
= generic_read
,
133 .write
= generic_write
,
134 .console_write
= pty_console_write
,
135 .window_size
= generic_window_size
,
136 .free
= generic_free
,
140 struct chan_ops pts_ops
= {
142 .init
= pty_chan_init
,
144 .close
= generic_close
,
145 .read
= generic_read
,
146 .write
= generic_write
,
147 .console_write
= pty_console_write
,
148 .window_size
= generic_window_size
,
149 .free
= generic_free
,
154 * Overrides for Emacs so that we follow Linus's tabbing style.
155 * Emacs will notice this stuff at the end of the file and automatically
156 * adjust the settings for this buffer only. This must remain at the end
158 * ---------------------------------------------------------------------------
160 * c-file-style: "linux"