diff --git a/applications/external/mass_storage/scenes/mass_storage_scene_create_image.c b/applications/external/mass_storage/scenes/mass_storage_scene_create_image.c index 4f3eb0778..1c12ff8a3 100644 --- a/applications/external/mass_storage/scenes/mass_storage_scene_create_image.c +++ b/applications/external/mass_storage/scenes/mass_storage_scene_create_image.c @@ -125,19 +125,33 @@ bool mass_storage_scene_create_image_on_event(void* context, SceneManagerEvent e app->file = storage_file_alloc(app->fs_api); const char* error = NULL; - if(storage_file_open( - app->file, furi_string_get_cstr(app->file_path), FSAM_WRITE, FSOM_CREATE_NEW)) { + bool success = false; + + uint8_t* buffer = malloc(WRITE_BUF_LEN); + do { + if(!storage_file_open( + app->file, + furi_string_get_cstr(app->file_path), + FSAM_WRITE, + FSOM_CREATE_NEW)) + break; + uint64_t size = image_sizes[app->create_image_size].value; - if(size == app->create_image_max) { - size--; - } - if(!storage_file_expand(app->file, size)) { - error = storage_file_get_error_desc(app->file); - storage_file_close(app->file); - storage_common_remove(app->fs_api, furi_string_get_cstr(app->file_path)); - } - } else { + if(size == app->create_image_max) size--; + if(!storage_file_seek(file, size, true)) break; + + // Zero out first 4k - partition table and adjacent data + if(!storage_file_seek(file, 0, true)) break; + if(!storage_file_write(file, buffer, WRITE_BUF_LEN)) break; + + success = true; + } while(false); + free(buffer); + + if(!success) { error = storage_file_get_error_desc(app->file); + storage_file_close(app->file); + storage_common_remove(app->fs_api, furi_string_get_cstr(app->file_path)); } storage_file_free(app->file); mass_storage_app_show_loading_popup(app, false); diff --git a/applications/services/storage/filesystem_api_internal.h b/applications/services/storage/filesystem_api_internal.h index 407b37a71..47214f21a 100644 --- a/applications/services/storage/filesystem_api_internal.h +++ b/applications/services/storage/filesystem_api_internal.h @@ -62,12 +62,6 @@ struct File { * @param file pointer to file object * @return current r/w pointer position * - * @var FS_File_Api::expand - * @brief Expand the file (allocate space for it) - * @param file pointer to file object - * @param size how many bytes to allocate - * @return success flag - * * @var FS_File_Api::truncate * @brief Truncate file size to current r/w pointer position * @param file pointer to file object @@ -100,7 +94,6 @@ typedef struct { uint16_t (*write)(void* context, File* file, const void* buff, uint16_t bytes_to_write); bool (*const seek)(void* context, File* file, uint32_t offset, bool from_start); uint64_t (*tell)(void* context, File* file); - bool (*const expand)(void* context, File* file, uint64_t size); bool (*const truncate)(void* context, File* file); uint64_t (*size)(void* context, File* file); bool (*const sync)(void* context, File* file); diff --git a/applications/services/storage/storage.h b/applications/services/storage/storage.h index 2743255cd..1ee4ab820 100644 --- a/applications/services/storage/storage.h +++ b/applications/services/storage/storage.h @@ -117,13 +117,6 @@ bool storage_file_seek(File* file, uint32_t offset, bool from_start); */ uint64_t storage_file_tell(File* file); -/** Expand the file (allocate space for it) - * @param file pointer to file object. - * @param size how many bytes to allocate - * @return success flag - */ -bool storage_file_expand(File* file, uint64_t size); - /** Truncates the file size to the current position of the r/w pointer * @param file pointer to file object. * @return bool success flag diff --git a/applications/services/storage/storage_external_api.c b/applications/services/storage/storage_external_api.c index a5fc8cd6e..1cfe06a52 100644 --- a/applications/services/storage/storage_external_api.c +++ b/applications/services/storage/storage_external_api.c @@ -203,21 +203,6 @@ uint64_t storage_file_tell(File* file) { return S_RETURN_UINT64; } -bool storage_file_expand(File* file, uint64_t size) { - S_FILE_API_PROLOGUE; - S_API_PROLOGUE; - - SAData data = { - .fexpand = { - .file = file, - .size = size, - }}; - - S_API_MESSAGE(StorageCommandFileExpand); - S_API_EPILOGUE; - return S_RETURN_BOOL; -} - bool storage_file_truncate(File* file) { S_FILE_API_PROLOGUE; S_API_PROLOGUE; diff --git a/applications/services/storage/storage_message.h b/applications/services/storage/storage_message.h index 8f0dc2879..e77bad6ee 100644 --- a/applications/services/storage/storage_message.h +++ b/applications/services/storage/storage_message.h @@ -32,11 +32,6 @@ typedef struct { bool from_start; } SADataFSeek; -typedef struct { - File* file; - uint64_t size; -} SADataFExpand; - typedef struct { File* file; const char* path; @@ -102,7 +97,6 @@ typedef union { SADataFRead fread; SADataFWrite fwrite; SADataFSeek fseek; - SADataFExpand fexpand; SADataDOpen dopen; SADataDRead dread; @@ -136,7 +130,6 @@ typedef enum { StorageCommandFileWrite, StorageCommandFileSeek, StorageCommandFileTell, - StorageCommandFileExpand, StorageCommandFileTruncate, StorageCommandFileSize, StorageCommandFileSync, diff --git a/applications/services/storage/storage_processing.c b/applications/services/storage/storage_processing.c index fef9a9891..87cb6b286 100644 --- a/applications/services/storage/storage_processing.c +++ b/applications/services/storage/storage_processing.c @@ -206,19 +206,6 @@ static uint64_t storage_process_file_tell(Storage* app, File* file) { return ret; } -static bool storage_process_file_expand(Storage* app, File* file, const uint64_t size) { - bool ret = false; - StorageData* storage = get_storage_by_file(file, app->storage); - - if(storage == NULL) { - file->error_id = FSE_INVALID_PARAMETER; - } else { - FS_CALL(storage, file.expand(storage, file, size)); - } - - return ret; -} - static bool storage_process_file_truncate(Storage* app, File* file) { bool ret = false; StorageData* storage = get_storage_by_file(file, app->storage); @@ -588,10 +575,6 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) { message->return_data->uint64_value = storage_process_file_tell(app, message->data->file.file); break; - case StorageCommandFileExpand: - message->return_data->bool_value = storage_process_file_expand( - app, message->data->fexpand.file, message->data->fexpand.size); - break; case StorageCommandFileTruncate: message->return_data->bool_value = storage_process_file_truncate(app, message->data->file.file); diff --git a/applications/services/storage/storages/storage_ext.c b/applications/services/storage/storages/storage_ext.c index 7592b82fe..ca77b6843 100644 --- a/applications/services/storage/storages/storage_ext.c +++ b/applications/services/storage/storages/storage_ext.c @@ -396,22 +396,6 @@ static uint64_t storage_ext_file_tell(void* ctx, File* file) { return position; } -static bool storage_ext_file_expand(void* ctx, File* file, const uint64_t size) { -#ifdef FURI_RAM_EXEC - UNUSED(ctx); - UNUSED(file); - UNUSED(size); - file->error_id = FSE_NOT_READY; -#else - StorageData* storage = ctx; - SDFile* file_data = storage_get_storage_file_data(file, storage); - - file->internal_error_id = f_expand(file_data, size, 1); - file->error_id = storage_ext_parse_error(file->internal_error_id); -#endif - return (file->error_id == FSE_OK); -} - static bool storage_ext_file_truncate(void* ctx, File* file) { #ifdef FURI_RAM_EXEC UNUSED(ctx); @@ -625,7 +609,6 @@ static const FS_Api fs_api = { .write = storage_ext_file_write, .seek = storage_ext_file_seek, .tell = storage_ext_file_tell, - .expand = storage_ext_file_expand, .truncate = storage_ext_file_truncate, .size = storage_ext_file_size, .sync = storage_ext_file_sync, diff --git a/applications/services/storage/storages/storage_int.c b/applications/services/storage/storages/storage_int.c index 765bb8e93..50e3a7899 100644 --- a/applications/services/storage/storages/storage_int.c +++ b/applications/services/storage/storages/storage_int.c @@ -455,14 +455,6 @@ static uint64_t storage_int_file_tell(void* ctx, File* file) { return position; } -static bool storage_int_file_expand(void* ctx, File* file, const uint64_t size) { - UNUSED(ctx); - UNUSED(file); - UNUSED(size); - file->error_id = FSE_NOT_IMPLEMENTED; - return (file->error_id == FSE_OK); -} - static bool storage_int_file_truncate(void* ctx, File* file) { StorageData* storage = ctx; lfs_t* lfs = lfs_get_from_storage(storage); @@ -711,7 +703,6 @@ static const FS_Api fs_api = { .write = storage_int_file_write, .seek = storage_int_file_seek, .tell = storage_int_file_tell, - .expand = storage_int_file_expand, .truncate = storage_int_file_truncate, .size = storage_int_file_size, .sync = storage_int_file_sync, diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 6b33a3998..2e503f7e3 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -2695,7 +2695,6 @@ Function,+,storage_file_close,_Bool,File* Function,+,storage_file_copy_to_file,_Bool,"File*, File*, uint32_t" Function,+,storage_file_eof,_Bool,File* Function,+,storage_file_exists,_Bool,"Storage*, const char*" -Function,+,storage_file_expand,_Bool,"File*, uint64_t" Function,+,storage_file_free,void,File* Function,+,storage_file_get_error,FS_Error,File* Function,+,storage_file_get_error_desc,const char*,File* diff --git a/firmware/targets/f7/fatfs/ffconf.h b/firmware/targets/f7/fatfs/ffconf.h index 3d9462fc5..8408a1ec1 100644 --- a/firmware/targets/f7/fatfs/ffconf.h +++ b/firmware/targets/f7/fatfs/ffconf.h @@ -68,7 +68,7 @@ #define _USE_FASTSEEK 1 /* This option switches fast seek feature. (0:Disable or 1:Enable) */ -#define _USE_EXPAND 1 +#define _USE_EXPAND 0 /* This option switches f_expand function. (0:Disable or 1:Enable) */ #define _USE_CHMOD 0