m_ioctl.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. Dedicated to the ioctl system call, MON 54.
  3. */
  4. /* $Id$ */
  5. #include "sysidf.h"
  6. #include "v7ioctl.h"
  7. #include "global.h"
  8. #include "mem.h"
  9. #include "warn.h"
  10. #include <sgtty.h>
  11. #ifdef V7IOCTL /* define the proper V7 requests */
  12. #define V7IOGETP (('t'<<8)|8)
  13. #define V7IOSETP (('t'<<8)|9)
  14. #define V7IOSETN (('t'<<8)|10)
  15. #define V7IOEXCL (('t'<<8)|13)
  16. #define V7IONXCL (('t'<<8)|14)
  17. #define V7IOHPCL (('t'<<8)|2)
  18. #define V7IOFLUSH (('t'<<8)|16)
  19. #define V7IOSETC (('t'<<8)|17)
  20. #define V7IOGETC (('t'<<8)|18)
  21. #endif /* V7IOCTL */
  22. /************************************************************************
  23. * do_ioctl handles all ioctl system calls. It is called by the *
  24. * moncall() routine, case 54. It was too big to leave it there. *
  25. * The ioctl system call is divided into 5 parts. *
  26. * Ioctl's dealing with respectively: *
  27. * sgttyb, tchars, local mode word, ltchars, and miscellaneous ioctl's. *
  28. * Some of the sgttyb-calls are only possible under the new tty-driver. *
  29. * All of these are to be found in the miscellaneous section. *
  30. * do_ioctl() simply returns the value ioctl() would return itself. *
  31. * (0 for success, -1 for failure) *
  32. ***********************************************************************/
  33. int do_ioctl(fd, req, addr)
  34. int fd, req;
  35. ptr addr;
  36. {
  37. register long e;
  38. struct sgttyb sg_buf;
  39. #ifdef BSD_X /* from system.h */
  40. #ifndef V7IOCTL
  41. char c;
  42. int mask; /* will get ALIGNMENT problems with this one */
  43. long count; /* might get ALIGNMENT problems with this one */
  44. int ldisc; /* might get ALIGNMENT problems with this one */
  45. int pgrp; /* might get ALIGNMENT problems with this one */
  46. #endif /* V7IOCTL */
  47. struct tchars tc_buf;
  48. #ifndef V7IOCTL
  49. struct ltchars ltc_buf;
  50. #endif /* V7IOCTL */
  51. #endif /* BSD_X */
  52. #ifdef V7IOCTL
  53. switch (req) { /* translate the V7 requests */
  54. /* and reject the non-V7 ones */
  55. case V7IOGETP:
  56. req = TIOCGETP;
  57. break;
  58. case V7IOSETP:
  59. req = TIOCSETP;
  60. break;
  61. case V7IOEXCL:
  62. req = TIOCEXCL;
  63. break;
  64. case V7IONXCL:
  65. req = TIOCNXCL;
  66. break;
  67. case V7IOHPCL:
  68. req = TIOCHPCL;
  69. break;
  70. #ifdef BSD_X /* from system.h */
  71. case V7IOSETN:
  72. req = TIOCSETN;
  73. break;
  74. case V7IOSETC:
  75. req = TIOCSETC;
  76. break;
  77. case V7IOGETC:
  78. req = TIOCGETC;
  79. break;
  80. #endif /* BSD_X */
  81. default:
  82. einval(WBADIOCTL);
  83. return (-1); /* Fake return value */
  84. }
  85. #endif /* V7IOCTL */
  86. switch (req) {
  87. /*************************************/
  88. /****** Struct sgttyb ioctl's ********/
  89. /*************************************/
  90. case TIOCGETP:
  91. /* Get fd's current param's and store at dsp2 */
  92. if ( (e = ioctl(fd, req, (char *) &sg_buf)) == -1
  93. || !sgttyb2mem(addr, &sg_buf)
  94. ) {
  95. e = -1; /* errno already set */
  96. }
  97. break;
  98. case TIOCSETP:
  99. #ifdef BSD4_1 /* from system.h */
  100. case TIOCSETN:
  101. #endif /* BSD4_1 */
  102. /* set fd's parameters according to sgtty buffer */
  103. /* pointed to (addr), so first fill sg_buf properly. */
  104. if ( !mem2sgtty(addr, &sg_buf)
  105. || (e = ioctl(fd, req, (char *) &sg_buf)) == -1
  106. ) {
  107. e = -1; /* errno already set */
  108. }
  109. break;
  110. case TIOCEXCL:
  111. case TIOCNXCL:
  112. case TIOCHPCL:
  113. /* These have no third argument. */
  114. e = ioctl(fd, req, (char *) 0);
  115. break;
  116. #ifdef BSD_X /* from system.h */
  117. /*************************************/
  118. /****** Struct tchars ioctl's ********/
  119. /*************************************/
  120. case TIOCGETC:
  121. /* get special char's; store at addr */
  122. if ( (e = ioctl(fd, req, (char *) &tc_buf)) == -1
  123. || !tchars2mem(addr, &tc_buf)
  124. ) {
  125. e = -1; /* errno already set */
  126. }
  127. break;
  128. case TIOCSETC:
  129. /* set special char's; load from addr */
  130. if ( !mem2tchars(addr, &tc_buf)
  131. || (e = ioctl(fd, req, (char *) &tc_buf)) == -1
  132. ) {
  133. e = -1;
  134. }
  135. break;
  136. #ifndef V7IOCTL
  137. /***************************************/
  138. /****** Local mode word ioctl's ********/
  139. /***************************************/
  140. case TIOCLBIS: /* addr points to mask which is or-ed with lmw */
  141. case TIOCLBIC: /* addr points to mask, ~mask & lmw is done */
  142. case TIOCLSET: /* addr points to mask, lmw is replaced by it */
  143. if (memfault(addr, wsize)) {
  144. e = -1;
  145. }
  146. else {
  147. mask = mem_ldu(addr, wsize);
  148. e = ioctl(fd, req, (char *) &mask);
  149. }
  150. break;
  151. case TIOCLGET: /* addr points to space, store lmw there */
  152. if ( memfault(addr, wsize)
  153. || (e = ioctl(fd, req, (char *) &mask)) == -1
  154. ) {
  155. e = -1;
  156. }
  157. else {
  158. mem_stn(addr, (long) mask, wsize);
  159. }
  160. break;
  161. /**************************************/
  162. /****** Struct ltchars ioctl's ********/
  163. /**************************************/
  164. case TIOCGLTC:
  165. /* get current ltc's; store at addr */
  166. if ( (e = ioctl(fd, req, (char *) &ltc_buf)) == -1
  167. || !ltchars2mem(addr, &ltc_buf)
  168. ) {
  169. e = -1; /* errno already set */
  170. }
  171. break;
  172. case TIOCSLTC:
  173. /* set ltc_buf; load from addr */
  174. if ( !mem2ltchars(addr, &ltc_buf)
  175. || (e = ioctl(fd, req, (char *) &ltc_buf)) == -1
  176. ) {
  177. e = -1;
  178. }
  179. break;
  180. /*************************************/
  181. /****** Miscellaneous ioctl's ********/
  182. /*************************************/
  183. case TIOCGETD:
  184. /* Get line discipline, store at addr */
  185. if ( memfault(addr, wsize)
  186. || (e = ioctl(fd, req, (char *) &ldisc)) == -1
  187. ) {
  188. e = -1;
  189. }
  190. else {
  191. mem_stn(addr, (long) ldisc, wsize);
  192. }
  193. break;
  194. case TIOCSETD:
  195. /* Set line discipline, load from addr */
  196. if (memfault(addr, wsize)) {
  197. e = -1;
  198. }
  199. else {
  200. ldisc = (int) mem_ldu(addr, wsize);
  201. e = ioctl(fd, req, (char *) &ldisc);
  202. }
  203. break;
  204. /* The following are not standard vanilla 7 UNIX */
  205. case TIOCSBRK: /* These have no argument */
  206. case TIOCCBRK: /* They work on parts of struct sgttyb */
  207. case TIOCSDTR:
  208. case TIOCCDTR:
  209. e = ioctl(fd, req, (char *) 0);
  210. break;
  211. /* The following are used to set the line discipline */
  212. case OTTYDISC:
  213. case NETLDISC:
  214. case NTTYDISC:
  215. e = ioctl(fd, req, (char *) 0);
  216. break;
  217. case TIOCSTI: /* addr = address of character */
  218. if (memfault(addr, 1L)) {
  219. e = -1;
  220. }
  221. else {
  222. c = (char) mem_ldu(addr, 1L);
  223. e = ioctl(fd, req, (char *) &c);
  224. }
  225. break;
  226. case TIOCGPGRP:
  227. /* store proc grp number of control term in addr */
  228. if ( memfault(addr, wsize)
  229. || (e = ioctl(fd, req, (char *) &pgrp)) == -1
  230. ) {
  231. e = -1;
  232. }
  233. else {
  234. mem_stn(addr, (long) pgrp, wsize);
  235. }
  236. break;
  237. case TIOCSPGRP: /* addr is NO POINTER !! */
  238. e = ioctl(fd, req, (char *) addr);
  239. break;
  240. case FIONREAD: /* do the ioctl, addr is long-int ptr now */
  241. if ( memfault(addr, wsize)
  242. || (e = ioctl(fd, req, (char *) &count)) == -1
  243. ) {
  244. e = -1;
  245. }
  246. else {
  247. mem_stn(addr, count, wsize);
  248. }
  249. break;
  250. #endif /* V7IOCTL */
  251. #endif /* BSD_X */
  252. default:
  253. einval(WBADIOCTL);
  254. e = -1; /* Fake return value */
  255. break;
  256. }
  257. return (e);
  258. }