vfs_int.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. // stat data
  38. struct vfs_stat {
  39. uint32_t size;
  40. char name[FS_OBJ_NAME_LEN+1];
  41. struct vfs_time tm;
  42. uint8_t tm_valid;
  43. uint8_t is_dir;
  44. uint8_t is_rdonly;
  45. uint8_t is_hidden;
  46. uint8_t is_sys;
  47. uint8_t is_arch;
  48. };
  49. // file descriptor functions
  50. struct vfs_file_fns {
  51. sint32_t (*close)( const struct vfs_file *fd );
  52. sint32_t (*read)( const struct vfs_file *fd, void *ptr, size_t len );
  53. sint32_t (*write)( const struct vfs_file *fd, const void *ptr, size_t len );
  54. sint32_t (*lseek)( const struct vfs_file *fd, sint32_t off, int whence );
  55. sint32_t (*eof)( const struct vfs_file *fd );
  56. sint32_t (*tell)( const struct vfs_file *fd );
  57. sint32_t (*flush)( const struct vfs_file *fd );
  58. uint32_t (*size)( const struct vfs_file *fd );
  59. sint32_t (*ferrno)( const struct vfs_file *fd );
  60. };
  61. typedef const struct vfs_file_fns vfs_file_fns;
  62. // generic dir descriptor
  63. struct vfs_dir {
  64. int fs_type;
  65. const struct vfs_dir_fns *fns;
  66. };
  67. typedef const struct vfs_dir vfs_dir;
  68. // dir descriptor functions
  69. struct vfs_dir_fns {
  70. sint32_t (*close)( const struct vfs_dir *dd );
  71. sint32_t (*readdir)( const struct vfs_dir *dd, struct vfs_stat *buf );
  72. };
  73. typedef const struct vfs_dir_fns vfs_dir_fns;
  74. // generic volume descriptor
  75. struct vfs_vol {
  76. int fs_type;
  77. const struct vfs_vol_fns *fns;
  78. };
  79. typedef const struct vfs_vol vfs_vol;
  80. // volume functions
  81. struct vfs_vol_fns {
  82. sint32_t (*umount)( const struct vfs_vol *vol );
  83. };
  84. typedef const struct vfs_vol_fns vfs_vol_fns;
  85. struct vfs_fs_fns {
  86. vfs_vol *(*mount)( const char *name, int num );
  87. vfs_file *(*open)( const char *name, const char *mode );
  88. vfs_dir *(*opendir)( const char *name );
  89. sint32_t (*stat)( const char *name, struct vfs_stat *buf );
  90. sint32_t (*remove)( const char *name );
  91. sint32_t (*rename)( const char *oldname, const char *newname );
  92. sint32_t (*mkdir)( const char *name );
  93. sint32_t (*fsinfo)( uint32_t *total, uint32_t *used );
  94. sint32_t (*fscfg)( uint32_t *phys_addr, uint32_t *phys_size );
  95. sint32_t (*format)( void );
  96. sint32_t (*chdrive)( const char * );
  97. sint32_t (*chdir)( const char * );
  98. sint32_t (*ferrno)( void );
  99. void (*clearerr)( void );
  100. };
  101. typedef const struct vfs_fs_fns vfs_fs_fns;
  102. vfs_fs_fns *myspiffs_realm( const char *inname, char **outname, int set_current_drive );
  103. vfs_fs_fns *myfatfs_realm( const char *inname, char **outname, int set_current_drive );
  104. sint32_t vfs_get_rtc( vfs_time *tm );
  105. #endif