2022-07-20 10:56:33 +00:00
|
|
|
#include <core/log.h>
|
|
|
|
#include <core/record.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 12:20:19 +00:00
|
|
|
#include "storage.h"
|
2022-01-05 16:10:18 +00:00
|
|
|
#include "storage_i.h"
|
|
|
|
#include "storage_message.h"
|
2022-04-01 12:21:31 +00:00
|
|
|
#include <toolbox/stream/file_stream.h>
|
2022-05-10 14:05:36 +00:00
|
|
|
#include <toolbox/dir_walk.h>
|
2022-07-14 16:44:34 +00: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 12:20:19 +00:00
|
|
|
|
2021-10-26 16:05:28 +00:00
|
|
|
#define MAX_NAME_LENGTH 256
|
2022-07-14 16:44:34 +00:00
|
|
|
#define MAX_EXT_LEN 16
|
2021-10-26 16:05:28 +00:00
|
|
|
|
2022-04-27 16:16:06 +00:00
|
|
|
#define TAG "StorageAPI"
|
|
|
|
|
2022-07-20 10:56:33 +00: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 12:20:19 +00:00
|
|
|
furi_check(semaphore != NULL);
|
|
|
|
|
|
|
|
#define S_FILE_API_PROLOGUE \
|
|
|
|
Storage* storage = file->storage; \
|
|
|
|
furi_assert(storage);
|
|
|
|
|
2022-07-20 10:56:33 +00: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 12:20:19 +00: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 12:21:31 +00: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 12:20:19 +00:00
|
|
|
/****************** FILE ******************/
|
|
|
|
|
2022-04-01 12:21:31 +00: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 12:20:19 +00: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 16:16:06 +00: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 12:20:19 +00:00
|
|
|
|
|
|
|
S_API_MESSAGE(StorageCommandFileOpen);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
2022-04-01 12:21:31 +00:00
|
|
|
static void storage_file_close_callback(const void* message, void* context) {
|
|
|
|
const StorageEvent* storage_event = message;
|
|
|
|
|
2022-04-04 12:27:48 +00:00
|
|
|
if(storage_event->type == StorageEventTypeFileClose ||
|
|
|
|
storage_event->type == StorageEventTypeDirClose) {
|
2022-04-01 12:21:31 +00:00
|
|
|
furi_assert(context);
|
2022-07-20 10:56:33 +00:00
|
|
|
FuriEventFlag* event = context;
|
|
|
|
furi_event_flag_set(event, StorageEventFlagFileClose);
|
2022-04-01 12:21:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_file_open(
|
|
|
|
File* file,
|
|
|
|
const char* path,
|
|
|
|
FS_AccessMode access_mode,
|
|
|
|
FS_OpenMode open_mode) {
|
|
|
|
bool result;
|
2022-07-20 10:56:33 +00:00
|
|
|
FuriEventFlag* event = furi_event_flag_alloc();
|
2022-04-01 12:21:31 +00: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 10:56:33 +00:00
|
|
|
furi_event_flag_wait(
|
|
|
|
event, StorageEventFlagFileClose, FuriFlagWaitAny, FuriWaitForever);
|
2022-04-01 12:21:31 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(true);
|
|
|
|
|
|
|
|
furi_pubsub_unsubscribe(storage_get_pubsub(file->storage), subscription);
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_event_flag_free(event);
|
2022-04-27 16:16:06 +00:00
|
|
|
|
|
|
|
FURI_LOG_T(
|
2022-10-07 13:35:15 +00:00
|
|
|
TAG,
|
|
|
|
"File %p - %p open (%s)",
|
|
|
|
(void*)((uint32_t)file - SRAM_BASE),
|
|
|
|
(void*)(file->file_id - SRAM_BASE),
|
|
|
|
path);
|
2022-04-27 16:16:06 +00:00
|
|
|
|
2022-04-01 12:21:31 +00: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 12:20:19 +00: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-10-07 13:35:15 +00:00
|
|
|
FURI_LOG_T(
|
|
|
|
TAG,
|
|
|
|
"File %p - %p closed",
|
|
|
|
(void*)((uint32_t)file - SRAM_BASE),
|
|
|
|
(void*)(file->file_id - SRAM_BASE));
|
2022-04-27 16:16:06 +00: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 12:20:19 +00:00
|
|
|
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t storage_file_read(File* file, void* buff, uint16_t bytes_to_read) {
|
2022-06-14 01:14:13 +00: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 12:20:19 +00: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 01:14:13 +00: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 12:20:19 +00: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;
|
|
|
|
}
|
|
|
|
|
[FL-2529][FL-1628] New LF-RFID subsystem (#1601)
* Makefile: unit tests pack
* RFID: pulse joiner and its unit test
* Move pulse protocol helpers to appropriate place
* Drop pulse_joiner tests
* Generic protocol, protocols dictionary, unit test
* Protocol dict unit test
* iButton: protocols dictionary
* Lib: varint
* Lib: profiler
* Unit test: varint
* rfid: worker mockup
* LFRFID: em4100 unit test
* Storage: file_exist function
* rfid: fsk osc
* rfid: generic fsk demodulator
* rfid: protocol em4100
* rfid: protocol h10301
* rfid: protocol io prox xsf
* Unit test: rfid protocols
* rfid: new hal
* rfid: raw worker
* Unit test: fix error output
* rfid: worker
* rfid: plain c cli
* fw: migrate to scons
* lfrfid: full io prox support
* unit test: io prox protocol
* SubGHZ: move bit defines to source
* FSK oscillator: level duration compability
* libs: bit manipulation library
* lfrfid: ioprox protocol, use bit library and new level duration method of FSK ocillator
* bit lib: unit tests
* Bit lib: parity tests, remove every nth bit, copy bits
* Lfrfid: awid protocol
* bit lib: uint16 and uint32 getters, unit tests
* lfrfid: FDX-B read, draft version
* Minunit: better memeq assert
* bit lib: reverse, print, print regions
* Protocol dict: get protocol features, get protocol validate count
* lfrfid worker: improved read
* lfrfid raw worker: psk support
* Cli: rfid plain C cli
* protocol AWID: render
* protocol em4100: render
* protocol h10301: render
* protocol indala26: support every indala 26 scramble
* Protocol IO Prox: render
* Protocol FDX-B: advanced read
* lfrfid: remove unused test function
* lfrfid: fix os primitives
* bit lib: crc16 and unit tests
* FDX-B: save data
* lfrfid worker: increase stream size. Alloc raw worker only when needed.
* lfrfid: indala26 emulation
* lfrfid: prepare to write
* lfrfid: fdx-b emulation
* lfrfid: awid, ioprox write
* lfrfid: write t55xx w\o validation
* lfrfid: better t55xx block0 handling
* lfrfid: use new t5577 functions in worker
* lfrfid: improve protocol description
* lfrfid: write and verify
* lfrfid: delete cpp cli
* lfrfid: improve worker usage
* lfrfid-app: step to new worker
* lfrfid: old indala (I40134) load fallback
* lfrfid: indala26, recover wrong synced data
* lfrfid: remove old worker
* lfrfid app: dummy read screen
* lfrfid app: less dummy read screen
* lfrfid: generic 96-bit HID protocol (covers up to HID 37-bit)
* rename
* lfrfid: improve indala26 read
* lfrfid: generic 192-bit HID protocol (covers all HID extended)
* lfrfid: TODO about HID render
* lfrfid: new protocol FDX-A
* lfrfid-app: correct worker stop on exit
* misc fixes
* lfrfid: FDX-A and HID distinguishability has been fixed.
* lfrfid: decode HID size header and render it (#1612)
* lfrfid: rename HID96 and HID192 to HIDProx and HIDExt
* lfrfid: extra actions scene
* lfrfid: decode generic HID Proximity size lazily (#1618)
* lib: stream of data buffers concept
* lfrfid: raw file helper
* lfrfid: changed raw worker api
* lfrfid: packed varint pair
* lfrfid: read stream speedup
* lfrfid app: show read mode
* Documentation
* lfrfid app: raw read gui
* lfrfid app: storage check for raw read
* memleak fix
* review fixes
* lfrfid app: read blink color
* lfrfid app: reset key name after read
* review fixes
* lfrfid app: fix copypasted text
* review fixes
* lfrfid: disable debug gpio
* lfrfid: card detection events
* lfrfid: change validation color from magenta to green
* Update core_defines.
* lfrfid: prefix fdx-b id by zeroes
* lfrfid: parse up to 43-bit HID Proximity keys (#1640)
* Fbt: downgrade toolchain and fix PS1
* lfrfid: fix unit tests
* lfrfid app: remove printf
* lfrfid: indala26, use bit 55 as data
* lfrfid: indala26, better brief format
* lfrfid: indala26, loading fallback
* lfrfid: read timing tuning
Co-authored-by: James Ide <ide@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
2022-08-23 15:57:39 +00:00
|
|
|
bool storage_file_exists(Storage* storage, const char* path) {
|
|
|
|
bool exist = false;
|
|
|
|
FileInfo fileinfo;
|
|
|
|
FS_Error error = storage_common_stat(storage, path, &fileinfo);
|
|
|
|
|
|
|
|
if(error == FSE_OK && !(fileinfo.flags & FSF_DIRECTORY)) {
|
|
|
|
exist = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return exist;
|
|
|
|
}
|
|
|
|
|
[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 12:20:19 +00:00
|
|
|
/****************** DIR ******************/
|
|
|
|
|
2022-04-04 12:27:48 +00: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 12:20:19 +00:00
|
|
|
S_FILE_API_PROLOGUE;
|
|
|
|
S_API_PROLOGUE;
|
|
|
|
|
|
|
|
SAData data = {
|
|
|
|
.dopen = {
|
|
|
|
.file = file,
|
|
|
|
.path = path,
|
|
|
|
}};
|
|
|
|
|
2022-04-27 16:16:06 +00: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 12:20:19 +00:00
|
|
|
|
|
|
|
S_API_MESSAGE(StorageCommandDirOpen);
|
|
|
|
S_API_EPILOGUE;
|
|
|
|
return S_RETURN_BOOL;
|
|
|
|
}
|
|
|
|
|
2022-04-04 12:27:48 +00:00
|
|
|
bool storage_dir_open(File* file, const char* path) {
|
|
|
|
bool result;
|
2022-07-20 10:56:33 +00:00
|
|
|
FuriEventFlag* event = furi_event_flag_alloc();
|
2022-04-04 12:27:48 +00: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 10:56:33 +00:00
|
|
|
furi_event_flag_wait(
|
|
|
|
event, StorageEventFlagFileClose, FuriFlagWaitAny, FuriWaitForever);
|
2022-04-04 12:27:48 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(true);
|
|
|
|
|
|
|
|
furi_pubsub_unsubscribe(storage_get_pubsub(file->storage), subscription);
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_event_flag_free(event);
|
2022-04-27 16:16:06 +00:00
|
|
|
|
|
|
|
FURI_LOG_T(
|
2022-10-07 13:35:15 +00:00
|
|
|
TAG,
|
|
|
|
"Dir %p - %p open (%s)",
|
|
|
|
(void*)((uint32_t)file - SRAM_BASE),
|
|
|
|
(void*)(file->file_id - SRAM_BASE),
|
|
|
|
path);
|
2022-04-27 16:16:06 +00:00
|
|
|
|
2022-04-04 12:27:48 +00: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 12:20:19 +00: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-10-07 13:35:15 +00:00
|
|
|
FURI_LOG_T(
|
|
|
|
TAG,
|
|
|
|
"Dir %p - %p closed",
|
|
|
|
(void*)((uint32_t)file - SRAM_BASE),
|
|
|
|
(void*)(file->file_id - SRAM_BASE));
|
2022-04-27 16:16:06 +00: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 12:20:19 +00: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 12:21:31 +00:00
|
|
|
FS_Error error = storage_common_copy(storage, old_path, new_path);
|
|
|
|
if(error == FSE_OK) {
|
2022-05-10 14:05:36 +00:00
|
|
|
if(storage_simply_remove_recursive(storage, old_path)) {
|
|
|
|
error = FSE_OK;
|
|
|
|
} else {
|
|
|
|
error = FSE_INTERNAL;
|
|
|
|
}
|
2022-04-01 12:21:31 +00: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 12:20:19 +00:00
|
|
|
|
2022-04-01 12:21:31 +00: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 12:20:19 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 14:05:36 +00: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);
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* path;
|
|
|
|
FuriString* tmp_new_path;
|
|
|
|
FuriString* tmp_old_path;
|
2022-05-10 14:05:36 +00:00
|
|
|
FileInfo fileinfo;
|
2022-10-05 15:15:23 +00:00
|
|
|
path = furi_string_alloc();
|
|
|
|
tmp_new_path = furi_string_alloc();
|
|
|
|
tmp_old_path = furi_string_alloc();
|
2022-05-10 14:05:36 +00:00
|
|
|
|
|
|
|
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 {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_set(tmp_old_path, path);
|
|
|
|
furi_string_right(path, strlen(old_path));
|
|
|
|
furi_string_printf(tmp_new_path, "%s%s", new_path, furi_string_get_cstr(path));
|
2022-05-10 14:05:36 +00:00
|
|
|
|
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
2022-10-05 15:15:23 +00:00
|
|
|
error = storage_common_mkdir(storage, furi_string_get_cstr(tmp_new_path));
|
2022-05-10 14:05:36 +00:00
|
|
|
} else {
|
|
|
|
error = storage_common_copy(
|
2022-10-05 15:15:23 +00:00
|
|
|
storage,
|
|
|
|
furi_string_get_cstr(tmp_old_path),
|
|
|
|
furi_string_get_cstr(tmp_new_path));
|
2022-05-10 14:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(error != FSE_OK) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while(false);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(tmp_new_path);
|
|
|
|
furi_string_free(tmp_old_path);
|
|
|
|
furi_string_free(path);
|
2022-05-10 14:05:36 +00:00
|
|
|
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 12:20:19 +00:00
|
|
|
FS_Error storage_common_copy(Storage* storage, const char* old_path, const char* new_path) {
|
2022-04-01 12:21:31 +00: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 14:05:36 +00:00
|
|
|
error = storage_copy_recursive(storage, old_path, new_path);
|
2022-04-01 12:21:31 +00: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 12:20:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-14 16:44:34 +00: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-10-05 15:15:23 +00:00
|
|
|
FuriString *path, *file_basename, *tmp_new_path;
|
2022-07-14 16:44:34 +00:00
|
|
|
FileInfo fileinfo;
|
2022-10-05 15:15:23 +00:00
|
|
|
path = furi_string_alloc();
|
|
|
|
file_basename = furi_string_alloc();
|
|
|
|
tmp_new_path = furi_string_alloc();
|
2022-07-14 16:44:34 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
if((error != FSE_OK) && (error != FSE_EXIST)) break;
|
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
dir_walk_set_recursive(dir_walk, false);
|
2022-07-14 16:44:34 +00: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-10-05 15:15:23 +00:00
|
|
|
path_extract_basename(furi_string_get_cstr(path), file_basename);
|
|
|
|
path_concat(new_path, furi_string_get_cstr(file_basename), tmp_new_path);
|
2022-07-14 16:44:34 +00:00
|
|
|
|
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
2022-10-05 15:15:23 +00:00
|
|
|
if(storage_common_stat(
|
|
|
|
storage, furi_string_get_cstr(tmp_new_path), &fileinfo) == FSE_OK) {
|
2022-07-14 16:44:34 +00:00
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
2022-10-05 15:15:23 +00:00
|
|
|
error =
|
|
|
|
storage_common_mkdir(storage, furi_string_get_cstr(tmp_new_path));
|
2022-07-26 12:21:51 +00:00
|
|
|
if(error != FSE_OK) {
|
|
|
|
break;
|
|
|
|
}
|
2022-07-14 16:44:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-26 12:21:51 +00:00
|
|
|
error = storage_common_merge(
|
2022-10-05 15:15:23 +00:00
|
|
|
storage, furi_string_get_cstr(path), furi_string_get_cstr(tmp_new_path));
|
2022-07-14 16:44:34 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
if(error != FSE_OK) {
|
|
|
|
break;
|
|
|
|
}
|
2022-07-14 16:44:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while(false);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(tmp_new_path);
|
|
|
|
furi_string_free(file_basename);
|
|
|
|
furi_string_free(path);
|
2022-07-14 16:44:34 +00:00
|
|
|
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;
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* new_path_next;
|
|
|
|
new_path_next = furi_string_alloc();
|
2022-07-14 16:44:34 +00:00
|
|
|
|
|
|
|
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) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_set(new_path_next, new_path);
|
|
|
|
FuriString* dir_path;
|
|
|
|
FuriString* filename;
|
2022-07-14 16:44:34 +00:00
|
|
|
char extension[MAX_EXT_LEN];
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
dir_path = furi_string_alloc();
|
|
|
|
filename = furi_string_alloc();
|
2022-07-14 16:44:34 +00:00
|
|
|
|
|
|
|
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,
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(dir_path),
|
|
|
|
furi_string_get_cstr(filename),
|
2022-07-14 16:44:34 +00:00
|
|
|
extension,
|
|
|
|
new_path_next,
|
|
|
|
255);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_cat_printf(
|
|
|
|
dir_path, "/%s%s", furi_string_get_cstr(new_path_next), extension);
|
|
|
|
furi_string_set(new_path_next, dir_path);
|
2022-07-14 16:44:34 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(dir_path);
|
|
|
|
furi_string_free(filename);
|
|
|
|
new_path_tmp = furi_string_get_cstr(new_path_next);
|
2022-07-14 16:44:34 +00:00
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(new_path_next);
|
2022-07-14 16:44:34 +00: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 12:20:19 +00: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 10:46:45 +00: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 12:20:19 +00: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 19:53:46 +00:00
|
|
|
File* file = malloc(sizeof(File));
|
2022-04-27 16:16:06 +00: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 12:20:19 +00:00
|
|
|
file->storage = storage;
|
|
|
|
|
2022-10-07 13:35:15 +00:00
|
|
|
FURI_LOG_T(TAG, "File/Dir %p alloc", (void*)((uint32_t)file - SRAM_BASE));
|
2022-04-27 16:16:06 +00: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 12:20:19 +00:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool storage_file_is_open(File* file) {
|
2022-04-27 16:16:06 +00: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 12:20:19 +00:00
|
|
|
}
|
|
|
|
|
2022-04-04 12:27:48 +00:00
|
|
|
bool storage_file_is_dir(File* file) {
|
2022-04-27 16:16:06 +00:00
|
|
|
return (file->type == FileTypeOpenDir);
|
2022-04-04 12:27:48 +00: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 12:20:19 +00:00
|
|
|
void storage_file_free(File* file) {
|
|
|
|
if(storage_file_is_open(file)) {
|
2022-04-04 12:27:48 +00: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 12:20:19 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 13:35:15 +00:00
|
|
|
FURI_LOG_T(TAG, "File/Dir %p free", (void*)((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 12:20:19 +00:00
|
|
|
free(file);
|
2021-10-06 09:40:28 +00:00
|
|
|
}
|
|
|
|
|
2021-11-24 16:21:12 +00:00
|
|
|
FuriPubSub* storage_get_pubsub(Storage* storage) {
|
|
|
|
return storage->pubsub;
|
|
|
|
}
|
|
|
|
|
2021-10-26 16:05:28 +00:00
|
|
|
bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
|
|
|
furi_assert(storage);
|
|
|
|
furi_assert(path);
|
|
|
|
FileInfo fileinfo;
|
|
|
|
bool result = false;
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* fullname;
|
|
|
|
FuriString* cur_dir;
|
2021-10-26 16:05:28 +00:00
|
|
|
|
|
|
|
if(storage_simply_remove(storage, path)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-18 19:53:46 +00:00
|
|
|
char* name = malloc(MAX_NAME_LENGTH + 1);
|
2021-10-26 16:05:28 +00:00
|
|
|
File* dir = storage_file_alloc(storage);
|
2022-10-05 15:15:23 +00:00
|
|
|
cur_dir = furi_string_alloc_set(path);
|
2021-10-26 16:05:28 +00:00
|
|
|
bool go_deeper = false;
|
|
|
|
|
|
|
|
while(1) {
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!storage_dir_open(dir, furi_string_get_cstr(cur_dir))) {
|
2021-10-26 16:05:28 +00:00
|
|
|
storage_dir_close(dir);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH)) {
|
|
|
|
if(fileinfo.flags & FSF_DIRECTORY) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_cat_printf(cur_dir, "/%s", name);
|
2021-10-26 16:05:28 +00:00
|
|
|
go_deeper = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
fullname = furi_string_alloc_printf("%s/%s", furi_string_get_cstr(cur_dir), name);
|
|
|
|
FS_Error error = storage_common_remove(storage, furi_string_get_cstr(fullname));
|
2021-11-28 18:28:19 +00:00
|
|
|
furi_check(error == FSE_OK);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(fullname);
|
2021-10-26 16:05:28 +00:00
|
|
|
}
|
|
|
|
storage_dir_close(dir);
|
|
|
|
|
|
|
|
if(go_deeper) {
|
|
|
|
go_deeper = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FS_Error error = storage_common_remove(storage, furi_string_get_cstr(cur_dir));
|
2021-11-28 18:28:19 +00:00
|
|
|
furi_check(error == FSE_OK);
|
2021-10-26 16:05:28 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_cmp(cur_dir, path)) {
|
|
|
|
size_t last_char = furi_string_search_rchar(cur_dir, '/');
|
|
|
|
furi_assert(last_char != FURI_STRING_FAILURE);
|
|
|
|
furi_string_left(cur_dir, last_char);
|
2021-10-26 16:05:28 +00:00
|
|
|
} else {
|
|
|
|
result = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
storage_file_free(dir);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(cur_dir);
|
2021-10-26 16:05:28 +00:00
|
|
|
free(name);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-10-06 09:40:28 +00: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 16:05:28 +00:00
|
|
|
}
|
2021-11-11 12:49:19 +00:00
|
|
|
|
|
|
|
void storage_get_next_filename(
|
|
|
|
Storage* storage,
|
|
|
|
const char* dirname,
|
|
|
|
const char* filename,
|
|
|
|
const char* fileextension,
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* nextfilename,
|
2022-04-07 11:47:47 +00:00
|
|
|
uint8_t max_len) {
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* temp_str;
|
2021-11-11 12:49:19 +00:00
|
|
|
uint16_t num = 0;
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
temp_str = furi_string_alloc_printf("%s/%s%s", dirname, filename, fileextension);
|
2021-11-11 12:49:19 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
while(storage_common_stat(storage, furi_string_get_cstr(temp_str), NULL) == FSE_OK) {
|
2021-11-11 12:49:19 +00:00
|
|
|
num++;
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(temp_str, "%s/%s%d%s", dirname, filename, num, fileextension);
|
2021-11-11 12:49:19 +00:00
|
|
|
}
|
2022-04-07 11:47:47 +00:00
|
|
|
if(num && (max_len > strlen(filename))) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(nextfilename, "%s%d", filename, num);
|
2021-11-11 12:49:19 +00:00
|
|
|
} else {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(nextfilename, "%s", filename);
|
2021-11-11 12:49:19 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(temp_str);
|
2021-11-11 12:49:19 +00:00
|
|
|
}
|