Mass storage revert to expand (max 2G img w/ seek)

This reverts commit 54804fcc66.
This commit is contained in:
Willy-JL
2023-08-29 03:25:45 +02:00
parent 0ec8c85481
commit 034edf50ce
10 changed files with 83 additions and 2 deletions

View File

@@ -62,6 +62,12 @@ 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
@@ -98,6 +104,8 @@ typedef struct {
uint64_t (*size)(void* context, File* file);
bool (*const sync)(void* context, File* file);
bool (*const eof)(void* context, File* file);
bool (*const expand)(void* context, File* file, uint64_t size);
} FS_File_Api;
/** Dir api structure

View File

@@ -117,6 +117,13 @@ 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

View File

@@ -203,6 +203,21 @@ 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;

View File

@@ -32,6 +32,11 @@ typedef struct {
bool from_start;
} SADataFSeek;
typedef struct {
File* file;
uint64_t size;
} SADataFExpand;
typedef struct {
File* file;
const char* path;
@@ -97,6 +102,7 @@ typedef union {
SADataFRead fread;
SADataFWrite fwrite;
SADataFSeek fseek;
SADataFExpand fexpand;
SADataDOpen dopen;
SADataDRead dread;
@@ -149,6 +155,7 @@ typedef enum {
StorageCommandSDStatus,
StorageCommandCommonResolvePath,
StorageCommandFileExpand,
StorageCommandCommonRename,
} StorageCommand;

View File

@@ -206,6 +206,19 @@ 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);
@@ -575,6 +588,10 @@ 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);

View File

@@ -396,6 +396,22 @@ 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);
@@ -609,6 +625,7 @@ 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,

View File

@@ -455,6 +455,14 @@ 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);
@@ -703,6 +711,7 @@ 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,