Deleted Added
full compact
tty.c (72200) tty.c (72521)
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)tty.c 8.8 (Berkeley) 1/21/94
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)tty.c 8.8 (Berkeley) 1/21/94
39 * $FreeBSD: head/sys/kern/tty.c 72200 2001-02-09 06:11:45Z bmilekic $
39 * $FreeBSD: head/sys/kern/tty.c 72521 2001-02-15 16:34:11Z jlemon $
40 */
41
42/*-
43 * TODO:
44 * o Fix races for sending the start char in ttyflush().
45 * o Handle inter-byte timeout for "MIN > 0, TIME > 0" in ttyselect().
46 * With luck, there will be MIN chars before select() returns().
47 * o Handle CLOCAL consistently for ptys. Perhaps disallow setting it.

--- 60 unchanged lines hidden (view full) ---

108static void ttyecho __P((int c, struct tty *tp));
109static int ttyoutput __P((int c, register struct tty *tp));
110static void ttypend __P((struct tty *tp));
111static void ttyretype __P((struct tty *tp));
112static void ttyrub __P((int c, struct tty *tp));
113static void ttyrubo __P((struct tty *tp, int cnt));
114static void ttyunblock __P((struct tty *tp));
115static int ttywflush __P((struct tty *tp));
40 */
41
42/*-
43 * TODO:
44 * o Fix races for sending the start char in ttyflush().
45 * o Handle inter-byte timeout for "MIN > 0, TIME > 0" in ttyselect().
46 * With luck, there will be MIN chars before select() returns().
47 * o Handle CLOCAL consistently for ptys. Perhaps disallow setting it.

--- 60 unchanged lines hidden (view full) ---

108static void ttyecho __P((int c, struct tty *tp));
109static int ttyoutput __P((int c, register struct tty *tp));
110static void ttypend __P((struct tty *tp));
111static void ttyretype __P((struct tty *tp));
112static void ttyrub __P((int c, struct tty *tp));
113static void ttyrubo __P((struct tty *tp, int cnt));
114static void ttyunblock __P((struct tty *tp));
115static int ttywflush __P((struct tty *tp));
116static int filt_ttyread __P((struct knote *kn, long hint));
117static void filt_ttyrdetach __P((struct knote *kn));
118static int filt_ttywrite __P((struct knote *kn, long hint));
119static void filt_ttywdetach __P((struct knote *kn));
116
117/*
118 * Table with character classes and parity. The 8th bit indicates parity,
119 * the 7th bit indicates the character is an alphameric or underscore (for
120 * ALTWERASE), and the low 6 bits indicate delay type. If the low 6 bits
121 * are 0 then the character needs no special processing on output; classes
122 * other than 0 might be translated or (not currently) require delays.
123 */

--- 963 unchanged lines hidden (view full) ---

1087 revents |= events & (POLLOUT | POLLWRNORM);
1088 else
1089 selrecord(p, &tp->t_wsel);
1090 }
1091 splx(s);
1092 return (revents);
1093}
1094
120
121/*
122 * Table with character classes and parity. The 8th bit indicates parity,
123 * the 7th bit indicates the character is an alphameric or underscore (for
124 * ALTWERASE), and the low 6 bits indicate delay type. If the low 6 bits
125 * are 0 then the character needs no special processing on output; classes
126 * other than 0 might be translated or (not currently) require delays.
127 */

--- 963 unchanged lines hidden (view full) ---

1091 revents |= events & (POLLOUT | POLLWRNORM);
1092 else
1093 selrecord(p, &tp->t_wsel);
1094 }
1095 splx(s);
1096 return (revents);
1097}
1098
1099static struct filterops ttyread_filtops =
1100 { 1, NULL, filt_ttyrdetach, filt_ttyread };
1101static struct filterops ttywrite_filtops =
1102 { 1, NULL, filt_ttywdetach, filt_ttywrite };
1103
1104int
1105ttykqfilter(dev, kn)
1106 dev_t dev;
1107 struct knote *kn;
1108{
1109 struct tty *tp = dev->si_tty;
1110 struct klist *klist;
1111 int s;
1112
1113 switch (kn->kn_filter) {
1114 case EVFILT_READ:
1115 klist = &tp->t_rsel.si_note;
1116 kn->kn_fop = &ttyread_filtops;
1117 break;
1118 case EVFILT_WRITE:
1119 klist = &tp->t_wsel.si_note;
1120 kn->kn_fop = &ttywrite_filtops;
1121 break;
1122 default:
1123 return (1);
1124 }
1125
1126 kn->kn_hook = (caddr_t)dev;
1127
1128 s = spltty();
1129 SLIST_INSERT_HEAD(klist, kn, kn_selnext);
1130 splx(s);
1131
1132 return (0);
1133}
1134
1135static void
1136filt_ttyrdetach(struct knote *kn)
1137{
1138 struct tty *tp = ((dev_t)kn->kn_hook)->si_tty;
1139 int s = spltty();
1140
1141 SLIST_REMOVE(&tp->t_rsel.si_note, kn, knote, kn_selnext);
1142 splx(s);
1143}
1144
1145static int
1146filt_ttyread(struct knote *kn, long hint)
1147{
1148 struct tty *tp = ((dev_t)kn->kn_hook)->si_tty;
1149
1150 kn->kn_data = ttnread(tp);
1151 if (ISSET(tp->t_state, TS_ZOMBIE)) {
1152 kn->kn_flags |= EV_EOF;
1153 return (1);
1154 }
1155 return (kn->kn_data > 0);
1156}
1157
1158static void
1159filt_ttywdetach(struct knote *kn)
1160{
1161 struct tty *tp = ((dev_t)kn->kn_hook)->si_tty;
1162 int s = spltty();
1163
1164 SLIST_REMOVE(&tp->t_wsel.si_note, kn, knote, kn_selnext);
1165 splx(s);
1166}
1167
1168static int
1169filt_ttywrite(kn, hint)
1170 struct knote *kn;
1171 long hint;
1172{
1173 struct tty *tp = ((dev_t)kn->kn_hook)->si_tty;
1174
1175 kn->kn_data = tp->t_outq.c_cc;
1176 if (ISSET(tp->t_state, TS_ZOMBIE))
1177 return (1);
1178 return (kn->kn_data <= tp->t_olowat &&
1179 ISSET(tp->t_state, TS_CONNECTED));
1180}
1181
1095/*
1096 * Must be called at spltty().
1097 */
1098static int
1099ttnread(tp)
1100 struct tty *tp;
1101{
1102 int nread;

--- 1010 unchanged lines hidden (view full) ---

2113 register struct tty *tp;
2114{
2115
2116 if (tp->t_rsel.si_pid != 0)
2117 selwakeup(&tp->t_rsel);
2118 if (ISSET(tp->t_state, TS_ASYNC) && tp->t_sigio != NULL)
2119 pgsigio(tp->t_sigio, SIGIO, (tp->t_session != NULL));
2120 wakeup(TSA_HUP_OR_INPUT(tp));
1182/*
1183 * Must be called at spltty().
1184 */
1185static int
1186ttnread(tp)
1187 struct tty *tp;
1188{
1189 int nread;

--- 1010 unchanged lines hidden (view full) ---

2200 register struct tty *tp;
2201{
2202
2203 if (tp->t_rsel.si_pid != 0)
2204 selwakeup(&tp->t_rsel);
2205 if (ISSET(tp->t_state, TS_ASYNC) && tp->t_sigio != NULL)
2206 pgsigio(tp->t_sigio, SIGIO, (tp->t_session != NULL));
2207 wakeup(TSA_HUP_OR_INPUT(tp));
2208 KNOTE(&tp->t_rsel.si_note, 0);
2121}
2122
2123/*
2124 * Wake up any writers on a tty.
2125 */
2126void
2127ttwwakeup(tp)
2128 register struct tty *tp;

--- 8 unchanged lines hidden (view full) ---

2137 CLR(tp->t_state, TS_SO_OCOMPLETE);
2138 wakeup(TSA_OCOMPLETE(tp));
2139 }
2140 if (ISSET(tp->t_state, TS_SO_OLOWAT) &&
2141 tp->t_outq.c_cc <= tp->t_olowat) {
2142 CLR(tp->t_state, TS_SO_OLOWAT);
2143 wakeup(TSA_OLOWAT(tp));
2144 }
2209}
2210
2211/*
2212 * Wake up any writers on a tty.
2213 */
2214void
2215ttwwakeup(tp)
2216 register struct tty *tp;

--- 8 unchanged lines hidden (view full) ---

2225 CLR(tp->t_state, TS_SO_OCOMPLETE);
2226 wakeup(TSA_OCOMPLETE(tp));
2227 }
2228 if (ISSET(tp->t_state, TS_SO_OLOWAT) &&
2229 tp->t_outq.c_cc <= tp->t_olowat) {
2230 CLR(tp->t_state, TS_SO_OLOWAT);
2231 wakeup(TSA_OLOWAT(tp));
2232 }
2233 KNOTE(&tp->t_wsel.si_note, 0);
2145}
2146
2147/*
2148 * Look up a code for a specified speed in a conversion table;
2149 * used by drivers to map software speed values to hardware parameters.
2150 */
2151int
2152ttspeedtab(speed, table)

--- 346 unchanged lines hidden ---
2234}
2235
2236/*
2237 * Look up a code for a specified speed in a conversion table;
2238 * used by drivers to map software speed values to hardware parameters.
2239 */
2240int
2241ttspeedtab(speed, table)

--- 346 unchanged lines hidden ---