dfs_file.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2006-2018, 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_fd *fd);
  21. int (*close) (struct dfs_fd *fd);
  22. int (*ioctl) (struct dfs_fd *fd, int cmd, void *args);
  23. int (*read) (struct dfs_fd *fd, void *buf, size_t count);
  24. int (*write) (struct dfs_fd *fd, const void *buf, size_t count);
  25. int (*flush) (struct dfs_fd *fd);
  26. int (*lseek) (struct dfs_fd *fd, off_t offset);
  27. int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, uint32_t count);
  28. int (*poll) (struct dfs_fd *fd, struct rt_pollreq *req);
  29. };
  30. /* file descriptor */
  31. #define DFS_FD_MAGIC 0xfdfd
  32. struct dfs_fnode
  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 fnode 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_fd
  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_fnode *fnode; /* file node struct */
  52. void *data; /* Specific fd data */
  53. };
  54. void dfs_fnode_mgr_init(void);
  55. int dfs_file_is_open(const char *pathname);
  56. int dfs_file_open(struct dfs_fd *fd, const char *path, int flags);
  57. int dfs_file_close(struct dfs_fd *fd);
  58. int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args);
  59. int dfs_file_read(struct dfs_fd *fd, void *buf, size_t len);
  60. int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, size_t nbytes);
  61. int dfs_file_unlink(const char *path);
  62. int dfs_file_write(struct dfs_fd *fd, const void *buf, size_t len);
  63. int dfs_file_flush(struct dfs_fd *fd);
  64. int dfs_file_lseek(struct dfs_fd *fd, off_t offset);
  65. int dfs_file_stat(const char *path, struct stat *buf);
  66. int dfs_file_rename(const char *oldpath, const char *newpath);
  67. int dfs_file_ftruncate(struct dfs_fd *fd, off_t length);
  68. /* 0x5254 is just a magic number to make these relatively unique ("RT") */
  69. #define RT_FIOFTRUNCATE 0x52540000U
  70. #define RT_FIOGETADDR 0x52540001U
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif