dfs_file.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_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. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif