[FL-1191][FL-1524] Filesystem rework (#568)

* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
SG
2021-07-23 22:20:19 +10:00
committed by GitHub
parent a81203941b
commit ad421a81bc
95 changed files with 6451 additions and 4349 deletions

View File

@@ -2,13 +2,14 @@
#include <gui/elements.h>
#include <m-string.h>
#include <sys/param.h>
#include <storage/storage.h>
#define FILENAME_COUNT 4
struct FileSelect {
// public
View* view;
FS_Api* fs_api;
Storage* fs_api;
const char* path;
const char* extension;
@@ -180,6 +181,8 @@ static bool file_select_init_inner(FileSelect* file_select) {
FileSelect* file_select_alloc() {
FileSelect* file_select = furi_alloc(sizeof(FileSelect));
file_select->view = view_alloc();
file_select->fs_api = furi_record_open("storage");
view_set_context(file_select->view, file_select);
view_allocate_model(file_select->view, ViewModelTypeLockFree, sizeof(FileSelectModel));
view_set_draw_callback(file_select->view, file_select_draw_callback);
@@ -210,6 +213,7 @@ void file_select_free(FileSelect* file_select) {
});
view_free(file_select->view);
free(file_select);
furi_record_close("storage");
}
View* file_select_get_view(FileSelect* file_select) {
@@ -217,11 +221,6 @@ View* file_select_get_view(FileSelect* file_select) {
return file_select->view;
}
void file_select_set_api(FileSelect* file_select, FS_Api* fs_api) {
furi_assert(file_select);
file_select->fs_api = fs_api;
}
void file_select_set_callback(FileSelect* file_select, FileSelectCallback callback, void* context) {
file_select->context = context;
file_select->callback = callback;
@@ -272,13 +271,12 @@ bool file_select_fill_strings(FileSelect* file_select) {
furi_assert(file_select->extension);
FileInfo file_info;
File directory;
bool result;
FS_Dir_Api* dir_api = &file_select->fs_api->dir;
File* directory = storage_file_alloc(file_select->fs_api);
uint8_t string_counter = 0;
uint16_t file_counter = 0;
const uint8_t name_length = 100;
char* name = calloc(name_length, sizeof(char));
char* name = furi_alloc(name_length);
uint16_t first_file_index = 0;
with_view_model(
@@ -287,59 +285,50 @@ bool file_select_fill_strings(FileSelect* file_select) {
return false;
});
if(name == NULL) {
return false;
}
result = dir_api->open(&directory, file_select->path);
if(!result) {
dir_api->close(&directory);
if(!storage_dir_open(directory, file_select->path)) {
storage_dir_close(directory);
storage_file_free(directory);
free(name);
return false;
}
while(1) {
result = dir_api->read(&directory, &file_info, name, name_length);
if(directory.error_id == FSE_NOT_EXIST || name[0] == 0) {
if(!storage_dir_read(directory, &file_info, name, name_length)) {
break;
}
if(result) {
if(directory.error_id == FSE_OK) {
if(filter_file(file_select, &file_info, name)) {
if(file_counter >= first_file_index) {
with_view_model(
file_select->view, (FileSelectModel * model) {
string_set_str(model->filename[string_counter], name);
if(storage_file_get_error(directory) == FSE_OK) {
if(filter_file(file_select, &file_info, name)) {
if(file_counter >= first_file_index) {
with_view_model(
file_select->view, (FileSelectModel * model) {
string_set_str(model->filename[string_counter], name);
if(strcmp(file_select->extension, "*") != 0) {
string_replace_all_str(
model->filename[string_counter],
file_select->extension,
"");
}
if(strcmp(file_select->extension, "*") != 0) {
string_replace_all_str(
model->filename[string_counter], file_select->extension, "");
}
return true;
});
string_counter++;
return true;
});
string_counter++;
if(string_counter >= FILENAME_COUNT) {
break;
}
if(string_counter >= FILENAME_COUNT) {
break;
}
file_counter++;
}
} else {
dir_api->close(&directory);
free(name);
return false;
file_counter++;
}
} else {
storage_dir_close(directory);
storage_file_free(directory);
free(name);
return false;
}
}
dir_api->close(&directory);
storage_dir_close(directory);
storage_file_free(directory);
free(name);
return true;
}
@@ -351,42 +340,33 @@ bool file_select_fill_count(FileSelect* file_select) {
furi_assert(file_select->extension);
FileInfo file_info;
File directory;
bool result;
FS_Dir_Api* dir_api = &file_select->fs_api->dir;
File* directory = storage_file_alloc(file_select->fs_api);
uint16_t file_counter = 0;
const uint8_t name_length = 100;
char* name = calloc(name_length, sizeof(char));
char* name = furi_alloc(name_length);
if(name == NULL) {
return false;
}
result = dir_api->open(&directory, file_select->path);
if(!result) {
dir_api->close(&directory);
if(!storage_dir_open(directory, file_select->path)) {
storage_dir_close(directory);
storage_file_free(directory);
free(name);
return false;
}
while(1) {
result = dir_api->read(&directory, &file_info, name, name_length);
if(directory.error_id == FSE_NOT_EXIST || name[0] == 0) {
if(!storage_dir_read(directory, &file_info, name, name_length)) {
break;
}
if(result) {
if(directory.error_id == FSE_OK) {
if(filter_file(file_select, &file_info, name)) {
file_counter++;
}
} else {
dir_api->close(&directory);
free(name);
return false;
if(storage_file_get_error(directory) == FSE_OK) {
if(filter_file(file_select, &file_info, name)) {
file_counter++;
}
} else {
storage_dir_close(directory);
storage_file_free(directory);
free(name);
return false;
}
}
@@ -396,7 +376,8 @@ bool file_select_fill_count(FileSelect* file_select) {
return false;
});
dir_api->close(&directory);
storage_dir_close(directory);
storage_file_free(directory);
free(name);
return true;
}
@@ -411,16 +392,10 @@ void file_select_set_selected_file_internal(FileSelect* file_select, const char*
if(strlen(filename) == 0) return;
FileInfo file_info;
File directory;
bool result;
FS_Dir_Api* dir_api = &file_select->fs_api->dir;
File* directory = storage_file_alloc(file_select->fs_api);
const uint8_t name_length = 100;
char* name = calloc(name_length, sizeof(char));
if(name == NULL) {
return;
}
char* name = furi_alloc(name_length);
uint16_t file_position = 0;
bool file_found = false;
@@ -430,38 +405,34 @@ void file_select_set_selected_file_internal(FileSelect* file_select, const char*
string_cat_str(filename_str, file_select->extension);
}
result = dir_api->open(&directory, file_select->path);
if(!result) {
if(!storage_dir_open(directory, file_select->path)) {
string_clear(filename_str);
dir_api->close(&directory);
storage_dir_close(directory);
storage_file_free(directory);
free(name);
return;
}
while(1) {
result = dir_api->read(&directory, &file_info, name, name_length);
if(directory.error_id == FSE_NOT_EXIST || name[0] == 0) {
if(!storage_dir_read(directory, &file_info, name, name_length)) {
break;
}
if(result) {
if(directory.error_id == FSE_OK) {
if(filter_file(file_select, &file_info, name)) {
if(strcmp(string_get_cstr(filename_str), name) == 0) {
file_found = true;
break;
}
file_position++;
if(storage_file_get_error(directory) == FSE_OK) {
if(filter_file(file_select, &file_info, name)) {
if(strcmp(string_get_cstr(filename_str), name) == 0) {
file_found = true;
break;
}
} else {
string_clear(filename_str);
dir_api->close(&directory);
free(name);
return;
file_position++;
}
} else {
string_clear(filename_str);
storage_dir_close(directory);
storage_file_free(directory);
free(name);
return;
}
}
@@ -488,7 +459,8 @@ void file_select_set_selected_file_internal(FileSelect* file_select, const char*
}
string_clear(filename_str);
dir_api->close(&directory);
storage_dir_close(directory);
storage_file_free(directory);
free(name);
}

View File

@@ -1,6 +1,5 @@
#pragma once
#include <gui/view.h>
#include <filesystem-api.h>
#ifdef __cplusplus
extern "C" {
@@ -15,7 +14,6 @@ FileSelect* file_select_alloc();
void file_select_free(FileSelect* file_select);
View* file_select_get_view(FileSelect* file_select);
void file_select_set_api(FileSelect* file_select, FS_Api* fs_api);
void file_select_set_callback(FileSelect* file_select, FileSelectCallback callback, void* context);
void file_select_set_filter(FileSelect* file_select, const char* path, const char* extension);
void file_select_set_result_buffer(FileSelect* file_select, char* buffer, uint8_t buffer_size);