vfs_int.h 3.0 KB

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