From 29c3813f683649f3ec7692e03bc7b94587da6e59 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sat, 6 Apr 2024 23:16:29 +0100 Subject: [PATCH] Improve error handling, use correct drive id --- applications/services/storage/storage_glue.c | 2 +- .../services/storage/storages/storage_ext.c | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/applications/services/storage/storage_glue.c b/applications/services/storage/storage_glue.c index 63bb017fd..727af765f 100644 --- a/applications/services/storage/storage_glue.c +++ b/applications/services/storage/storage_glue.c @@ -158,7 +158,7 @@ size_t storage_open_files_count(StorageData* storage) { } const char* storage_file_get_path(File* file, StorageData* storage) { - if(!storage_has_file(file, storage)) return ""; StorageFile* storage_file_ref = storage_get_file(file, storage); + if(!storage_file_ref) return ""; return furi_string_get_cstr(storage_file_ref->path); } \ No newline at end of file diff --git a/applications/services/storage/storages/storage_ext.c b/applications/services/storage/storages/storage_ext.c index f219005a8..fb61f8086 100644 --- a/applications/services/storage/storages/storage_ext.c +++ b/applications/services/storage/storages/storage_ext.c @@ -5,6 +5,7 @@ #include #include "sd_notify.h" #include +#include typedef FIL SDFile; typedef DIR SDDir; @@ -740,15 +741,22 @@ FS_Error storage_process_virtual_format(StorageData* storage) { SDData* sd_data = storage->data; uint8_t* work = malloc(_MAX_SS); SDError error = f_mkfs(sd_data->path, FM_ANY, 0, work, _MAX_SS); - storage_process_virtual_mount(storage); - const char* path = storage_file_get_path(mnt_image, mnt_image_storage); - const char* name = basename(path); - char label[strlen(name) - 3]; - strlcpy(label, name, sizeof(label)); - f_setlabel(label); - storage_process_virtual_unmount(storage); free(work); if(error != FR_OK) return FSE_INTERNAL; + + if(storage_process_virtual_mount(storage) == FSE_OK) { + // Image file path + const char* img_path = storage_file_get_path(mnt_image, mnt_image_storage); + // Image file name + FuriString* img_name = furi_string_alloc(); + path_extract_filename_no_ext(img_path, img_name); + // Label with drive id prefix + char* label = storage_ext_drive_path(storage, furi_string_get_cstr(img_name)); + furi_string_free(img_name); + f_setlabel(label); + free(label); + storage_process_virtual_unmount(storage); + } return FSE_OK; #endif }