m_ioctl.c 6.7 KB

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