[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

@@ -47,7 +47,7 @@ static RpcSessionContext rpc_session[TEST_RPC_SESSIONS];
#define MAX_NAME_LENGTH 255
#define MAX_DATA_SIZE 512u // have to be exact as in rpc_storage.c
#define TEST_DIR TEST_DIR_NAME "/"
#define TEST_DIR_NAME "/ext/unit_tests_tmp"
#define TEST_DIR_NAME EXT_PATH("unit_tests_tmp")
#define MD5SUM_SIZE 16
#define PING_REQUEST 0
@@ -83,7 +83,7 @@ static void test_rpc_setup(void) {
furi_check(!rpc);
furi_check(!(rpc_session[0].session));
rpc = furi_record_open("rpc");
rpc = furi_record_open(RECORD_RPC);
for(int i = 0; !(rpc_session[0].session) && (i < 10000); ++i) {
rpc_session[0].session = rpc_session_open(rpc);
furi_delay_tick(1);
@@ -125,7 +125,7 @@ static void test_rpc_teardown(void) {
xSemaphoreTake(rpc_session[0].terminate_semaphore, 0);
rpc_session_close(rpc_session[0].session);
furi_check(xSemaphoreTake(rpc_session[0].terminate_semaphore, portMAX_DELAY));
furi_record_close("rpc");
furi_record_close(RECORD_RPC);
vStreamBufferDelete(rpc_session[0].output_stream);
vSemaphoreDelete(rpc_session[0].close_session_semaphore);
vSemaphoreDelete(rpc_session[0].terminate_semaphore);
@@ -153,17 +153,17 @@ static void test_rpc_teardown_second_session(void) {
static void test_rpc_storage_setup(void) {
test_rpc_setup();
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
clean_directory(fs_api, TEST_DIR_NAME);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
}
static void test_rpc_storage_teardown(void) {
test_rpc_teardown();
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
clean_directory(fs_api, TEST_DIR_NAME);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
}
static void test_rpc_session_close_callback(void* context) {
@@ -571,7 +571,7 @@ static void test_rpc_storage_list_create_expected_list(
MsgList_t msg_list,
const char* path,
uint32_t command_id) {
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* dir = storage_file_alloc(fs_api);
PB_Main response = {
@@ -627,7 +627,7 @@ static void test_rpc_storage_list_create_expected_list(
storage_dir_close(dir);
storage_file_free(dir);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
}
static void test_rpc_decode_and_compare(MsgList_t expected_msg_list, uint8_t session) {
@@ -693,13 +693,13 @@ static void test_rpc_storage_list_run(const char* path, uint32_t command_id) {
MU_TEST(test_storage_list) {
test_rpc_storage_list_run("/", ++command_id);
test_rpc_storage_list_run("/ext/nfc", ++command_id);
test_rpc_storage_list_run(EXT_PATH("nfc"), ++command_id);
test_rpc_storage_list_run("/int", ++command_id);
test_rpc_storage_list_run("/ext", ++command_id);
test_rpc_storage_list_run("/ext/infrared", ++command_id);
test_rpc_storage_list_run("/ext/ibutton", ++command_id);
test_rpc_storage_list_run("/ext/lfrfid", ++command_id);
test_rpc_storage_list_run(STORAGE_INT_PATH_PREFIX, ++command_id);
test_rpc_storage_list_run(STORAGE_EXT_PATH_PREFIX, ++command_id);
test_rpc_storage_list_run(EXT_PATH("infrared"), ++command_id);
test_rpc_storage_list_run(EXT_PATH("ibutton"), ++command_id);
test_rpc_storage_list_run(EXT_PATH("lfrfid"), ++command_id);
test_rpc_storage_list_run("error_path", ++command_id);
}
@@ -718,7 +718,7 @@ static void test_rpc_add_read_to_list_by_reading_real_file(
const char* path,
uint32_t command_id) {
furi_check(MsgList_empty_p(msg_list));
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);
bool result = false;
@@ -759,7 +759,7 @@ static void test_rpc_add_read_to_list_by_reading_real_file(
storage_file_close(file);
storage_file_free(file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
}
static void test_storage_read_run(const char* path, uint32_t command_id) {
@@ -777,25 +777,25 @@ static void test_storage_read_run(const char* path, uint32_t command_id) {
}
static bool test_is_exists(const char* path) {
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
FileInfo fileinfo;
FS_Error result = storage_common_stat(fs_api, path, &fileinfo);
furi_check((result == FSE_OK) || (result == FSE_NOT_EXIST));
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
return result == FSE_OK;
}
static void test_create_dir(const char* path) {
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
FS_Error error = storage_common_mkdir(fs_api, path);
(void)error;
furi_check((error == FSE_OK) || (error == FSE_EXIST));
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
furi_check(test_is_exists(path));
}
static void test_create_file(const char* path, size_t size) {
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);
if(storage_file_open(file, path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
@@ -813,7 +813,7 @@ static void test_create_file(const char* path, size_t size) {
storage_file_close(file);
storage_file_free(file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
furi_check(test_is_exists(path));
}
@@ -827,7 +827,7 @@ static void test_rpc_storage_info_run(const char* path, uint32_t command_id) {
PB_Main* response = MsgList_push_new(expected_msg_list);
response->command_id = command_id;
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
FS_Error error = storage_common_fs_info(
fs_api,
@@ -856,10 +856,10 @@ static void test_rpc_storage_stat_run(const char* path, uint32_t command_id) {
test_rpc_create_simple_message(&request, PB_Main_storage_stat_request_tag, path, command_id);
Storage* fs_api = furi_record_open("storage");
Storage* fs_api = furi_record_open(RECORD_STORAGE);
FileInfo fileinfo;
FS_Error error = storage_common_stat(fs_api, path, &fileinfo);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
PB_Main* response = MsgList_push_new(expected_msg_list);
response->command_id = command_id;
@@ -884,9 +884,9 @@ static void test_rpc_storage_stat_run(const char* path, uint32_t command_id) {
}
MU_TEST(test_storage_info) {
test_rpc_storage_info_run("/any", ++command_id);
test_rpc_storage_info_run("/int", ++command_id);
test_rpc_storage_info_run("/ext", ++command_id);
test_rpc_storage_info_run(STORAGE_ANY_PATH_PREFIX, ++command_id);
test_rpc_storage_info_run(STORAGE_INT_PATH_PREFIX, ++command_id);
test_rpc_storage_info_run(STORAGE_EXT_PATH_PREFIX, ++command_id);
}
#define TEST_DIR_STAT_NAME TEST_DIR "stat_dir"
@@ -897,8 +897,8 @@ MU_TEST(test_storage_stat) {
test_create_file(TEST_DIR_STAT "l33t.txt", 1337);
test_rpc_storage_stat_run("/", ++command_id);
test_rpc_storage_stat_run("/int", ++command_id);
test_rpc_storage_stat_run("/ext", ++command_id);
test_rpc_storage_stat_run(STORAGE_INT_PATH_PREFIX, ++command_id);
test_rpc_storage_stat_run(STORAGE_EXT_PATH_PREFIX, ++command_id);
test_rpc_storage_stat_run(TEST_DIR_STAT "empty.txt", ++command_id);
test_rpc_storage_stat_run(TEST_DIR_STAT "l33t.txt", ++command_id);
@@ -1225,7 +1225,7 @@ MU_TEST(test_storage_mkdir) {
}
static void test_storage_calculate_md5sum(const char* path, char* md5sum) {
Storage* api = furi_record_open("storage");
Storage* api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(api);
if(storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING)) {
@@ -1257,7 +1257,7 @@ static void test_storage_calculate_md5sum(const char* path, char* md5sum) {
storage_file_close(file);
storage_file_free(file);
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
}
static void test_storage_md5sum_run(
@@ -1516,7 +1516,8 @@ static void test_app_get_status_lock_run(bool locked_expected, uint32_t command_
MU_TEST(test_app_start_and_lock_status) {
test_app_get_status_lock_run(false, ++command_id);
test_app_start_run(NULL, "/ext/file", PB_CommandStatus_ERROR_INVALID_PARAMETERS, ++command_id);
test_app_start_run(
NULL, EXT_PATH("file"), PB_CommandStatus_ERROR_INVALID_PARAMETERS, ++command_id);
test_app_start_run(NULL, NULL, PB_CommandStatus_ERROR_INVALID_PARAMETERS, ++command_id);
test_app_get_status_lock_run(false, ++command_id);
test_app_start_run(
@@ -1765,23 +1766,23 @@ MU_TEST_SUITE(test_rpc_session) {
MU_RUN_TEST(test_rpc_feed_rubbish);
MU_RUN_TEST(test_rpc_multisession_ping);
Storage* storage = furi_record_open("storage");
Storage* storage = furi_record_open(RECORD_STORAGE);
if(storage_sd_status(storage) != FSE_OK) {
FURI_LOG_E(TAG, "SD card not mounted - skip storage tests");
} else {
MU_RUN_TEST(test_rpc_multisession_storage);
}
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
}
int run_minunit_test_rpc() {
Storage* storage = furi_record_open("storage");
Storage* storage = furi_record_open(RECORD_STORAGE);
if(storage_sd_status(storage) != FSE_OK) {
FURI_LOG_E(TAG, "SD card not mounted - skip storage tests");
} else {
MU_RUN_SUITE(test_rpc_storage);
}
furi_record_close("storage");
furi_record_close(RECORD_STORAGE);
MU_RUN_SUITE(test_rpc_system);
MU_RUN_SUITE(test_rpc_app);
MU_RUN_SUITE(test_rpc_session);