dfs_file.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2005-01-26 Bernard The first version.
  9. */
  10. #ifndef __DFS_FILE_H__
  11. #define __DFS_FILE_H__
  12. #include <dfs.h>
  13. #include <dfs_fs.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. struct rt_pollreq;
  18. struct dfs_file_ops
  19. {
  20. int (*open) (struct dfs_file *fd);
  21. int (*close) (struct dfs_file *fd);
  22. int (*ioctl) (struct dfs_file *fd, int cmd, void *args);
  23. ssize_t (*read) (struct dfs_file *fd, void *buf, size_t count);
  24. ssize_t (*write) (struct dfs_file *fd, const void *buf, size_t count);
  25. int (*flush) (struct dfs_file *fd);
  26. off_t (*lseek) (struct dfs_file *fd, off_t offset);
  27. int (*getdents) (struct dfs_file *fd, struct dirent *dirp, uint32_t count);
  28. int (*poll) (struct dfs_file *fd, struct rt_pollreq *req);
  29. };
  30. /* file descriptor */
  31. #define DFS_FD_MAGIC 0xfdfd
  32. struct dfs_vnode
  33. {
  34. uint16_t type; /* Type (regular or socket) */
  35. char *path; /* Name (below mount point) */
  36. char *fullpath; /* Full path is hash key */
  37. int ref_count; /* Descriptor reference count */
  38. rt_list_t list; /* The node of vnode hash table */
  39. struct dfs_filesystem *fs;
  40. const struct dfs_file_ops *fops;
  41. uint32_t flags; /* self flags, is dir etc.. */
  42. size_t size; /* Size in bytes */
  43. void *data; /* Specific file system data */
  44. };
  45. struct dfs_file
  46. {
  47. uint16_t magic; /* file descriptor magic number */
  48. uint32_t flags; /* Descriptor flags */
  49. int ref_count; /* Descriptor reference count */
  50. off_t pos; /* Current file position */
  51. struct dfs_vnode *vnode; /* file node struct */
  52. void *data; /* Specific fd data */
  53. };
  54. #define DFS_FILE_POS(dfs_file) ((dfs_file)->pos)
  55. #ifdef RT_USING_SMART
  56. struct dfs_mmap2_args
  57. {
  58. void *addr;
  59. size_t length;
  60. int prot;
  61. int flags;
  62. off_t pgoffset;
  63. struct rt_lwp *lwp;
  64. void *ret;
  65. };
  66. #endif
  67. void dfs_vnode_mgr_init(void);
  68. int dfs_vnode_init(struct dfs_vnode *vnode, int type, const struct dfs_file_ops *fops);
  69. int dfs_file_is_open(const char *pathname);
  70. int dfs_file_open(struct dfs_file *fd, const char *path, int flags);
  71. int dfs_file_close(struct dfs_file *fd);
  72. int dfs_file_ioctl(struct dfs_file *fd, int cmd, void *args);
  73. ssize_t dfs_file_read(struct dfs_file *fd, void *buf, size_t len);
  74. int dfs_file_getdents(struct dfs_file *fd, struct dirent *dirp, size_t nbytes);
  75. int dfs_file_unlink(const char *path);
  76. ssize_t dfs_file_write(struct dfs_file *fd, const void *buf, size_t len);
  77. int dfs_file_flush(struct dfs_file *fd);
  78. off_t dfs_file_lseek(struct dfs_file *fd, off_t offset);
  79. int dfs_file_stat(const char *path, struct stat *buf);
  80. int dfs_file_rename(const char *oldpath, const char *newpath);
  81. int dfs_file_ftruncate(struct dfs_file *fd, off_t length);
  82. #ifdef RT_USING_SMART
  83. int dfs_file_mmap2(struct dfs_file *fd, struct dfs_mmap2_args *mmap2);
  84. #endif
  85. /* 0x5254 is just a magic number to make these relatively unique ("RT") */
  86. #define RT_FIOFTRUNCATE 0x52540000U
  87. #define RT_FIOGETADDR 0x52540001U
  88. #define RT_FIOMMAP2 0x52540002U
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif