[FL-2675] /int space reservation (#1448)

* storage: added global #defines for /int, /ext & /any
* storage: introduced PATH_EXT, PATH_INT& PATH_ANY macros
* core apps: moved hardcoded config files names to separate headers; prefixed them with "."; updater: added file name migration to new naming convention on backup extraction
* storage: fixed storage_merge_recursive handling of complex directory structures; storage_move_to_sd: changed data migration logic to all non-dot files & all folders
* core: added macro aliases for core record names
* Bumped protobuf commit pointer
* storage: reserved 5 pages in /int; denying write&creation of non-dot files when running out of free space

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
hedger
2022-07-26 15:21:51 +03:00
committed by GitHub
parent 52a83fc929
commit 056446dfed
171 changed files with 1111 additions and 910 deletions

View File

@@ -3,7 +3,7 @@ App(
name="StorageMoveToSd",
apptype=FlipperAppType.SYSTEM,
entry_point="storage_move_to_sd_app",
requires=["gui","storage"],
requires=["gui", "storage"],
provides=["storage_move_to_sd_start"],
stack_size=2 * 1024,
order=30,
@@ -16,4 +16,3 @@ App(
requires=["storage"],
order=120,
)

View File

@@ -4,66 +4,78 @@
#include "loader/loader.h"
#include "m-string.h"
#include <stdint.h>
#include <toolbox/dir_walk.h>
#include <toolbox/path.h>
#define TAG "MoveToSd"
#define MOVE_SRC "/int"
#define MOVE_DST "/ext"
#define MOVE_SRC STORAGE_INT_PATH_PREFIX
#define MOVE_DST STORAGE_EXT_PATH_PREFIX
static const char* app_dirs[] = {
"subghz",
"lfrfid",
"nfc",
"infrared",
"ibutton",
"badusb",
};
bool storage_move_to_sd_perform(void) {
Storage* storage = furi_record_open("storage");
string_t path_src;
string_t path_dst;
string_init(path_src);
string_init(path_dst);
for(uint32_t i = 0; i < COUNT_OF(app_dirs); i++) {
string_printf(path_src, "%s/%s", MOVE_SRC, app_dirs[i]);
string_printf(path_dst, "%s/%s", MOVE_DST, app_dirs[i]);
storage_common_merge(storage, string_get_cstr(path_src), string_get_cstr(path_dst));
storage_simply_remove_recursive(storage, string_get_cstr(path_src));
static bool storage_move_to_sd_check_entry(const char* name, FileInfo* fileinfo, void* ctx) {
UNUSED(ctx);
if((fileinfo->flags & FSF_DIRECTORY) != 0) {
return true;
}
string_clear(path_src);
string_clear(path_dst);
return (name && (*name != '.'));
}
furi_record_close("storage");
bool storage_move_to_sd_perform(void) {
Storage* storage = furi_record_open(RECORD_STORAGE);
DirWalk* dir_walk = dir_walk_alloc(storage);
dir_walk_set_recursive(dir_walk, false);
dir_walk_set_filter_cb(dir_walk, storage_move_to_sd_check_entry, NULL);
string_t path_src, path_dst;
string_init(path_dst);
string_init(path_src);
if(dir_walk_open(dir_walk, STORAGE_INT_PATH_PREFIX)) {
while(dir_walk_read(dir_walk, path_src, NULL) == DirWalkOK) {
string_set(path_dst, path_src);
string_replace_at(
path_dst, 0, strlen(STORAGE_INT_PATH_PREFIX), STORAGE_EXT_PATH_PREFIX);
storage_common_merge(storage, string_get_cstr(path_src), string_get_cstr(path_dst));
storage_simply_remove_recursive(storage, string_get_cstr(path_src));
}
}
dir_walk_free(dir_walk);
string_clear(path_dst);
string_clear(path_src);
furi_record_close(RECORD_STORAGE);
return false;
}
static bool storage_move_to_sd_check(void) {
Storage* storage = furi_record_open("storage");
Storage* storage = furi_record_open(RECORD_STORAGE);
FileInfo file_info;
bool state = false;
string_t path;
string_init(path);
bool should_migrate = false;
for(uint32_t i = 0; i < COUNT_OF(app_dirs); i++) {
string_printf(path, "%s/%s", MOVE_SRC, app_dirs[i]);
if(storage_common_stat(storage, string_get_cstr(path), &file_info) == FSE_OK) {
if((file_info.flags & FSF_DIRECTORY) != 0) {
state = true;
break;
}
}
DirWalk* dir_walk = dir_walk_alloc(storage);
dir_walk_set_recursive(dir_walk, false);
dir_walk_set_filter_cb(dir_walk, storage_move_to_sd_check_entry, NULL);
string_t name;
string_init(name);
if(dir_walk_open(dir_walk, STORAGE_INT_PATH_PREFIX)) {
// if at least 1 entry is present, we should migrate
should_migrate = (dir_walk_read(dir_walk, name, NULL) == DirWalkOK);
}
string_clear(path);
dir_walk_free(dir_walk);
string_clear(name);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
return state;
return should_migrate;
}
static bool storage_move_to_sd_custom_event_callback(void* context, uint32_t event) {
@@ -92,8 +104,8 @@ static void storage_move_to_sd_unmount_callback(const void* message, void* conte
static StorageMoveToSd* storage_move_to_sd_alloc() {
StorageMoveToSd* app = malloc(sizeof(StorageMoveToSd));
app->gui = furi_record_open("gui");
app->notifications = furi_record_open("notification");
app->gui = furi_record_open(RECORD_GUI);
app->notifications = furi_record_open(RECORD_NOTIFICATION);
app->view_dispatcher = view_dispatcher_alloc();
app->scene_manager = scene_manager_alloc(&storage_move_to_sd_scene_handlers, app);
@@ -114,26 +126,26 @@ static StorageMoveToSd* storage_move_to_sd_alloc() {
scene_manager_next_scene(app->scene_manager, StorageMoveToSdConfirm);
Storage* storage = furi_record_open("storage");
Storage* storage = furi_record_open(RECORD_STORAGE);
app->sub = furi_pubsub_subscribe(
storage_get_pubsub(storage), storage_move_to_sd_unmount_callback, app);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
return app;
}
static void storage_move_to_sd_free(StorageMoveToSd* app) {
Storage* storage = furi_record_open("storage");
Storage* storage = furi_record_open(RECORD_STORAGE);
furi_pubsub_unsubscribe(storage_get_pubsub(storage), app->sub);
furi_record_close("storage");
furi_record_close("notification");
furi_record_close(RECORD_STORAGE);
furi_record_close(RECORD_NOTIFICATION);
view_dispatcher_remove_view(app->view_dispatcher, StorageMoveToSdViewWidget);
widget_free(app->widget);
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);
furi_record_close("gui");
furi_record_close(RECORD_GUI);
free(app);
}
@@ -159,18 +171,18 @@ static void storage_move_to_sd_mount_callback(const void* message, void* context
const StorageEvent* storage_event = message;
if(storage_event->type == StorageEventTypeCardMount) {
Loader* loader = furi_record_open("loader");
Loader* loader = furi_record_open(RECORD_LOADER);
loader_start(loader, "StorageMoveToSd", NULL);
furi_record_close("loader");
furi_record_close(RECORD_LOADER);
}
}
int32_t storage_move_to_sd_start(void* p) {
UNUSED(p);
Storage* storage = furi_record_open("storage");
Storage* storage = furi_record_open(RECORD_STORAGE);
furi_pubsub_subscribe(storage_get_pubsub(storage), storage_move_to_sd_mount_callback, NULL);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
return 0;
}