n_null.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <linux/types.h>
  2. #include <linux/errno.h>
  3. #include <linux/tty.h>
  4. #include <linux/module.h>
  5. /*
  6. * n_null.c - Null line discipline used in the failure path
  7. *
  8. * Copyright (C) Intel 2017
  9. *
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. */
  23. static int n_null_open(struct tty_struct *tty)
  24. {
  25. return 0;
  26. }
  27. static void n_null_close(struct tty_struct *tty)
  28. {
  29. }
  30. static ssize_t n_null_read(struct tty_struct *tty, struct file *file,
  31. unsigned char __user * buf, size_t nr)
  32. {
  33. return -EOPNOTSUPP;
  34. }
  35. static ssize_t n_null_write(struct tty_struct *tty, struct file *file,
  36. const unsigned char *buf, size_t nr)
  37. {
  38. return -EOPNOTSUPP;
  39. }
  40. static void n_null_receivebuf(struct tty_struct *tty,
  41. const unsigned char *cp, char *fp,
  42. int cnt)
  43. {
  44. }
  45. static struct tty_ldisc_ops null_ldisc = {
  46. .owner = THIS_MODULE,
  47. .magic = TTY_LDISC_MAGIC,
  48. .name = "n_null",
  49. .open = n_null_open,
  50. .close = n_null_close,
  51. .read = n_null_read,
  52. .write = n_null_write,
  53. .receive_buf = n_null_receivebuf
  54. };
  55. static int __init n_null_init(void)
  56. {
  57. BUG_ON(tty_register_ldisc(N_NULL, &null_ldisc));
  58. return 0;
  59. }
  60. static void __exit n_null_exit(void)
  61. {
  62. tty_unregister_ldisc(N_NULL);
  63. }
  64. module_init(n_null_init);
  65. module_exit(n_null_exit);
  66. MODULE_LICENSE("GPL");
  67. MODULE_AUTHOR("Alan Cox");
  68. MODULE_ALIAS_LDISC(N_NULL);
  69. MODULE_DESCRIPTION("Null ldisc driver");