SD Driver: reinit sd card on error (#2493)
* SD Driver: reinit sd card on error * SD Driver: cleanup fatfs bindings * Storage: optimized glue * Storage: move fatfs initialization to appropriate subsystems, minor code cleanup * SD Driver: minor code cleanup Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -73,29 +73,34 @@ uint32_t storage_data_get_timestamp(StorageData* storage) {
|
||||
|
||||
/****************** storage glue ******************/
|
||||
|
||||
bool storage_has_file(const File* file, StorageData* storage_data) {
|
||||
bool result = false;
|
||||
static StorageFile* storage_get_file(const File* file, StorageData* storage) {
|
||||
StorageFile* storage_file_ref = NULL;
|
||||
|
||||
StorageFileList_it_t it;
|
||||
for(StorageFileList_it(it, storage_data->files); !StorageFileList_end_p(it);
|
||||
for(StorageFileList_it(it, storage->files); !StorageFileList_end_p(it);
|
||||
StorageFileList_next(it)) {
|
||||
const StorageFile* storage_file = StorageFileList_cref(it);
|
||||
StorageFile* storage_file = StorageFileList_ref(it);
|
||||
|
||||
if(storage_file->file->file_id == file->file_id) {
|
||||
result = true;
|
||||
storage_file_ref = storage_file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return storage_file_ref;
|
||||
}
|
||||
|
||||
bool storage_path_already_open(FuriString* path, StorageFileList_t array) {
|
||||
bool storage_has_file(const File* file, StorageData* storage) {
|
||||
return storage_get_file(file, storage) != NULL;
|
||||
}
|
||||
|
||||
bool storage_path_already_open(FuriString* path, StorageData* storage) {
|
||||
bool open = false;
|
||||
|
||||
StorageFileList_it_t it;
|
||||
|
||||
for(StorageFileList_it(it, array); !StorageFileList_end_p(it); StorageFileList_next(it)) {
|
||||
for(StorageFileList_it(it, storage->files); !StorageFileList_end_p(it);
|
||||
StorageFileList_next(it)) {
|
||||
const StorageFile* storage_file = StorageFileList_cref(it);
|
||||
|
||||
if(furi_string_cmp(storage_file->path, path) == 0) {
|
||||
@@ -108,43 +113,15 @@ bool storage_path_already_open(FuriString* path, StorageFileList_t array) {
|
||||
}
|
||||
|
||||
void storage_set_storage_file_data(const File* file, void* file_data, StorageData* storage) {
|
||||
StorageFile* founded_file = NULL;
|
||||
|
||||
StorageFileList_it_t it;
|
||||
|
||||
for(StorageFileList_it(it, storage->files); !StorageFileList_end_p(it);
|
||||
StorageFileList_next(it)) {
|
||||
StorageFile* storage_file = StorageFileList_ref(it);
|
||||
|
||||
if(storage_file->file->file_id == file->file_id) {
|
||||
founded_file = storage_file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
furi_check(founded_file != NULL);
|
||||
|
||||
founded_file->file_data = file_data;
|
||||
StorageFile* storage_file_ref = storage_get_file(file, storage);
|
||||
furi_check(storage_file_ref != NULL);
|
||||
storage_file_ref->file_data = file_data;
|
||||
}
|
||||
|
||||
void* storage_get_storage_file_data(const File* file, StorageData* storage) {
|
||||
const StorageFile* founded_file = NULL;
|
||||
|
||||
StorageFileList_it_t it;
|
||||
|
||||
for(StorageFileList_it(it, storage->files); !StorageFileList_end_p(it);
|
||||
StorageFileList_next(it)) {
|
||||
const StorageFile* storage_file = StorageFileList_cref(it);
|
||||
|
||||
if(storage_file->file->file_id == file->file_id) {
|
||||
founded_file = storage_file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
furi_check(founded_file != NULL);
|
||||
|
||||
return founded_file->file_data;
|
||||
StorageFile* storage_file_ref = storage_get_file(file, storage);
|
||||
furi_check(storage_file_ref != NULL);
|
||||
return storage_file_ref->file_data;
|
||||
}
|
||||
|
||||
void storage_push_storage_file(File* file, FuriString* path, StorageData* storage) {
|
||||
|
@@ -60,7 +60,7 @@ struct StorageData {
|
||||
};
|
||||
|
||||
bool storage_has_file(const File* file, StorageData* storage_data);
|
||||
bool storage_path_already_open(FuriString* path, StorageFileList_t files);
|
||||
bool storage_path_already_open(FuriString* path, StorageData* storage_data);
|
||||
|
||||
void storage_set_storage_file_data(const File* file, void* file_data, StorageData* storage);
|
||||
void* storage_get_storage_file_data(const File* file, StorageData* storage);
|
||||
|
@@ -77,7 +77,7 @@ static void storage_path_change_to_real_storage(FuriString* path, StorageType re
|
||||
}
|
||||
}
|
||||
|
||||
FS_Error storage_get_data(Storage* app, FuriString* path, StorageData** storage) {
|
||||
static FS_Error storage_get_data(Storage* app, FuriString* path, StorageData** storage) {
|
||||
StorageType type = storage_get_type_by_path(path);
|
||||
|
||||
if(storage_type_is_valid(type)) {
|
||||
@@ -111,7 +111,7 @@ bool storage_process_file_open(
|
||||
file->error_id = storage_get_data(app, path, &storage);
|
||||
|
||||
if(file->error_id == FSE_OK) {
|
||||
if(storage_path_already_open(path, storage->files)) {
|
||||
if(storage_path_already_open(path, storage)) {
|
||||
file->error_id = FSE_ALREADY_OPEN;
|
||||
} else {
|
||||
if(access_mode & FSAM_WRITE) {
|
||||
@@ -268,7 +268,7 @@ bool storage_process_dir_open(Storage* app, File* file, FuriString* path) {
|
||||
file->error_id = storage_get_data(app, path, &storage);
|
||||
|
||||
if(file->error_id == FSE_OK) {
|
||||
if(storage_path_already_open(path, storage->files)) {
|
||||
if(storage_path_already_open(path, storage)) {
|
||||
file->error_id = FSE_ALREADY_OPEN;
|
||||
} else {
|
||||
storage_push_storage_file(file, path, storage);
|
||||
@@ -357,7 +357,7 @@ static FS_Error storage_process_common_remove(Storage* app, FuriString* path) {
|
||||
FS_Error ret = storage_get_data(app, path, &storage);
|
||||
|
||||
do {
|
||||
if(storage_path_already_open(path, storage->files)) {
|
||||
if(storage_path_already_open(path, storage)) {
|
||||
ret = FSE_ALREADY_OPEN;
|
||||
break;
|
||||
}
|
||||
|
@@ -618,8 +618,10 @@ static const FS_Api fs_api = {
|
||||
};
|
||||
|
||||
void storage_ext_init(StorageData* storage) {
|
||||
fatfs_init();
|
||||
|
||||
SDData* sd_data = malloc(sizeof(SDData));
|
||||
sd_data->fs = &USERFatFS;
|
||||
sd_data->fs = &fatfs_object;
|
||||
sd_data->path = "0:/";
|
||||
sd_data->sd_was_present = true;
|
||||
|
||||
|
Reference in New Issue
Block a user