Skip to content

Commit

Permalink
[FL-2675] /int space reservation (#1448)
Browse files Browse the repository at this point in the history
* 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: あく <[email protected]>
  • Loading branch information
hedger and skotopes authored Jul 26, 2022
1 parent 52a83fc commit 056446d
Show file tree
Hide file tree
Showing 171 changed files with 1,111 additions and 910 deletions.
8 changes: 4 additions & 4 deletions applications/about/about.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ const size_t about_screens_count = sizeof(about_screens) / sizeof(AboutDialogScr

int32_t about_settings_app(void* p) {
UNUSED(p);
DialogsApp* dialogs = furi_record_open("dialogs");
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
DialogMessage* message = dialog_message_alloc();

Gui* gui = furi_record_open("gui");
Gui* gui = furi_record_open(RECORD_GUI);
ViewDispatcher* view_dispatcher = view_dispatcher_alloc();
EmptyScreen* empty_screen = empty_screen_alloc();
const uint32_t empty_screen_index = 0;
Expand Down Expand Up @@ -198,12 +198,12 @@ int32_t about_settings_app(void* p) {
}

dialog_message_free(message);
furi_record_close("dialogs");
furi_record_close(RECORD_DIALOGS);

view_dispatcher_remove_view(view_dispatcher, empty_screen_index);
view_dispatcher_free(view_dispatcher);
empty_screen_free(empty_screen);
furi_record_close("gui");
furi_record_close(RECORD_GUI);

return 0;
}
4 changes: 2 additions & 2 deletions applications/archive/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bool archive_back_event_callback(void* context) {
ArchiveApp* archive_alloc() {
ArchiveApp* archive = malloc(sizeof(ArchiveApp));

archive->gui = furi_record_open("gui");
archive->gui = furi_record_open(RECORD_GUI);
archive->text_input = text_input_alloc();
string_init(archive->fav_move_str);

Expand Down Expand Up @@ -62,7 +62,7 @@ void archive_free(ArchiveApp* archive) {

text_input_free(archive->text_input);

furi_record_close("gui");
furi_record_close(RECORD_GUI);
archive->gui = NULL;

free(archive);
Expand Down
17 changes: 9 additions & 8 deletions applications/archive/helpers/archive_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ bool archive_app_is_available(void* context, const char* path) {

if(app == ArchiveAppTypeU2f) {
bool file_exists = false;
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);

file_exists = storage_file_open(file, "/any/u2f/key.u2f", FSAM_READ, FSOM_OPEN_EXISTING);
file_exists =
storage_file_open(file, ANY_PATH("u2f/key.u2f"), FSAM_READ, FSOM_OPEN_EXISTING);
if(file_exists) {
storage_file_close(file);
file_exists =
storage_file_open(file, "/any/u2f/cnt.u2f", FSAM_READ, FSOM_OPEN_EXISTING);
storage_file_open(file, ANY_PATH("u2f/cnt.u2f"), FSAM_READ, FSOM_OPEN_EXISTING);
if(file_exists) {
storage_file_close(file);
}
}

storage_file_free(file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);

return file_exists;
} else {
Expand Down Expand Up @@ -77,10 +78,10 @@ void archive_app_delete_file(void* context, const char* path) {
bool res = false;

if(app == ArchiveAppTypeU2f) {
Storage* fs_api = furi_record_open("storage");
res = (storage_common_remove(fs_api, "/any/u2f/key.u2f") == FSE_OK);
res |= (storage_common_remove(fs_api, "/any/u2f/cnt.u2f") == FSE_OK);
furi_record_close("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
res = (storage_common_remove(fs_api, ANY_PATH("u2f/key.u2f")) == FSE_OK);
res |= (storage_common_remove(fs_api, ANY_PATH("u2f/cnt.u2f")) == FSE_OK);
furi_record_close(RECORD_STORAGE);

if(archive_is_favorite("/app:u2f/U2F Token")) {
archive_favorites_delete("/app:u2f/U2F Token");
Expand Down
6 changes: 3 additions & 3 deletions applications/archive/helpers/archive_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,18 @@ void archive_favorites_move_mode(ArchiveBrowserView* browser, bool active) {
}

static bool archive_is_dir_exists(string_t path) {
if(string_equal_str_p(path, "/any")) {
if(string_equal_str_p(path, STORAGE_ANY_PATH_PREFIX)) {
return true;
}
bool state = false;
FileInfo file_info;
Storage* storage = furi_record_open("storage");
Storage* storage = furi_record_open(RECORD_STORAGE);
if(storage_common_stat(storage, string_get_cstr(path), &file_info) == FSE_OK) {
if(file_info.flags & FSF_DIRECTORY) {
state = true;
}
}
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
return state;
}

Expand Down
15 changes: 8 additions & 7 deletions applications/archive/helpers/archive_browser.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#pragma once

#include "../archive_i.h"
#include <storage/storage.h>

#define TAB_RIGHT InputKeyRight // Default tab swith direction
#define TAB_DEFAULT ArchiveTabFavorites // Start tab
#define FILE_LIST_BUF_LEN 100

static const char* tab_default_paths[] = {
[ArchiveTabFavorites] = "/app:favorites",
[ArchiveTabIButton] = "/any/ibutton",
[ArchiveTabNFC] = "/any/nfc",
[ArchiveTabSubGhz] = "/any/subghz",
[ArchiveTabLFRFID] = "/any/lfrfid",
[ArchiveTabInfrared] = "/any/infrared",
[ArchiveTabBadUsb] = "/any/badusb",
[ArchiveTabIButton] = ANY_PATH("ibutton"),
[ArchiveTabNFC] = ANY_PATH("nfc"),
[ArchiveTabSubGhz] = ANY_PATH("subghz"),
[ArchiveTabLFRFID] = ANY_PATH("lfrfid"),
[ArchiveTabInfrared] = ANY_PATH("infrared"),
[ArchiveTabBadUsb] = ANY_PATH("badusb"),
[ArchiveTabU2f] = "/app:u2f",
[ArchiveTabBrowser] = "/any",
[ArchiveTabBrowser] = STORAGE_ANY_PATH_PREFIX,
};

static const char* known_ext[] = {
Expand Down
28 changes: 14 additions & 14 deletions applications/archive/helpers/archive_favorites.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static bool archive_favorites_read_line(File* file, string_t str_result) {
uint16_t archive_favorites_count(void* context) {
furi_assert(context);

Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);

string_t buffer;
Expand All @@ -74,15 +74,15 @@ uint16_t archive_favorites_count(void* context) {

string_clear(buffer);
storage_file_free(file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);

return lines;
}

static bool archive_favourites_rescan() {
string_t buffer;
string_init(buffer);
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);
File* fav_item_file = storage_file_alloc(fs_api);

Expand Down Expand Up @@ -122,7 +122,7 @@ static bool archive_favourites_rescan() {

storage_file_free(file);
storage_file_free(fav_item_file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);

return result;
}
Expand All @@ -131,7 +131,7 @@ bool archive_favorites_read(void* context) {
furi_assert(context);

ArchiveBrowserView* browser = context;
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);
File* fav_item_file = storage_file_alloc(fs_api);

Expand Down Expand Up @@ -184,7 +184,7 @@ bool archive_favorites_read(void* context) {
string_clear(buffer);
storage_file_free(file);
storage_file_free(fav_item_file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);

archive_set_item_count(browser, file_count);

Expand All @@ -204,7 +204,7 @@ bool archive_favorites_delete(const char* format, ...) {
va_end(args);

string_init(buffer);
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);

bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
Expand Down Expand Up @@ -233,7 +233,7 @@ bool archive_favorites_delete(const char* format, ...) {
storage_common_remove(fs_api, ARCHIVE_FAV_TEMP_PATH);

storage_file_free(file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);

return result;
}
Expand All @@ -247,7 +247,7 @@ bool archive_is_favorite(const char* format, ...) {
va_end(args);

string_init(buffer);
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);

bool found = false;
Expand All @@ -272,7 +272,7 @@ bool archive_is_favorite(const char* format, ...) {
string_clear(buffer);
string_clear(filename);
storage_file_free(file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);

return found;
}
Expand All @@ -281,7 +281,7 @@ bool archive_favorites_rename(const char* src, const char* dst) {
furi_assert(src);
furi_assert(dst);

Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);

string_t path;
Expand Down Expand Up @@ -318,7 +318,7 @@ bool archive_favorites_rename(const char* src, const char* dst) {
storage_common_remove(fs_api, ARCHIVE_FAV_TEMP_PATH);

storage_file_free(file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);

return result;
}
Expand All @@ -333,7 +333,7 @@ void archive_favorites_save(void* context) {
furi_assert(context);

ArchiveBrowserView* browser = context;
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);

for(size_t i = 0; i < archive_file_get_array_size(browser); i++) {
Expand All @@ -346,5 +346,5 @@ void archive_favorites_save(void* context) {
storage_common_remove(fs_api, ARCHIVE_FAV_TEMP_PATH);

storage_file_free(file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
}
4 changes: 2 additions & 2 deletions applications/archive/helpers/archive_favorites.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <storage/storage.h>

#define ARCHIVE_FAV_PATH "/any/favorites.txt"
#define ARCHIVE_FAV_TEMP_PATH "/any/favorites.tmp"
#define ARCHIVE_FAV_PATH ANY_PATH("favorites.txt")
#define ARCHIVE_FAV_TEMP_PATH ANY_PATH("favorites.tmp")

uint16_t archive_favorites_count(void* context);
bool archive_favorites_read(void* context);
Expand Down
8 changes: 4 additions & 4 deletions applications/archive/helpers/archive_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void archive_file_append(const char* path, const char* format, ...) {
string_init_vprintf(string, format, args);
va_end(args);

Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);

bool res = storage_file_open(file, path, FSAM_WRITE, FSOM_OPEN_APPEND);
Expand All @@ -71,7 +71,7 @@ void archive_file_append(const char* path, const char* format, ...) {

storage_file_close(file);
storage_file_free(file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
}

void archive_delete_file(void* context, const char* format, ...) {
Expand All @@ -84,7 +84,7 @@ void archive_delete_file(void* context, const char* format, ...) {
va_end(args);

ArchiveBrowserView* browser = context;
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);

FileInfo fileinfo;
storage_common_stat(fs_api, string_get_cstr(filename), &fileinfo);
Expand All @@ -97,7 +97,7 @@ void archive_delete_file(void* context, const char* format, ...) {
res = (storage_common_remove(fs_api, string_get_cstr(filename)) == FSE_OK);
}

furi_record_close("storage");
furi_record_close(RECORD_STORAGE);

if(archive_is_favorite("%s", string_get_cstr(filename))) {
archive_favorites_delete("%s", string_get_cstr(filename));
Expand Down
16 changes: 8 additions & 8 deletions applications/archive/scenes/archive_scene_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void archive_loader_callback(const void* message, void* context) {

static void archive_run_in_app(ArchiveBrowserView* browser, ArchiveFile_t* selected) {
UNUSED(browser);
Loader* loader = furi_record_open("loader");
Loader* loader = furi_record_open(RECORD_LOADER);

LoaderStatus status;
if(selected->is_app) {
Expand All @@ -54,7 +54,7 @@ static void archive_run_in_app(ArchiveBrowserView* browser, ArchiveFile_t* selec
FURI_LOG_E(TAG, "loader_start failed: %d", status);
}

furi_record_close("loader");
furi_record_close(RECORD_LOADER);
}

void archive_scene_browser_callback(ArchiveBrowserEvent event, void* context) {
Expand All @@ -71,10 +71,10 @@ void archive_scene_browser_on_enter(void* context) {
archive_update_focus(browser, archive->text_store);
view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewBrowser);

Loader* loader = furi_record_open("loader");
Loader* loader = furi_record_open(RECORD_LOADER);
archive->loader_stop_subscription =
furi_pubsub_subscribe(loader_get_pubsub(loader), archive_loader_callback, archive);
furi_record_close("loader");
furi_record_close(RECORD_LOADER);

uint32_t state = scene_manager_get_scene_state(archive->scene_manager, ArchiveAppSceneBrowser);

Expand Down Expand Up @@ -196,10 +196,10 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
if(!archive_is_home(browser)) {
archive_leave_dir(browser);
} else {
Loader* loader = furi_record_open("loader");
Loader* loader = furi_record_open(RECORD_LOADER);
furi_pubsub_unsubscribe(
loader_get_pubsub(loader), archive->loader_stop_subscription);
furi_record_close("loader");
furi_record_close(RECORD_LOADER);

view_dispatcher_stop(archive->view_dispatcher);
}
Expand All @@ -216,7 +216,7 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
void archive_scene_browser_on_exit(void* context) {
ArchiveApp* archive = (ArchiveApp*)context;

Loader* loader = furi_record_open("loader");
Loader* loader = furi_record_open(RECORD_LOADER);
furi_pubsub_unsubscribe(loader_get_pubsub(loader), archive->loader_stop_subscription);
furi_record_close("loader");
furi_record_close(RECORD_LOADER);
}
4 changes: 2 additions & 2 deletions applications/archive/scenes/archive_scene_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SCENE_RENAME_CUSTOM_EVENT) {
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);

const char* path_src = archive_get_name(archive->browser);
ArchiveFile_t* file = archive_get_current_file(archive->browser);
Expand All @@ -62,7 +62,7 @@ bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {
string_cat_printf(path_dst, "/%s%s", archive->text_store, known_ext[file->type]);

storage_common_rename(fs_api, path_src, string_get_cstr(path_dst));
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);

if(file->fav) {
archive_favorites_rename(path_src, string_get_cstr(path_dst));
Expand Down
Loading

0 comments on commit 056446d

Please sign in to comment.