dfs_file.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * File : dfs_file.h
  3. * This file is part of Device File System in RT-Thread RTOS
  4. * COPYRIGHT (C) 2004-2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2005-01-26 Bernard The first version.
  23. */
  24. #ifndef __DFS_FILE_H__
  25. #define __DFS_FILE_H__
  26. #include <dfs.h>
  27. #include <dfs_fs.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. struct rt_pollreq;
  32. struct dfs_file_ops
  33. {
  34. int (*open) (struct dfs_fd *fd);
  35. int (*close) (struct dfs_fd *fd);
  36. int (*ioctl) (struct dfs_fd *fd, int cmd, void *args);
  37. int (*read) (struct dfs_fd *fd, void *buf, size_t count);
  38. int (*write) (struct dfs_fd *fd, const void *buf, size_t count);
  39. int (*flush) (struct dfs_fd *fd);
  40. int (*lseek) (struct dfs_fd *fd, off_t offset);
  41. int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, uint32_t count);
  42. int (*poll) (struct dfs_fd *fd, struct rt_pollreq *req);
  43. };
  44. /* file descriptor */
  45. #define DFS_FD_MAGIC 0xfdfd
  46. struct dfs_fd
  47. {
  48. uint16_t magic; /* file descriptor magic number */
  49. uint16_t type; /* Type (regular or socket) */
  50. char *path; /* Name (below mount point) */
  51. int ref_count; /* Descriptor reference count */
  52. const struct dfs_file_ops *fops;
  53. uint32_t flags; /* Descriptor flags */
  54. size_t size; /* Size in bytes */
  55. off_t pos; /* Current file position */
  56. void *data; /* Specific file system data */
  57. };
  58. int dfs_file_open(struct dfs_fd *fd, const char *path, int flags);
  59. int dfs_file_close(struct dfs_fd *fd);
  60. int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args);
  61. int dfs_file_read(struct dfs_fd *fd, void *buf, size_t len);
  62. int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, size_t nbytes);
  63. int dfs_file_unlink(const char *path);
  64. int dfs_file_write(struct dfs_fd *fd, const void *buf, size_t len);
  65. int dfs_file_flush(struct dfs_fd *fd);
  66. int dfs_file_lseek(struct dfs_fd *fd, off_t offset);
  67. int dfs_file_stat(const char *path, struct stat *buf);
  68. int dfs_file_rename(const char *oldpath, const char *newpath);
  69. #ifdef __cplusplus
  70. }
  71. #endif
  72. #endif