_ioctl.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <lib.h>
  2. #include <minix/com.h>
  3. #define ioctl _ioctl
  4. #include <sgtty.h>
  5. PUBLIC int ioctl(fd, request, argp)
  6. int fd;
  7. int request;
  8. struct sgttyb *argp;
  9. {
  10. int n;
  11. long erase, kill, intr, quit, xon, xoff, eof, brk, speed;
  12. struct tchars *argt;
  13. _M.TTY_REQUEST = request;
  14. _M.TTY_LINE = fd;
  15. switch(request) {
  16. case TIOCSETP:
  17. erase = argp->sg_erase & BYTE;
  18. kill = argp->sg_kill & BYTE;
  19. speed = ((argp->sg_ospeed & BYTE) << 8) | (argp->sg_ispeed & BYTE);
  20. _M.TTY_SPEK = (speed << 16) | (erase << 8) | kill;
  21. _M.TTY_FLAGS = argp->sg_flags;
  22. n = _callx(FS, IOCTL);
  23. return(n);
  24. case TIOCSETC:
  25. argt = (struct tchars * /* kludge */) argp;
  26. intr = argt->t_intrc & BYTE;
  27. quit = argt->t_quitc & BYTE;
  28. xon = argt->t_startc & BYTE;
  29. xoff = argt->t_stopc & BYTE;
  30. eof = argt->t_eofc & BYTE;
  31. brk = argt->t_brkc & BYTE; /* not used at the moment */
  32. _M.TTY_SPEK = (intr<<24) | (quit<<16) | (xon<<8) | (xoff<<0);
  33. _M.TTY_FLAGS = (eof<<8) | (brk<<0);
  34. n = _callx(FS, IOCTL);
  35. return(n);
  36. case TIOCGETP:
  37. n = _callx(FS, IOCTL);
  38. argp->sg_erase = (_M.TTY_SPEK >> 8) & BYTE;
  39. argp->sg_kill = (_M.TTY_SPEK >> 0) & BYTE;
  40. argp->sg_flags = _M.TTY_FLAGS & 0xFFFFL;
  41. speed = (_M.TTY_SPEK >> 16) & 0xFFFFL;
  42. argp->sg_ispeed = speed & BYTE;
  43. argp->sg_ospeed = (speed >> 8) & BYTE;
  44. return(n);
  45. case TIOCGETC:
  46. n = _callx(FS, IOCTL);
  47. argt = (struct tchars *) argp;
  48. argt->t_intrc = (_M.TTY_SPEK >> 24) & BYTE;
  49. argt->t_quitc = (_M.TTY_SPEK >> 16) & BYTE;
  50. argt->t_startc = (_M.TTY_SPEK >> 8) & BYTE;
  51. argt->t_stopc = (_M.TTY_SPEK >> 0) & BYTE;
  52. argt->t_eofc = (_M.TTY_FLAGS >> 8) & BYTE;
  53. argt->t_brkc = (_M.TTY_FLAGS >> 8) & BYTE;
  54. return(n);
  55. /* This is silly, do we want to add 1001 cases and _M.TTY_XYZ's here?
  56. * We should just pop argp into the message for low-level interpretation.
  57. */
  58. case TIOCFLUSH:
  59. _M.TTY_FLAGS = (int /* kludge */) argp;
  60. return _callx(FS, IOCTL);
  61. /* decided to pop argp in the ADDRESS field. Left TIOCFLUSH a special case
  62. * since it affects other platforms and old software too. FM
  63. */
  64. default:
  65. _M.ADDRESS = (char *)argp;
  66. return _callx(FS, IOCTL);
  67. }
  68. }