filesystem_api_internal.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #pragma once
  2. #include <furi.h>
  3. #include "filesystem_api_defines.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /** Structure that hold file index and returned api errors */
  8. struct File {
  9. uint32_t file_id; /**< File ID for internal references */
  10. FS_Error error_id; /**< Standart API error from FS_Error enum */
  11. int32_t internal_error_id; /**< Internal API error value */
  12. void* storage;
  13. };
  14. /** File api structure
  15. * @var FS_File_Api::open
  16. * @brief Open file
  17. * @param file pointer to file object, filled by api
  18. * @param path path to file
  19. * @param access_mode access mode from FS_AccessMode
  20. * @param open_mode open mode from FS_OpenMode
  21. * @return success flag
  22. *
  23. * @var FS_File_Api::close
  24. * @brief Close file
  25. * @param file pointer to file object
  26. * @return success flag
  27. *
  28. * @var FS_File_Api::read
  29. * @brief Read bytes from file to buffer
  30. * @param file pointer to file object
  31. * @param buff pointer to buffer for reading
  32. * @param bytes_to_read how many bytes to read, must be smaller or equal to buffer size
  33. * @return how many bytes actually has been read
  34. *
  35. * @var FS_File_Api::write
  36. * @brief Write bytes from buffer to file
  37. * @param file pointer to file object
  38. * @param buff pointer to buffer for writing
  39. * @param bytes_to_read how many bytes to write, must be smaller or equal to buffer size
  40. * @return how many bytes actually has been written
  41. *
  42. * @var FS_File_Api::seek
  43. * @brief Move r/w pointer
  44. * @param file pointer to file object
  45. * @param offset offset to move r/w pointer
  46. * @param from_start set offset from start, or from current position
  47. * @return success flag
  48. *
  49. * @var FS_File_Api::tell
  50. * @brief Get r/w pointer position
  51. * @param file pointer to file object
  52. * @return current r/w pointer position
  53. *
  54. * @var FS_File_Api::truncate
  55. * @brief Truncate file size to current r/w pointer position
  56. * @param file pointer to file object
  57. * @return success flag
  58. *
  59. * @var FS_File_Api::size
  60. * @brief Fet file size
  61. * @param file pointer to file object
  62. * @return file size
  63. *
  64. * @var FS_File_Api::sync
  65. * @brief Write file cache to storage
  66. * @param file pointer to file object
  67. * @return success flag
  68. *
  69. * @var FS_File_Api::eof
  70. * @brief Checks that the r/w pointer is at the end of the file
  71. * @param file pointer to file object
  72. * @return end of file flag
  73. */
  74. typedef struct {
  75. bool (*const open)(
  76. void* context,
  77. File* file,
  78. const char* path,
  79. FS_AccessMode access_mode,
  80. FS_OpenMode open_mode);
  81. bool (*const close)(void* context, File* file);
  82. uint16_t (*read)(void* context, File* file, void* buff, uint16_t bytes_to_read);
  83. uint16_t (*write)(void* context, File* file, const void* buff, uint16_t bytes_to_write);
  84. bool (*const seek)(void* context, File* file, uint32_t offset, bool from_start);
  85. uint64_t (*tell)(void* context, File* file);
  86. bool (*const truncate)(void* context, File* file);
  87. uint64_t (*size)(void* context, File* file);
  88. bool (*const sync)(void* context, File* file);
  89. bool (*const eof)(void* context, File* file);
  90. } FS_File_Api;
  91. /** Dir api structure
  92. * @var FS_Dir_Api::open
  93. * @brief Open directory to get objects from
  94. * @param file pointer to file object, filled by api
  95. * @param path path to directory
  96. * @return success flag
  97. *
  98. * @var FS_Dir_Api::close
  99. * @brief Close directory
  100. * @param file pointer to file object
  101. * @return success flag
  102. *
  103. * @var FS_Dir_Api::read
  104. * @brief Read next object info in directory
  105. * @param file pointer to file object
  106. * @param fileinfo pointer to read FileInfo, can be NULL
  107. * @param name pointer to name buffer, can be NULL
  108. * @param name_length name buffer length
  109. * @return success flag (if next object not exist also returns false and set error_id to FSE_NOT_EXIST)
  110. *
  111. * @var FS_Dir_Api::rewind
  112. * @brief Rewind to first object info in directory
  113. * @param file pointer to file object
  114. * @return success flag
  115. */
  116. typedef struct {
  117. bool (*const open)(void* context, File* file, const char* path);
  118. bool (*const close)(void* context, File* file);
  119. bool (*const read)(
  120. void* context,
  121. File* file,
  122. FileInfo* fileinfo,
  123. char* name,
  124. uint16_t name_length);
  125. bool (*const rewind)(void* context, File* file);
  126. } FS_Dir_Api;
  127. /** Common api structure
  128. * @var FS_Common_Api::stat
  129. * @brief Open directory to get objects from
  130. * @param path path to file/directory
  131. * @param fileinfo pointer to read FileInfo, can be NULL
  132. * @param name pointer to name buffer, can be NULL
  133. * @param name_length name buffer length
  134. * @return FS_Error error info
  135. *
  136. * @var FS_Common_Api::remove
  137. * @brief Remove file/directory from storage,
  138. * directory must be empty,
  139. * file/directory must not be opened,
  140. * file/directory must not have FSF_READ_ONLY flag
  141. * @param path path to file/directory
  142. * @return FS_Error error info
  143. *
  144. * @var FS_Common_Api::mkdir
  145. * @brief Create new directory
  146. * @param path path to new directory
  147. * @return FS_Error error info
  148. *
  149. * @var FS_Common_Api::fs_info
  150. * @brief Get total and free space storage values
  151. * @param fs_path path of fs
  152. * @param total_space pointer to total space value
  153. * @param free_space pointer to free space value
  154. * @return FS_Error error info
  155. */
  156. typedef struct {
  157. FS_Error (*const stat)(void* context, const char* path, FileInfo* fileinfo);
  158. FS_Error (*const remove)(void* context, const char* path);
  159. FS_Error (*const mkdir)(void* context, const char* path);
  160. FS_Error (*const fs_info)(
  161. void* context,
  162. const char* fs_path,
  163. uint64_t* total_space,
  164. uint64_t* free_space);
  165. } FS_Common_Api;
  166. /** Full filesystem api structure */
  167. typedef struct {
  168. const FS_File_Api file;
  169. const FS_Dir_Api dir;
  170. const FS_Common_Api common;
  171. } FS_Api;
  172. #ifdef __cplusplus
  173. }
  174. #endif