proc_tty.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include "proc.h"
  10. #include "procfs.h"
  11. #include <rthw.h>
  12. #include <rtdbg.h>
  13. #include <fcntl.h>
  14. #include <errno.h>
  15. #include <dfs_dentry.h>
  16. static void *seq_start(struct dfs_seq_file *seq, off_t *index)
  17. {
  18. off_t i = *index; // seq->index
  19. return NULL + (i == 0);
  20. }
  21. static void seq_stop(struct dfs_seq_file *seq, void *data)
  22. {
  23. }
  24. static void *seq_next(struct dfs_seq_file *seq, void *data, off_t *index)
  25. {
  26. /* data: The return value of the start or next*/
  27. off_t i = *index + 1; // seq->index
  28. *index = i;
  29. return NULL;
  30. }
  31. static int seq_show(struct dfs_seq_file *seq, void *data)
  32. {
  33. /* data: The return value of the start or next*/
  34. dfs_seq_puts(seq, "todo\n");
  35. return 0;
  36. }
  37. static const struct dfs_seq_ops seq_ops = {
  38. .start = seq_start,
  39. .stop = seq_stop,
  40. .next = seq_next,
  41. .show = seq_show,
  42. };
  43. void proc_tty_register_driver(void *driver)
  44. {
  45. //todo
  46. }
  47. void proc_tty_unregister_driver(void *driver)
  48. {
  49. //todo
  50. }
  51. int proc_tty_init(void)
  52. {
  53. struct proc_dentry *dentry;
  54. dentry = proc_mkdir("tty", NULL);
  55. if (!dentry)
  56. return -1;
  57. proc_release(dentry);
  58. dentry = proc_mkdir("tty/ldisc", NULL);
  59. proc_release(dentry);
  60. dentry = proc_mkdir_mode("tty/driver", S_IRUSR|S_IXUSR, NULL);
  61. proc_release(dentry);
  62. dentry = proc_create_data("tty/ldiscs", 0, NULL, NULL, NULL);
  63. if (dentry)
  64. {
  65. dentry->seq_ops = &seq_ops;
  66. }
  67. proc_release(dentry);
  68. dentry = proc_create_data("tty/drivers", 0, NULL, NULL, NULL);
  69. if (dentry)
  70. {
  71. dentry->seq_ops = &seq_ops;
  72. }
  73. proc_release(dentry);
  74. return 0;
  75. }
  76. INIT_ENV_EXPORT(proc_tty_init);