vfs_int.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // internal definitions for vfs
  2. #ifndef __VFS_INT_H__
  3. #define __VFS_INT_H__
  4. #include <c_string.h>
  5. #include <c_stdint.h>
  6. #if 0
  7. #include "spiffs.h"
  8. #include "fatfs_prefix_lib.h"
  9. #include "ff.h"
  10. #endif
  11. #define VFS_EOF -1
  12. enum vfs_filesystems {
  13. VFS_FS_NONE = 0,
  14. VFS_FS_SPIFFS,
  15. VFS_FS_FATFS
  16. };
  17. enum vfs_seek {
  18. VFS_SEEK_SET = 0,
  19. VFS_SEEK_CUR,
  20. VFS_SEEK_END
  21. };
  22. enum vfs_result {
  23. VFS_RES_OK = 0,
  24. VFS_RES_ERR = -1
  25. };
  26. struct vfs_time {
  27. int year, mon, day;
  28. int hour, min, sec;
  29. };
  30. typedef struct vfs_time vfs_time;
  31. // generic file descriptor
  32. struct vfs_file {
  33. int fs_type;
  34. const struct vfs_file_fns *fns;
  35. };
  36. typedef const struct vfs_file vfs_file;
  37. // file descriptor functions
  38. struct vfs_file_fns {
  39. sint32_t (*close)( const struct vfs_file *fd );
  40. sint32_t (*read)( const struct vfs_file *fd, void *ptr, size_t len );
  41. sint32_t (*write)( const struct vfs_file *fd, const void *ptr, size_t len );
  42. sint32_t (*lseek)( const struct vfs_file *fd, sint32_t off, int whence );
  43. sint32_t (*eof)( const struct vfs_file *fd );
  44. sint32_t (*tell)( const struct vfs_file *fd );
  45. sint32_t (*flush)( const struct vfs_file *fd );
  46. uint32_t (*size)( const struct vfs_file *fd );
  47. sint32_t (*ferrno)( const struct vfs_file *fd );
  48. };
  49. typedef const struct vfs_file_fns vfs_file_fns;
  50. // generic dir item descriptor
  51. struct vfs_item {
  52. int fs_type;
  53. const struct vfs_item_fns *fns;
  54. };
  55. typedef const struct vfs_item vfs_item;
  56. // directory item functions
  57. struct vfs_item_fns {
  58. void (*close)( const struct vfs_item *di );
  59. uint32_t (*size)( const struct vfs_item *di );
  60. sint32_t (*time)( const struct vfs_item *di, struct vfs_time *tm );
  61. const char *(*name)( const struct vfs_item *di );
  62. sint32_t (*is_dir)( const struct vfs_item *di );
  63. sint32_t (*is_rdonly)( const struct vfs_item *di );
  64. sint32_t (*is_hidden)( const struct vfs_item *di );
  65. sint32_t (*is_sys)( const struct vfs_item *di );
  66. sint32_t (*is_arch)( const struct vfs_item *di );
  67. };
  68. typedef const struct vfs_item_fns vfs_item_fns;
  69. // generic dir descriptor
  70. struct vfs_dir {
  71. int fs_type;
  72. const struct vfs_dir_fns *fns;
  73. };
  74. typedef const struct vfs_dir vfs_dir;
  75. // dir descriptor functions
  76. struct vfs_dir_fns {
  77. sint32_t (*close)( const struct vfs_dir *dd );
  78. vfs_item *(*readdir)( const struct vfs_dir *dd );
  79. };
  80. typedef const struct vfs_dir_fns vfs_dir_fns;
  81. // generic volume descriptor
  82. struct vfs_vol {
  83. int fs_type;
  84. const struct vfs_vol_fns *fns;
  85. };
  86. typedef const struct vfs_vol vfs_vol;
  87. // volume functions
  88. struct vfs_vol_fns {
  89. sint32_t (*umount)( const struct vfs_vol *vol );
  90. };
  91. typedef const struct vfs_vol_fns vfs_vol_fns;
  92. struct vfs_fs_fns {
  93. vfs_vol *(*mount)( const char *name, int num );
  94. vfs_file *(*open)( const char *name, const char *mode );
  95. vfs_dir *(*opendir)( const char *name );
  96. vfs_item *(*stat)( const char *name );
  97. sint32_t (*remove)( const char *name );
  98. sint32_t (*rename)( const char *oldname, const char *newname );
  99. sint32_t (*mkdir)( const char *name );
  100. sint32_t (*fsinfo)( uint32_t *total, uint32_t *used );
  101. sint32_t (*fscfg)( uint32_t *phys_addr, uint32_t *phys_size );
  102. sint32_t (*format)( void );
  103. sint32_t (*chdrive)( const char * );
  104. sint32_t (*chdir)( const char * );
  105. sint32_t (*ferrno)( void );
  106. void (*clearerr)( void );
  107. };
  108. typedef const struct vfs_fs_fns vfs_fs_fns;
  109. vfs_fs_fns *myspiffs_realm( const char *inname, char **outname, int set_current_drive );
  110. vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_drive );
  111. sint32_t vfs_get_rtc( vfs_time *tm );
  112. #endif