m_ioctl.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. #if 0
  91. /* FIXME: I'm not entirely certain what these do; I think they have
  92. * to do with serial port manipulation. If so, they need to be rewritten
  93. * to use the Posix standards. ---dtrg */
  94. case TIOCGETP:
  95. /* Get fd's current param's and store at dsp2 */
  96. if ( (e = ioctl(fd, req, (char *) &sg_buf)) == -1
  97. || !sgttyb2mem(addr, &sg_buf)
  98. ) {
  99. e = -1; /* errno already set */
  100. }
  101. break;
  102. case TIOCSETP:
  103. #ifdef BSD4_1 /* from system.h */
  104. case TIOCSETN:
  105. #endif /* BSD4_1 */
  106. /* set fd's parameters according to sgtty buffer */
  107. /* pointed to (addr), so first fill sg_buf properly. */
  108. if ( !mem2sgtty(addr, &sg_buf)
  109. || (e = ioctl(fd, req, (char *) &sg_buf)) == -1
  110. ) {
  111. e = -1; /* errno already set */
  112. }
  113. break;
  114. case TIOCEXCL:
  115. case TIOCNXCL:
  116. case TIOCHPCL:
  117. /* These have no third argument. */
  118. e = ioctl(fd, req, (char *) 0);
  119. break;
  120. #endif
  121. #ifdef BSD_X /* from system.h */
  122. /*************************************/
  123. /****** Struct tchars ioctl's ********/
  124. /*************************************/
  125. case TIOCGETC:
  126. /* get special char's; store at addr */
  127. if ( (e = ioctl(fd, req, (char *) &tc_buf)) == -1
  128. || !tchars2mem(addr, &tc_buf)
  129. ) {
  130. e = -1; /* errno already set */
  131. }
  132. break;
  133. case TIOCSETC:
  134. /* set special char's; load from addr */
  135. if ( !mem2tchars(addr, &tc_buf)
  136. || (e = ioctl(fd, req, (char *) &tc_buf)) == -1
  137. ) {
  138. e = -1;
  139. }
  140. break;
  141. #ifndef V7IOCTL
  142. /***************************************/
  143. /****** Local mode word ioctl's ********/
  144. /***************************************/
  145. case TIOCLBIS: /* addr points to mask which is or-ed with lmw */
  146. case TIOCLBIC: /* addr points to mask, ~mask & lmw is done */
  147. case TIOCLSET: /* addr points to mask, lmw is replaced by it */
  148. if (memfault(addr, wsize)) {
  149. e = -1;
  150. }
  151. else {
  152. mask = mem_ldu(addr, wsize);
  153. e = ioctl(fd, req, (char *) &mask);
  154. }
  155. break;
  156. case TIOCLGET: /* addr points to space, store lmw there */
  157. if ( memfault(addr, wsize)
  158. || (e = ioctl(fd, req, (char *) &mask)) == -1
  159. ) {
  160. e = -1;
  161. }
  162. else {
  163. mem_stn(addr, (long) mask, wsize);
  164. }
  165. break;
  166. /**************************************/
  167. /****** Struct ltchars ioctl's ********/
  168. /**************************************/
  169. case TIOCGLTC:
  170. /* get current ltc's; store at addr */
  171. if ( (e = ioctl(fd, req, (char *) &ltc_buf)) == -1
  172. || !ltchars2mem(addr, &ltc_buf)
  173. ) {
  174. e = -1; /* errno already set */
  175. }
  176. break;
  177. case TIOCSLTC:
  178. /* set ltc_buf; load from addr */
  179. if ( !mem2ltchars(addr, &ltc_buf)
  180. || (e = ioctl(fd, req, (char *) &ltc_buf)) == -1
  181. ) {
  182. e = -1;
  183. }
  184. break;
  185. /*************************************/
  186. /****** Miscellaneous ioctl's ********/
  187. /*************************************/
  188. case TIOCGETD:
  189. /* Get line discipline, store at addr */
  190. if ( memfault(addr, wsize)
  191. || (e = ioctl(fd, req, (char *) &ldisc)) == -1
  192. ) {
  193. e = -1;
  194. }
  195. else {
  196. mem_stn(addr, (long) ldisc, wsize);
  197. }
  198. break;
  199. case TIOCSETD:
  200. /* Set line discipline, load from addr */
  201. if (memfault(addr, wsize)) {
  202. e = -1;
  203. }
  204. else {
  205. ldisc = (int) mem_ldu(addr, wsize);
  206. e = ioctl(fd, req, (char *) &ldisc);
  207. }
  208. break;
  209. /* The following are not standard vanilla 7 UNIX */
  210. case TIOCSBRK: /* These have no argument */
  211. case TIOCCBRK: /* They work on parts of struct sgttyb */
  212. case TIOCSDTR:
  213. case TIOCCDTR:
  214. e = ioctl(fd, req, (char *) 0);
  215. break;
  216. /* The following are used to set the line discipline */
  217. case OTTYDISC:
  218. case NETLDISC:
  219. case NTTYDISC:
  220. e = ioctl(fd, req, (char *) 0);
  221. break;
  222. case TIOCSTI: /* addr = address of character */
  223. if (memfault(addr, 1L)) {
  224. e = -1;
  225. }
  226. else {
  227. c = (char) mem_ldu(addr, 1L);
  228. e = ioctl(fd, req, (char *) &c);
  229. }
  230. break;
  231. case TIOCGPGRP:
  232. /* store proc grp number of control term in addr */
  233. if ( memfault(addr, wsize)
  234. || (e = ioctl(fd, req, (char *) &pgrp)) == -1
  235. ) {
  236. e = -1;
  237. }
  238. else {
  239. mem_stn(addr, (long) pgrp, wsize);
  240. }
  241. break;
  242. case TIOCSPGRP: /* addr is NO POINTER !! */
  243. e = ioctl(fd, req, (char *) addr);
  244. break;
  245. case FIONREAD: /* do the ioctl, addr is long-int ptr now */
  246. if ( memfault(addr, wsize)
  247. || (e = ioctl(fd, req, (char *) &count)) == -1
  248. ) {
  249. e = -1;
  250. }
  251. else {
  252. mem_stn(addr, count, wsize);
  253. }
  254. break;
  255. #endif /* V7IOCTL */
  256. #endif /* BSD_X */
  257. default:
  258. einval(WBADIOCTL);
  259. e = -1; /* Fake return value */
  260. break;
  261. }
  262. return (e);
  263. }