tty.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include <stdio.h>
  6. #include <termios.h>
  7. #include <errno.h>
  8. #include <unistd.h>
  9. #include "chan_user.h"
  10. #include "user_util.h"
  11. #include "user.h"
  12. #include "os.h"
  13. struct tty_chan {
  14. char *dev;
  15. int raw;
  16. struct termios tt;
  17. };
  18. static void *tty_chan_init(char *str, int device, struct chan_opts *opts)
  19. {
  20. struct tty_chan *data;
  21. if(*str != ':'){
  22. printk("tty_init : channel type 'tty' must specify "
  23. "a device\n");
  24. return(NULL);
  25. }
  26. str++;
  27. data = um_kmalloc(sizeof(*data));
  28. if(data == NULL)
  29. return(NULL);
  30. *data = ((struct tty_chan) { .dev = str,
  31. .raw = opts->raw });
  32. return(data);
  33. }
  34. static int tty_open(int input, int output, int primary, void *d,
  35. char **dev_out)
  36. {
  37. struct tty_chan *data = d;
  38. int fd, err;
  39. fd = os_open_file(data->dev, of_set_rw(OPENFLAGS(), input, output), 0);
  40. if(fd < 0) return(fd);
  41. if(data->raw){
  42. CATCH_EINTR(err = tcgetattr(fd, &data->tt));
  43. if(err)
  44. return(err);
  45. err = raw(fd);
  46. if(err)
  47. return(err);
  48. }
  49. *dev_out = data->dev;
  50. return(fd);
  51. }
  52. struct chan_ops tty_ops = {
  53. .type = "tty",
  54. .init = tty_chan_init,
  55. .open = tty_open,
  56. .close = generic_close,
  57. .read = generic_read,
  58. .write = generic_write,
  59. .console_write = generic_console_write,
  60. .window_size = generic_window_size,
  61. .free = generic_free,
  62. .winch = 0,
  63. };
  64. /*
  65. * Overrides for Emacs so that we follow Linus's tabbing style.
  66. * Emacs will notice this stuff at the end of the file and automatically
  67. * adjust the settings for this buffer only. This must remain at the end
  68. * of the file.
  69. * ---------------------------------------------------------------------------
  70. * Local variables:
  71. * c-file-style: "linux"
  72. * End:
  73. */