2 Dedicated to the ioctl system call, MON 54.
5 /* $Id: m_ioctl.c,v 2.3 1994/06/24 10:47:58 ceriel Exp $ */
15 #ifdef V7IOCTL /* define the proper V7 requests */
17 #define V7IOGETP (('t'<<8)|8)
18 #define V7IOSETP (('t'<<8)|9)
19 #define V7IOSETN (('t'<<8)|10)
20 #define V7IOEXCL (('t'<<8)|13)
21 #define V7IONXCL (('t'<<8)|14)
22 #define V7IOHPCL (('t'<<8)|2)
23 #define V7IOFLUSH (('t'<<8)|16)
25 #define V7IOSETC (('t'<<8)|17)
26 #define V7IOGETC (('t'<<8)|18)
31 /************************************************************************
32 * do_ioctl handles all ioctl system calls. It is called by the *
33 * moncall() routine, case 54. It was too big to leave it there. *
34 * The ioctl system call is divided into 5 parts. *
35 * Ioctl's dealing with respectively: *
36 * sgttyb, tchars, local mode word, ltchars, and miscellaneous ioctl's. *
37 * Some of the sgttyb-calls are only possible under the new tty-driver. *
38 * All of these are to be found in the miscellaneous section. *
39 * do_ioctl() simply returns the value ioctl() would return itself. *
40 * (0 for success, -1 for failure) *
41 ***********************************************************************/
43 int do_ioctl(fd, req, addr)
50 #ifdef BSD_X /* from system.h */
53 int mask; /* will get ALIGNMENT problems with this one */
54 long count; /* might get ALIGNMENT problems with this one */
55 int ldisc; /* might get ALIGNMENT problems with this one */
56 int pgrp; /* might get ALIGNMENT problems with this one */
61 struct ltchars ltc_buf;
67 switch (req) { /* translate the V7 requests */
68 /* and reject the non-V7 ones */
84 #ifdef BSD_X /* from system.h */
99 return (-1); /* Fake return value */
107 /*************************************/
108 /****** Struct sgttyb ioctl's ********/
109 /*************************************/
112 /* Get fd's current param's and store at dsp2 */
113 if ( (e = ioctl(fd, req, (char *) &sg_buf)) == -1
114 || !sgttyb2mem(addr, &sg_buf)
116 e = -1; /* errno already set */
121 #ifdef BSD4_1 /* from system.h */
124 /* set fd's parameters according to sgtty buffer */
125 /* pointed to (addr), so first fill sg_buf properly. */
126 if ( !mem2sgtty(addr, &sg_buf)
127 || (e = ioctl(fd, req, (char *) &sg_buf)) == -1
129 e = -1; /* errno already set */
136 /* These have no third argument. */
137 e = ioctl(fd, req, (char *) 0);
140 #ifdef BSD_X /* from system.h */
141 /*************************************/
142 /****** Struct tchars ioctl's ********/
143 /*************************************/
146 /* get special char's; store at addr */
147 if ( (e = ioctl(fd, req, (char *) &tc_buf)) == -1
148 || !tchars2mem(addr, &tc_buf)
150 e = -1; /* errno already set */
155 /* set special char's; load from addr */
156 if ( !mem2tchars(addr, &tc_buf)
157 || (e = ioctl(fd, req, (char *) &tc_buf)) == -1
164 /***************************************/
165 /****** Local mode word ioctl's ********/
166 /***************************************/
168 case TIOCLBIS: /* addr points to mask which is or-ed with lmw */
169 case TIOCLBIC: /* addr points to mask, ~mask & lmw is done */
170 case TIOCLSET: /* addr points to mask, lmw is replaced by it */
171 if (memfault(addr, wsize)) {
175 mask = mem_ldu(addr, wsize);
176 e = ioctl(fd, req, (char *) &mask);
180 case TIOCLGET: /* addr points to space, store lmw there */
181 if ( memfault(addr, wsize)
182 || (e = ioctl(fd, req, (char *) &mask)) == -1
187 mem_stn(addr, (long) mask, wsize);
191 /**************************************/
192 /****** Struct ltchars ioctl's ********/
193 /**************************************/
196 /* get current ltc's; store at addr */
197 if ( (e = ioctl(fd, req, (char *) <c_buf)) == -1
198 || !ltchars2mem(addr, <c_buf)
200 e = -1; /* errno already set */
205 /* set ltc_buf; load from addr */
206 if ( !mem2ltchars(addr, <c_buf)
207 || (e = ioctl(fd, req, (char *) <c_buf)) == -1
213 /*************************************/
214 /****** Miscellaneous ioctl's ********/
215 /*************************************/
218 /* Get line discipline, store at addr */
219 if ( memfault(addr, wsize)
220 || (e = ioctl(fd, req, (char *) &ldisc)) == -1
225 mem_stn(addr, (long) ldisc, wsize);
230 /* Set line discipline, load from addr */
231 if (memfault(addr, wsize)) {
235 ldisc = (int) mem_ldu(addr, wsize);
236 e = ioctl(fd, req, (char *) &ldisc);
240 /* The following are not standard vanilla 7 UNIX */
241 case TIOCSBRK: /* These have no argument */
242 case TIOCCBRK: /* They work on parts of struct sgttyb */
245 e = ioctl(fd, req, (char *) 0);
248 /* The following are used to set the line discipline */
252 e = ioctl(fd, req, (char *) 0);
255 case TIOCSTI: /* addr = address of character */
256 if (memfault(addr, 1L)) {
260 c = (char) mem_ldu(addr, 1L);
261 e = ioctl(fd, req, (char *) &c);
266 /* store proc grp number of control term in addr */
267 if ( memfault(addr, wsize)
268 || (e = ioctl(fd, req, (char *) &pgrp)) == -1
273 mem_stn(addr, (long) pgrp, wsize);
277 case TIOCSPGRP: /* addr is NO POINTER !! */
278 e = ioctl(fd, req, (char *) addr);
281 case FIONREAD: /* do the ioctl, addr is long-int ptr now */
282 if ( memfault(addr, wsize)
283 || (e = ioctl(fd, req, (char *) &count)) == -1
288 mem_stn(addr, count, wsize);
297 e = -1; /* Fake return value */