[FL-2415] Storage: blocking file open (#1078)

* Storage: correct replacement for "/any" path in path holder
* Unit tests: storage, blocking file open test
* File stream: error getter
* Storage: common copy and common remove now executes in external thread
* Filesystems: got rid of unused functions
* Storage: untangle dependencies, ram-frendly filesystem api
* iButton: context assertions
* Storage: pubsub messages
* Storage: wait for the file to close if it was open
* Storage: fix folder copying
* Storage: unit test
* Storage: pubsub documentation
* Fix merge error
* Fix memleak in storage test
* Storage: remove unused define

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
SG
2022-04-01 22:21:31 +10:00
committed by GitHub
parent cb7d43f7e1
commit 855f2584ab
37 changed files with 443 additions and 281 deletions

View File

@@ -75,21 +75,21 @@ struct File {
* @return end of file flag
*/
typedef struct {
bool (*open)(
bool (*const open)(
void* context,
File* file,
const char* path,
FS_AccessMode access_mode,
FS_OpenMode open_mode);
bool (*close)(void* context, File* file);
bool (*const close)(void* context, File* file);
uint16_t (*read)(void* context, File* file, void* buff, uint16_t bytes_to_read);
uint16_t (*write)(void* context, File* file, const void* buff, uint16_t bytes_to_write);
bool (*seek)(void* context, File* file, uint32_t offset, bool from_start);
bool (*const seek)(void* context, File* file, uint32_t offset, bool from_start);
uint64_t (*tell)(void* context, File* file);
bool (*truncate)(void* context, File* file);
bool (*const truncate)(void* context, File* file);
uint64_t (*size)(void* context, File* file);
bool (*sync)(void* context, File* file);
bool (*eof)(void* context, File* file);
bool (*const sync)(void* context, File* file);
bool (*const eof)(void* context, File* file);
} FS_File_Api;
/** Dir api structure
@@ -118,10 +118,15 @@ typedef struct {
* @return success flag
*/
typedef struct {
bool (*open)(void* context, File* file, const char* path);
bool (*close)(void* context, File* file);
bool (*read)(void* context, File* file, FileInfo* fileinfo, char* name, uint16_t name_length);
bool (*rewind)(void* context, File* file);
bool (*const open)(void* context, File* file, const char* path);
bool (*const close)(void* context, File* file);
bool (*const read)(
void* context,
File* file,
FileInfo* fileinfo,
char* name,
uint16_t name_length);
bool (*const rewind)(void* context, File* file);
} FS_Dir_Api;
/** Common api structure
@@ -141,12 +146,6 @@ typedef struct {
* @param path path to file/directory
* @return FS_Error error info
*
* @var FS_Common_Api::rename
* @brief Rename file/directory,
* file/directory must not be opened
* @param path path to file/directory
* @return FS_Error error info
*
* @var FS_Common_Api::mkdir
* @brief Create new directory
* @param path path to new directory
@@ -160,31 +159,21 @@ typedef struct {
* @return FS_Error error info
*/
typedef struct {
FS_Error (*stat)(void* context, const char* path, FileInfo* fileinfo);
FS_Error (*remove)(void* context, const char* path);
FS_Error (*rename)(void* context, const char* old_path, const char* new_path);
FS_Error (*mkdir)(void* context, const char* path);
FS_Error (
*fs_info)(void* context, const char* fs_path, uint64_t* total_space, uint64_t* free_space);
FS_Error (*const stat)(void* context, const char* path, FileInfo* fileinfo);
FS_Error (*const remove)(void* context, const char* path);
FS_Error (*const mkdir)(void* context, const char* path);
FS_Error (*const fs_info)(
void* context,
const char* fs_path,
uint64_t* total_space,
uint64_t* free_space);
} FS_Common_Api;
/** Errors api structure
* @var FS_Error_Api::get_desc
* @brief Get error description text
* @param error_id FS_Error error id (for fire/dir functions result can be obtained from File.error_id)
* @return pointer to description text
*/
typedef struct {
const char* (*get_desc)(void* context, FS_Error error_id);
} FS_Error_Api;
/** Full filesystem api structure */
typedef struct {
FS_File_Api file;
FS_Dir_Api dir;
FS_Common_Api common;
FS_Error_Api error;
void* context;
const FS_File_Api file;
const FS_Dir_Api dir;
const FS_Common_Api common;
} FS_Api;
#ifdef __cplusplus