mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 12:42:30 +04:00
[FL-3664] 64k does not enough (#3216)
* Unit tests: add "exists" to furi_record tests * Unit tests: mu_warn, storage 64k test * Storage: read/write over 64k * Unit tests: moar tests for storage r/w for >64k cases * Apps, libs: replace uint16_t with size_t on storage r/w operations * Unit tests: better data pattern, subghz: warning if transmission is prohibited Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -139,7 +139,7 @@ bool storage_file_close(File* file) {
|
||||
return S_RETURN_BOOL;
|
||||
}
|
||||
|
||||
uint16_t storage_file_read(File* file, void* buff, uint16_t bytes_to_read) {
|
||||
static uint16_t storage_file_read_underlying(File* file, void* buff, uint16_t bytes_to_read) {
|
||||
if(bytes_to_read == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -159,7 +159,8 @@ uint16_t storage_file_read(File* file, void* buff, uint16_t bytes_to_read) {
|
||||
return S_RETURN_UINT16;
|
||||
}
|
||||
|
||||
uint16_t storage_file_write(File* file, const void* buff, uint16_t bytes_to_write) {
|
||||
static uint16_t
|
||||
storage_file_write_underlying(File* file, const void* buff, uint16_t bytes_to_write) {
|
||||
if(bytes_to_write == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -179,6 +180,40 @@ uint16_t storage_file_write(File* file, const void* buff, uint16_t bytes_to_writ
|
||||
return S_RETURN_UINT16;
|
||||
}
|
||||
|
||||
size_t storage_file_read(File* file, void* buff, size_t to_read) {
|
||||
size_t total = 0;
|
||||
|
||||
const size_t max_chunk = UINT16_MAX;
|
||||
do {
|
||||
const size_t chunk = MIN((to_read - total), max_chunk);
|
||||
size_t read = storage_file_read_underlying(file, buff + total, chunk);
|
||||
total += read;
|
||||
|
||||
if(storage_file_get_error(file) != FSE_OK || read != chunk) {
|
||||
break;
|
||||
}
|
||||
} while(total != to_read);
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
size_t storage_file_write(File* file, const void* buff, size_t to_write) {
|
||||
size_t total = 0;
|
||||
|
||||
const size_t max_chunk = UINT16_MAX;
|
||||
do {
|
||||
const size_t chunk = MIN((to_write - total), max_chunk);
|
||||
size_t written = storage_file_write_underlying(file, buff + total, chunk);
|
||||
total += written;
|
||||
|
||||
if(storage_file_get_error(file) != FSE_OK || written != chunk) {
|
||||
break;
|
||||
}
|
||||
} while(total != to_write);
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
bool storage_file_seek(File* file, uint32_t offset, bool from_start) {
|
||||
S_FILE_API_PROLOGUE;
|
||||
S_API_PROLOGUE;
|
||||
@@ -252,7 +287,7 @@ bool storage_file_exists(Storage* storage, const char* path) {
|
||||
return exist;
|
||||
}
|
||||
|
||||
bool storage_file_copy_to_file(File* source, File* destination, uint32_t size) {
|
||||
bool storage_file_copy_to_file(File* source, File* destination, size_t size) {
|
||||
uint8_t* buffer = malloc(FILE_BUFFER_SIZE);
|
||||
|
||||
while(size) {
|
||||
|
||||
Reference in New Issue
Block a user