2022-07-20 13:56:33 +03:00
|
|
|
#include <core/log.h>
|
|
|
|
#include <core/record.h>
|
2021-10-26 19:05:28 +03:00
|
|
|
#include <m-string.h>
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
#include "storage.h"
|
2022-01-05 19:10:18 +03:00
|
|
|
#include "storage_i.h"
|
|
|
|
#include "storage_message.h"
|
2022-04-01 15:21:31 +03:00
|
|
|
#include <toolbox/stream/file_stream.h>
|
2022-05-10 17:05:36 +03:00
|
|
|
#include <toolbox/dir_walk.h>
|
2022-07-14 19:44:34 +03:00
|
|
|
#include "toolbox/path.h"
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
|
2021-10-26 19:05:28 +03:00
|
|
|
#define MAX_NAME_LENGTH 256
|
2022-07-14 19:44:34 +03:00
|
|
|
#define MAX_EXT_LEN 16
|
2021-10-26 19:05:28 +03:00
|
|
|
|
2022-04-27 19:16:06 +03:00
|
|
|
#define TAG "StorageAPI"
|
|
|
|
|
2022-07-20 13:56:33 +03:00
|
|
|
#define S_API_PROLOGUE \
|
|
|
|
FuriSemaphore* semaphore = furi_semaphore_alloc(1, 0); \
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
furi_check(semaphore != NULL);
|
|
|
|
|
|
|
|
#define S_FILE_API_PROLOGUE \
|
|
|
|
Storage* storage = file->storage; \
|
|
|
|
furi_assert(storage);
|
|
|
|
|
2022-07-20 13:56:33 +03:00
|
|
|
#define S_API_EPILOGUE \
|
|
|
|
furi_check( \
|
|
|
|
furi_message_queue_put(storage->message_queue, &message, FuriWaitForever) == \
|
|
|
|
FuriStatusOk); \
|
|
|
|
furi_semaphore_acquire(semaphore, FuriWaitForever); \
|
|
|
|
furi_semaphore_free(semaphore);
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
|
|
|
|
#define S_API_MESSAGE(_command) \
|
|
|
|
SAReturn return_data; \
|
|
|
|
StorageMessage message = { \
|
|
|
|
.semaphore = semaphore, \
|
|
|
|
.command = _command, \
|
|
|
|
.data = &data, \
|
|
|
|
.return_data = &return_data, \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define S_API_DATA_FILE \
|
|
|
|
SAData data = { \
|
|
|
|
.file = { \
|
|
|
|
.file = file, \
|
|
|
|
}};
|
|
|
|
|
|
|
|
#define S_API_DATA_PATH \
|
|
|
|
SAData data = { \
|
|
|
|
.path = { \
|
|
|
|
.path = path, \
|
|
|
|
}};
|
|
|
|
|
|
|
|
#define S_RETURN_BOOL (return_data.bool_value);
|
|
|
|
#define S_RETURN_UINT16 (return_data.uint16_value);
|
|
|
|
#define S_RETURN_UINT64 (return_data.uint64_value);
|
|
|
|
#define S_RETURN_ERROR (return_data.error_value);
|
|
|
|
#define S_RETURN_CSTRING (return_data.cstring_value);
|
|
|
|
|
2022-04-01 15:21:31 +03:00
|
|
|
typedef enum {
|
|
|
|
StorageEventFlagFileClose = (1 << 0),
|
|
|
|
} StorageEventFlag;
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
/****************** FILE ******************/
|
|
|
|
|
2022-04-01 15:21:31 +03:00
|
|
|
static bool storage_file_open_internal(
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
File* file,
|
|
|
|
const char* path,
|
|
|
|
FS_AccessMode access_mode,
|
|
|
|
FS_OpenMode open_mode) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
|
|
|
|
SAData data = {
|
|
|
|
.fopen = {
|
|
|
|
.file = file,
|
|
|
|
.path = path,
|
|
|
|
.access_mode = access_mode,
|
|
|
|
.open_mode = open_mode,
|
|
|
|
}};
|
|
|
|
|
2022-04-27 19:16:06 +03:00
|
|
|
file->type = FileTypeOpenFile;
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
|
|
|
|
S_API_MESSAGE(StorageCommandFileOpen);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
2022-04-01 15:21:31 +03:00
|
|
|
static void storage_file_close_callback(const void* message, void* context) {
|
|
|
|
const StorageEvent* storage_event = message;
|
|
|
|
|
2022-04-04 15:27:48 +03:00
|
|
|
if(storage_event->type == StorageEventTypeFileClose ||
|
|
|
|
storage_event->type == StorageEventTypeDirClose) {
|
2022-04-01 15:21:31 +03:00
|
|
|
furi_assert(context);
|
2022-07-20 13:56:33 +03:00
|
|
|
FuriEventFlag* event = context;
|
|
|
|
furi_event_flag_set(event, StorageEventFlagFileClose);
|
2022-04-01 15:21:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_file_open(
|
|
|
|
File* file,
|
|
|
|
const char* path,
|
|
|
|
FS_AccessMode access_mode,
|
|
|
|
FS_OpenMode open_mode) {
|
|
|
|
bool result;
|
2022-07-20 13:56:33 +03:00
|
|
|
FuriEventFlag* event = furi_event_flag_alloc();
|
2022-04-01 15:21:31 +03:00
|
|
|
FuriPubSubSubscription* subscription = furi_pubsub_subscribe(
|
|
|
|
storage_get_pubsub(file->storage), storage_file_close_callback, event);
|
|
|
|
|
|
|
|
do {
|
|
|
|
result = storage_file_open_internal(file, path, access_mode, open_mode);
|
|
|
|
|
|
|
|
if(!result && file->error_id == FSE_ALREADY_OPEN) {
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_event_flag_wait(
|
|
|
|
event, StorageEventFlagFileClose, FuriFlagWaitAny, FuriWaitForever);
|
2022-04-01 15:21:31 +03:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(true);
|
|
|
|
|
|
|
|
furi_pubsub_unsubscribe(storage_get_pubsub(file->storage), subscription);
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_event_flag_free(event);
|
2022-04-27 19:16:06 +03:00
|
|
|
|
|
|
|
FURI_LOG_T(
|
|
|
|
TAG, "File %p - %p open (%s)", (uint32_t)file - SRAM_BASE, file->file_id - SRAM_BASE, path);
|
|
|
|
|
2022-04-01 15:21:31 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
bool storage_file_close(File* file) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
|
|
|
|
S_API_DATA_FILE;
|
|
|
|
S_API_MESSAGE(StorageCommandFileClose);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
|
2022-04-27 19:16:06 +03:00
|
|
|
FURI_LOG_T(TAG, "File %p - %p closed", (uint32_t)file - SRAM_BASE, file->file_id - SRAM_BASE);
|
|
|
|
file->type = FileTypeClosed;
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t storage_file_read(File* file, void* buff, uint16_t bytes_to_read) {
|
2022-06-14 04:14:13 +03:00
|
|
|
if(bytes_to_read == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
|
|
|
|
SAData data = {
|
|
|
|
.fread = {
|
|
|
|
.file = file,
|
|
|
|
.buff = buff,
|
|
|
|
.bytes_to_read = bytes_to_read,
|
|
|
|
}};
|
|
|
|
|
|
|
|
S_API_MESSAGE(StorageCommandFileRead);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_UINT16;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t storage_file_write(File* file, const void* buff, uint16_t bytes_to_write) {
|
2022-06-14 04:14:13 +03:00
|
|
|
if(bytes_to_write == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
|
|
|
|
SAData data = {
|
|
|
|
.fwrite = {
|
|
|
|
.file = file,
|
|
|
|
.buff = buff,
|
|
|
|
.bytes_to_write = bytes_to_write,
|
|
|
|
}};
|
|
|
|
|
|
|
|
S_API_MESSAGE(StorageCommandFileWrite);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_UINT16;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_file_seek(File* file, uint32_t offset, bool from_start) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
|
|
|
|
SAData data = {
|
|
|
|
.fseek = {
|
|
|
|
.file = file,
|
|
|
|
.offset = offset,
|
|
|
|
.from_start = from_start,
|
|
|
|
}};
|
|
|
|
|
|
|
|
S_API_MESSAGE(StorageCommandFileSeek);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t storage_file_tell(File* file) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
S_API_DATA_FILE;
|
|
|
|
S_API_MESSAGE(StorageCommandFileTell);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_UINT64;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_file_truncate(File* file) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
S_API_DATA_FILE;
|
|
|
|
S_API_MESSAGE(StorageCommandFileTruncate);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t storage_file_size(File* file) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
S_API_DATA_FILE;
|
|
|
|
S_API_MESSAGE(StorageCommandFileSize);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_UINT64;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_file_sync(File* file) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
S_API_DATA_FILE;
|
|
|
|
S_API_MESSAGE(StorageCommandFileSync);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_file_eof(File* file) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
S_API_DATA_FILE;
|
|
|
|
S_API_MESSAGE(StorageCommandFileEof);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************** DIR ******************/
|
|
|
|
|
2022-04-04 15:27:48 +03:00
|
|
|
static bool storage_dir_open_internal(File* file, const char* path) {
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
|
|
|
|
SAData data = {
|
|
|
|
.dopen = {
|
|
|
|
.file = file,
|
|
|
|
.path = path,
|
|
|
|
}};
|
|
|
|
|
2022-04-27 19:16:06 +03:00
|
|
|
file->type = FileTypeOpenDir;
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
|
|
|
|
S_API_MESSAGE(StorageCommandDirOpen);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
2022-04-04 15:27:48 +03:00
|
|
|
bool storage_dir_open(File* file, const char* path) {
|
|
|
|
bool result;
|
2022-07-20 13:56:33 +03:00
|
|
|
FuriEventFlag* event = furi_event_flag_alloc();
|
2022-04-04 15:27:48 +03:00
|
|
|
FuriPubSubSubscription* subscription = furi_pubsub_subscribe(
|
|
|
|
storage_get_pubsub(file->storage), storage_file_close_callback, event);
|
|
|
|
|
|
|
|
do {
|
|
|
|
result = storage_dir_open_internal(file, path);
|
|
|
|
|
|
|
|
if(!result && file->error_id == FSE_ALREADY_OPEN) {
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_event_flag_wait(
|
|
|
|
event, StorageEventFlagFileClose, FuriFlagWaitAny, FuriWaitForever);
|
2022-04-04 15:27:48 +03:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(true);
|
|
|
|
|
|
|
|
furi_pubsub_unsubscribe(storage_get_pubsub(file->storage), subscription);
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_event_flag_free(event);
|
2022-04-27 19:16:06 +03:00
|
|
|
|
|
|
|
FURI_LOG_T(
|
|
|
|
TAG, "Dir %p - %p open (%s)", (uint32_t)file - SRAM_BASE, file->file_id - SRAM_BASE, path);
|
|
|
|
|
2022-04-04 15:27:48 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
bool storage_dir_close(File* file) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
S_API_DATA_FILE;
|
|
|
|
S_API_MESSAGE(StorageCommandDirClose);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
|
2022-04-27 19:16:06 +03:00
|
|
|
FURI_LOG_T(TAG, "Dir %p - %p closed", (uint32_t)file - SRAM_BASE, file->file_id - SRAM_BASE);
|
|
|
|
|
|
|
|
file->type = FileTypeClosed;
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_dir_read(File* file, FileInfo* fileinfo, char* name, uint16_t name_length) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
|
|
|
|
SAData data = {
|
|
|
|
.dread = {
|
|
|
|
.file = file,
|
|
|
|
.fileinfo = fileinfo,
|
|
|
|
.name = name,
|
|
|
|
.name_length = name_length,
|
|
|
|
}};
|
|
|
|
|
|
|
|
S_API_MESSAGE(StorageCommandDirRead);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_dir_rewind(File* file) {
|
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
S_API_DATA_FILE;
|
|
|
|
S_API_MESSAGE(StorageCommandDirRewind);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************** COMMON ******************/
|
|
|
|
|
|
|
|
FS_Error storage_common_stat(Storage* storage, const char* path, FileInfo* fileinfo) {
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
|
|
|
|
SAData data = {.cstat = {.path = path, .fileinfo = fileinfo}};
|
|
|
|
|
|
|
|
S_API_MESSAGE(StorageCommandCommonStat);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
FS_Error storage_common_remove(Storage* storage, const char* path) {
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
S_API_DATA_PATH;
|
|
|
|
S_API_MESSAGE(StorageCommandCommonRemove);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
FS_Error storage_common_rename(Storage* storage, const char* old_path, const char* new_path) {
|
2022-04-01 15:21:31 +03:00
|
|
|
FS_Error error = storage_common_copy(storage, old_path, new_path);
|
|
|
|
if(error == FSE_OK) {
|
2022-05-10 17:05:36 +03:00
|
|
|
if(storage_simply_remove_recursive(storage, old_path)) {
|
|
|
|
error = FSE_OK;
|
|
|
|
} else {
|
|
|
|
error = FSE_INTERNAL;
|
|
|
|
}
|
2022-04-01 15:21:31 +03:00
|
|
|
}
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
|
2022-04-01 15:21:31 +03:00
|
|
|
return error;
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
}
|
|
|
|
|
2022-05-10 17:05:36 +03:00
|
|
|
static FS_Error
|
|
|
|
storage_copy_recursive(Storage* storage, const char* old_path, const char* new_path) {
|
|
|
|
FS_Error error = storage_common_mkdir(storage, new_path);
|
|
|
|
DirWalk* dir_walk = dir_walk_alloc(storage);
|
|
|
|
string_t path;
|
|
|
|
string_t tmp_new_path;
|
|
|
|
string_t tmp_old_path;
|
|
|
|
FileInfo fileinfo;
|
|
|
|
string_init(path);
|
|
|
|
string_init(tmp_new_path);
|
|
|
|
string_init(tmp_old_path);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(error != FSE_OK) break;
|
|
|
|
|
|
|
|
if(!dir_walk_open(dir_walk, old_path)) {
|
|
|
|
error = dir_walk_get_error(dir_walk);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
DirWalkResult res = dir_walk_read(dir_walk, path, &fileinfo);
|
|
|
|
|
|
|
|
if(res == DirWalkError) {
|
|
|
|
error = dir_walk_get_error(dir_walk);
|
|
|
|
break;
|
|
|
|
} else if(res == DirWalkLast) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
string_set(tmp_old_path, path);
|
|
|
|
string_right(path, strlen(old_path));
|
|
|
|
string_printf(tmp_new_path, "%s%s", new_path, string_get_cstr(path));
|
|
|
|
|
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
|
|
|
error = storage_common_mkdir(storage, string_get_cstr(tmp_new_path));
|
|
|
|
} else {
|
|
|
|
error = storage_common_copy(
|
|
|
|
storage, string_get_cstr(tmp_old_path), string_get_cstr(tmp_new_path));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(error != FSE_OK) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while(false);
|
|
|
|
|
|
|
|
string_clear(tmp_new_path);
|
|
|
|
string_clear(tmp_old_path);
|
|
|
|
string_clear(path);
|
|
|
|
dir_walk_free(dir_walk);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
FS_Error storage_common_copy(Storage* storage, const char* old_path, const char* new_path) {
|
2022-04-01 15:21:31 +03:00
|
|
|
FS_Error error;
|
|
|
|
|
|
|
|
FileInfo fileinfo;
|
|
|
|
error = storage_common_stat(storage, old_path, &fileinfo);
|
|
|
|
|
|
|
|
if(error == FSE_OK) {
|
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
2022-05-10 17:05:36 +03:00
|
|
|
error = storage_copy_recursive(storage, old_path, new_path);
|
2022-04-01 15:21:31 +03:00
|
|
|
} else {
|
|
|
|
Stream* stream_from = file_stream_alloc(storage);
|
|
|
|
Stream* stream_to = file_stream_alloc(storage);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(!file_stream_open(stream_from, old_path, FSAM_READ, FSOM_OPEN_EXISTING)) break;
|
|
|
|
if(!file_stream_open(stream_to, new_path, FSAM_WRITE, FSOM_CREATE_NEW)) break;
|
|
|
|
stream_copy_full(stream_from, stream_to);
|
|
|
|
} while(false);
|
|
|
|
|
|
|
|
error = file_stream_get_error(stream_from);
|
|
|
|
if(error == FSE_OK) {
|
|
|
|
error = file_stream_get_error(stream_to);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream_free(stream_from);
|
|
|
|
stream_free(stream_to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
}
|
|
|
|
|
2022-07-14 19:44:34 +03:00
|
|
|
static FS_Error
|
|
|
|
storage_merge_recursive(Storage* storage, const char* old_path, const char* new_path) {
|
|
|
|
FS_Error error = storage_common_mkdir(storage, new_path);
|
|
|
|
DirWalk* dir_walk = dir_walk_alloc(storage);
|
2022-07-26 15:21:51 +03:00
|
|
|
string_t path, file_basename, tmp_new_path;
|
2022-07-14 19:44:34 +03:00
|
|
|
FileInfo fileinfo;
|
|
|
|
string_init(path);
|
2022-07-26 15:21:51 +03:00
|
|
|
string_init(file_basename);
|
2022-07-14 19:44:34 +03:00
|
|
|
string_init(tmp_new_path);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if((error != FSE_OK) && (error != FSE_EXIST)) break;
|
|
|
|
|
2022-07-26 15:21:51 +03:00
|
|
|
dir_walk_set_recursive(dir_walk, false);
|
2022-07-14 19:44:34 +03:00
|
|
|
if(!dir_walk_open(dir_walk, old_path)) {
|
|
|
|
error = dir_walk_get_error(dir_walk);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
DirWalkResult res = dir_walk_read(dir_walk, path, &fileinfo);
|
|
|
|
|
|
|
|
if(res == DirWalkError) {
|
|
|
|
error = dir_walk_get_error(dir_walk);
|
|
|
|
break;
|
|
|
|
} else if(res == DirWalkLast) {
|
|
|
|
break;
|
|
|
|
} else {
|
2022-07-26 15:21:51 +03:00
|
|
|
path_extract_basename(string_get_cstr(path), file_basename);
|
|
|
|
path_concat(new_path, string_get_cstr(file_basename), tmp_new_path);
|
2022-07-14 19:44:34 +03:00
|
|
|
|
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
|
|
|
if(storage_common_stat(storage, string_get_cstr(tmp_new_path), &fileinfo) ==
|
|
|
|
FSE_OK) {
|
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
|
|
|
error = storage_common_mkdir(storage, string_get_cstr(tmp_new_path));
|
2022-07-26 15:21:51 +03:00
|
|
|
if(error != FSE_OK) {
|
|
|
|
break;
|
|
|
|
}
|
2022-07-14 19:44:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-26 15:21:51 +03:00
|
|
|
error = storage_common_merge(
|
|
|
|
storage, string_get_cstr(path), string_get_cstr(tmp_new_path));
|
2022-07-14 19:44:34 +03:00
|
|
|
|
2022-07-26 15:21:51 +03:00
|
|
|
if(error != FSE_OK) {
|
|
|
|
break;
|
|
|
|
}
|
2022-07-14 19:44:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while(false);
|
|
|
|
|
|
|
|
string_clear(tmp_new_path);
|
2022-07-26 15:21:51 +03:00
|
|
|
string_clear(file_basename);
|
2022-07-14 19:44:34 +03:00
|
|
|
string_clear(path);
|
|
|
|
dir_walk_free(dir_walk);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
FS_Error storage_common_merge(Storage* storage, const char* old_path, const char* new_path) {
|
|
|
|
FS_Error error;
|
|
|
|
const char* new_path_tmp;
|
|
|
|
string_t new_path_next;
|
|
|
|
string_init(new_path_next);
|
|
|
|
|
|
|
|
FileInfo fileinfo;
|
|
|
|
error = storage_common_stat(storage, old_path, &fileinfo);
|
|
|
|
|
|
|
|
if(error == FSE_OK) {
|
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
|
|
|
error = storage_merge_recursive(storage, old_path, new_path);
|
|
|
|
} else {
|
|
|
|
error = storage_common_stat(storage, new_path, &fileinfo);
|
|
|
|
if(error == FSE_OK) {
|
|
|
|
string_set_str(new_path_next, new_path);
|
|
|
|
string_t dir_path;
|
|
|
|
string_t filename;
|
|
|
|
char extension[MAX_EXT_LEN];
|
|
|
|
|
|
|
|
string_init(dir_path);
|
|
|
|
string_init(filename);
|
|
|
|
|
|
|
|
path_extract_filename(new_path_next, filename, true);
|
|
|
|
path_extract_dirname(new_path, dir_path);
|
|
|
|
path_extract_extension(new_path_next, extension, MAX_EXT_LEN);
|
|
|
|
|
|
|
|
storage_get_next_filename(
|
|
|
|
storage,
|
|
|
|
string_get_cstr(dir_path),
|
|
|
|
string_get_cstr(filename),
|
|
|
|
extension,
|
|
|
|
new_path_next,
|
|
|
|
255);
|
|
|
|
string_cat_printf(dir_path, "/%s%s", string_get_cstr(new_path_next), extension);
|
|
|
|
string_set(new_path_next, dir_path);
|
|
|
|
|
|
|
|
string_clear(dir_path);
|
|
|
|
string_clear(filename);
|
|
|
|
new_path_tmp = string_get_cstr(new_path_next);
|
|
|
|
} else {
|
|
|
|
new_path_tmp = new_path;
|
|
|
|
}
|
|
|
|
Stream* stream_from = file_stream_alloc(storage);
|
|
|
|
Stream* stream_to = file_stream_alloc(storage);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(!file_stream_open(stream_from, old_path, FSAM_READ, FSOM_OPEN_EXISTING)) break;
|
|
|
|
if(!file_stream_open(stream_to, new_path_tmp, FSAM_WRITE, FSOM_CREATE_NEW)) break;
|
|
|
|
stream_copy_full(stream_from, stream_to);
|
|
|
|
} while(false);
|
|
|
|
|
|
|
|
error = file_stream_get_error(stream_from);
|
|
|
|
if(error == FSE_OK) {
|
|
|
|
error = file_stream_get_error(stream_to);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream_free(stream_from);
|
|
|
|
stream_free(stream_to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string_clear(new_path_next);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
FS_Error storage_common_mkdir(Storage* storage, const char* path) {
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
S_API_DATA_PATH;
|
|
|
|
S_API_MESSAGE(StorageCommandCommonMkDir);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
FS_Error storage_common_fs_info(
|
|
|
|
Storage* storage,
|
|
|
|
const char* fs_path,
|
|
|
|
uint64_t* total_space,
|
|
|
|
uint64_t* free_space) {
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
|
|
|
|
SAData data = {
|
|
|
|
.cfsinfo = {
|
|
|
|
.fs_path = fs_path,
|
|
|
|
.total_space = total_space,
|
|
|
|
.free_space = free_space,
|
|
|
|
}};
|
|
|
|
|
|
|
|
S_API_MESSAGE(StorageCommandCommonFSInfo);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************** ERROR ******************/
|
|
|
|
|
|
|
|
const char* storage_error_get_desc(FS_Error error_id) {
|
|
|
|
return filesystem_api_error_get_desc(error_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
FS_Error storage_file_get_error(File* file) {
|
|
|
|
furi_check(file != NULL);
|
|
|
|
return file->error_id;
|
|
|
|
}
|
|
|
|
|
2021-11-04 13:46:45 +03:00
|
|
|
int32_t storage_file_get_internal_error(File* file) {
|
|
|
|
furi_check(file != NULL);
|
|
|
|
return file->internal_error_id;
|
|
|
|
}
|
|
|
|
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
const char* storage_file_get_error_desc(File* file) {
|
|
|
|
furi_check(file != NULL);
|
|
|
|
return filesystem_api_error_get_desc(file->error_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************** Raw SD API ******************/
|
|
|
|
|
|
|
|
FS_Error storage_sd_format(Storage* storage) {
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
SAData data = {};
|
|
|
|
S_API_MESSAGE(StorageCommandSDFormat);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
FS_Error storage_sd_unmount(Storage* storage) {
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
SAData data = {};
|
|
|
|
S_API_MESSAGE(StorageCommandSDUnmount);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
FS_Error storage_sd_info(Storage* storage, SDInfo* info) {
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
SAData data = {
|
|
|
|
.sdinfo = {
|
|
|
|
.info = info,
|
|
|
|
}};
|
|
|
|
S_API_MESSAGE(StorageCommandSDInfo);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
FS_Error storage_sd_status(Storage* storage) {
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
SAData data = {};
|
|
|
|
S_API_MESSAGE(StorageCommandSDStatus);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
File* storage_file_alloc(Storage* storage) {
|
2022-02-18 22:53:46 +03:00
|
|
|
File* file = malloc(sizeof(File));
|
2022-04-27 19:16:06 +03:00
|
|
|
file->type = FileTypeClosed;
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
file->storage = storage;
|
|
|
|
|
2022-04-27 19:16:06 +03:00
|
|
|
FURI_LOG_T(TAG, "File/Dir %p alloc", (uint32_t)file - SRAM_BASE);
|
|
|
|
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_file_is_open(File* file) {
|
2022-04-27 19:16:06 +03:00
|
|
|
return (file->type != FileTypeClosed);
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
}
|
|
|
|
|
2022-04-04 15:27:48 +03:00
|
|
|
bool storage_file_is_dir(File* file) {
|
2022-04-27 19:16:06 +03:00
|
|
|
return (file->type == FileTypeOpenDir);
|
2022-04-04 15:27:48 +03:00
|
|
|
}
|
|
|
|
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
void storage_file_free(File* file) {
|
|
|
|
if(storage_file_is_open(file)) {
|
2022-04-04 15:27:48 +03:00
|
|
|
if(storage_file_is_dir(file)) {
|
|
|
|
storage_dir_close(file);
|
|
|
|
} else {
|
|
|
|
storage_file_close(file);
|
|
|
|
}
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
}
|
|
|
|
|
2022-04-27 19:16:06 +03:00
|
|
|
FURI_LOG_T(TAG, "File/Dir %p free", (uint32_t)file - SRAM_BASE);
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00
|
|
|
free(file);
|
2021-10-06 12:40:28 +03:00
|
|
|
}
|
|
|
|
|
2021-11-24 19:21:12 +03:00
|
|
|
FuriPubSub* storage_get_pubsub(Storage* storage) {
|
|
|
|
return storage->pubsub;
|
|
|
|
}
|
|
|
|
|
2021-10-26 19:05:28 +03:00
|
|
|
bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
|
|
|
furi_assert(storage);
|
|
|
|
furi_assert(path);
|
|
|
|
FileInfo fileinfo;
|
|
|
|
bool result = false;
|
|
|
|
string_t fullname;
|
|
|
|
string_t cur_dir;
|
|
|
|
|
|
|
|
if(storage_simply_remove(storage, path)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-18 22:53:46 +03:00
|
|
|
char* name = malloc(MAX_NAME_LENGTH + 1);
|
2021-10-26 19:05:28 +03:00
|
|
|
File* dir = storage_file_alloc(storage);
|
|
|
|
string_init_set_str(cur_dir, path);
|
|
|
|
bool go_deeper = false;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
if(!storage_dir_open(dir, string_get_cstr(cur_dir))) {
|
|
|
|
storage_dir_close(dir);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH)) {
|
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
|
|
|
string_cat_printf(cur_dir, "/%s", name);
|
|
|
|
go_deeper = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
string_init_printf(fullname, "%s/%s", string_get_cstr(cur_dir), name);
|
|
|
|
FS_Error error = storage_common_remove(storage, string_get_cstr(fullname));
|
2021-11-28 21:28:19 +03:00
|
|
|
furi_check(error == FSE_OK);
|
2021-10-26 19:05:28 +03:00
|
|
|
string_clear(fullname);
|
|
|
|
}
|
|
|
|
storage_dir_close(dir);
|
|
|
|
|
|
|
|
if(go_deeper) {
|
|
|
|
go_deeper = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
FS_Error error = storage_common_remove(storage, string_get_cstr(cur_dir));
|
2021-11-28 21:28:19 +03:00
|
|
|
furi_check(error == FSE_OK);
|
2021-10-26 19:05:28 +03:00
|
|
|
|
|
|
|
if(string_cmp(cur_dir, path)) {
|
|
|
|
size_t last_char = string_search_rchar(cur_dir, '/');
|
|
|
|
furi_assert(last_char != STRING_FAILURE);
|
|
|
|
string_left(cur_dir, last_char);
|
|
|
|
} else {
|
|
|
|
result = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
storage_file_free(dir);
|
|
|
|
string_clear(cur_dir);
|
|
|
|
free(name);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-10-06 12:40:28 +03:00
|
|
|
bool storage_simply_remove(Storage* storage, const char* path) {
|
|
|
|
FS_Error result;
|
|
|
|
result = storage_common_remove(storage, path);
|
|
|
|
return result == FSE_OK || result == FSE_NOT_EXIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_simply_mkdir(Storage* storage, const char* path) {
|
|
|
|
FS_Error result;
|
|
|
|
result = storage_common_mkdir(storage, path);
|
|
|
|
return result == FSE_OK || result == FSE_EXIST;
|
2021-10-26 19:05:28 +03:00
|
|
|
}
|
2021-11-11 15:49:19 +03:00
|
|
|
|
|
|
|
void storage_get_next_filename(
|
|
|
|
Storage* storage,
|
|
|
|
const char* dirname,
|
|
|
|
const char* filename,
|
|
|
|
const char* fileextension,
|
2022-04-07 14:47:47 +03:00
|
|
|
string_t nextfilename,
|
|
|
|
uint8_t max_len) {
|
2021-11-11 15:49:19 +03:00
|
|
|
string_t temp_str;
|
|
|
|
uint16_t num = 0;
|
|
|
|
|
|
|
|
string_init_printf(temp_str, "%s/%s%s", dirname, filename, fileextension);
|
|
|
|
|
|
|
|
while(storage_common_stat(storage, string_get_cstr(temp_str), NULL) == FSE_OK) {
|
|
|
|
num++;
|
|
|
|
string_printf(temp_str, "%s/%s%d%s", dirname, filename, num, fileextension);
|
|
|
|
}
|
2022-04-07 14:47:47 +03:00
|
|
|
if(num && (max_len > strlen(filename))) {
|
2021-11-11 15:49:19 +03:00
|
|
|
string_printf(nextfilename, "%s%d", filename, num);
|
|
|
|
} else {
|
|
|
|
string_printf(nextfilename, "%s", filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
string_clear(temp_str);
|
|
|
|
}
|