tty.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <filesystem/devfs/devfs.h>
  2. #include <filesystem/VFS/VFS.h>
  3. #include "tty.h"
  4. static struct devfs_private_inode_info_t * tty_inode_private_data_ptr; // 由devfs创建的inode私有信息指针
  5. static int tty_private_data;
  6. /**
  7. * @brief 打开tty文件
  8. *
  9. * @param inode 所在的inode
  10. * @param filp 文件指针
  11. * @return long
  12. */
  13. long tty_open(struct vfs_index_node_t *inode, struct vfs_file_t *filp)
  14. {
  15. filp->private_data = &tty_private_data;
  16. return 0;
  17. }
  18. /**
  19. * @brief 关闭tty文件
  20. *
  21. * @param inode 所在的inode
  22. * @param filp 文件指针
  23. * @return long
  24. */
  25. long tty_close(struct vfs_index_node_t *inode, struct vfs_file_t *filp)
  26. {
  27. filp->private_data = NULL;
  28. return 0;
  29. }
  30. /**
  31. * @brief tty控制接口
  32. *
  33. * @param inode 所在的inode
  34. * @param filp tty文件指针
  35. * @param cmd 命令
  36. * @param arg 参数
  37. * @return long
  38. */
  39. long tty_ioctl(struct vfs_index_node_t *inode, struct vfs_file_t *filp, uint64_t cmd, uint64_t arg)
  40. {
  41. switch (cmd)
  42. {
  43. default:
  44. break;
  45. }
  46. return 0;
  47. }
  48. /**
  49. * @brief 读取tty文件的操作接口
  50. *
  51. * @param filp 文件指针
  52. * @param buf 输出缓冲区
  53. * @param count 要读取的字节数
  54. * @param position 读取的位置
  55. * @return long 读取的字节数
  56. */
  57. long tty_read(struct vfs_file_t *filp, char *buf, int64_t count, long *position)
  58. {
  59. return 0;
  60. }
  61. /**
  62. * @brief tty文件写入接口(无作用,空)
  63. *
  64. * @param filp
  65. * @param buf
  66. * @param count
  67. * @param position
  68. * @return long
  69. */
  70. long tty_write(struct vfs_file_t *filp, char *buf, int64_t count, long *position)
  71. {
  72. return 0;
  73. }
  74. struct vfs_file_operations_t tty_fops={
  75. .open = tty_open,
  76. .close = tty_close,
  77. .ioctl = tty_ioctl,
  78. .read = tty_read,
  79. .write = tty_write,
  80. };
  81. void tty_init(){
  82. //注册devfs
  83. devfs_register_device(DEV_TYPE_CHAR, CHAR_DEV_STYPE_TTY, &tty_fops, &tty_inode_private_data_ptr);
  84. kinfo("tty driver registered. uuid=%d", tty_inode_private_data_ptr->uuid);
  85. }