dfs_file.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_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_fd
  33. {
  34. uint16_t magic; /* file descriptor magic number */
  35. uint16_t type; /* Type (regular or socket) */
  36. char *path; /* Name (below mount point) */
  37. int ref_count; /* Descriptor reference count */
  38. struct dfs_filesystem *fs;
  39. const struct dfs_file_ops *fops;
  40. uint32_t flags; /* Descriptor flags */
  41. size_t size; /* Size in bytes */
  42. off_t pos; /* Current file position */
  43. void *data; /* Specific file system data */
  44. };
  45. int dfs_file_open(struct dfs_fd *fd, const char *path, int flags);
  46. int dfs_file_close(struct dfs_fd *fd);
  47. int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args);
  48. int dfs_file_read(struct dfs_fd *fd, void *buf, size_t len);
  49. int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, size_t nbytes);
  50. int dfs_file_unlink(const char *path);
  51. int dfs_file_write(struct dfs_fd *fd, const void *buf, size_t len);
  52. int dfs_file_flush(struct dfs_fd *fd);
  53. int dfs_file_lseek(struct dfs_fd *fd, off_t offset);
  54. int dfs_file_stat(const char *path, struct stat *buf);
  55. int dfs_file_rename(const char *oldpath, const char *newpath);
  56. int dfs_file_ftruncate(struct dfs_fd *fd, off_t length);
  57. /* 0x5254 is just a magic number to make these relatively unique ("RT") */
  58. #define RT_FIOFTRUNCATE 0x52540000U
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif