Storage: force mount (#3033)
* Storage: count opened files * Storage: sd mount * Storage: prompt to mount SD card if not mounted * F18: update API * F18: update API version * Fix logger naming scheme * Storage: storage_files_count -> storage_open_files_count Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#define TAG "SubGhz TEST"
|
||||
#define TAG "SubGhzTest"
|
||||
#define KEYSTORE_DIR_NAME EXT_PATH("subghz/assets/keeloq_mfcodes")
|
||||
#define CAME_ATOMO_DIR_NAME EXT_PATH("subghz/assets/came_atomo")
|
||||
#define NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s")
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <cc1101.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define TAG "SubGhz_Device_CC1101_Ext"
|
||||
#define TAG "SubGhzDeviceCc1101Ext"
|
||||
|
||||
#define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO &gpio_ext_pb2
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "cc1101_ext.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#define TAG "SubGhzDeviceCC1101Ext"
|
||||
#define TAG "SubGhzDeviceCc1101Ext"
|
||||
|
||||
static bool subghz_device_cc1101_ext_interconnect_is_frequency_valid(uint32_t frequency) {
|
||||
bool ret = subghz_device_cc1101_ext_is_frequency_valid(frequency);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <toolbox/stream/file_stream.h>
|
||||
|
||||
// Define log tag
|
||||
#define TAG "example_apps_assets"
|
||||
#define TAG "ExampleAppsAssets"
|
||||
|
||||
static void example_apps_data_print_file_content(Storage* storage, const char* path) {
|
||||
Stream* stream = file_stream_alloc(storage);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <storage/storage.h>
|
||||
|
||||
// Define log tag
|
||||
#define TAG "example_apps_data"
|
||||
#define TAG "ExampleAppsData"
|
||||
|
||||
// Application entry point
|
||||
int32_t example_apps_data_main(void* p) {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <loader/firmware_api/firmware_api.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
#define TAG "example_plugins"
|
||||
#define TAG "ExamplePlugins"
|
||||
|
||||
int32_t example_plugins_app(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "example_plugins"
|
||||
#define TAG "ExamplePlugins"
|
||||
|
||||
int32_t example_plugins_multi_app(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <loader/firmware_api/firmware_api.h>
|
||||
|
||||
#define TAG "example_advanced_plugins"
|
||||
#define TAG "ExampleAdvancedPlugins"
|
||||
|
||||
int32_t example_advanced_plugins_app(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "ducky_script_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
#define TAG "BadUSB"
|
||||
#define TAG "BadUsb"
|
||||
#define WORKER_TAG TAG "Worker"
|
||||
|
||||
#define BADUSB_ASCII_TO_KEY(script, x) \
|
||||
|
||||
@@ -171,7 +171,7 @@ static const DuckyCmd ducky_commands[] = {
|
||||
{"WAIT_FOR_BUTTON_PRESS", ducky_fnc_waitforbutton, -1},
|
||||
};
|
||||
|
||||
#define TAG "BadUSB"
|
||||
#define TAG "BadUsb"
|
||||
#define WORKER_TAG TAG "Worker"
|
||||
|
||||
int32_t ducky_execute_cmd(BadUsbScript* bad_usb, const char* line) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <toolbox/path.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
#define TAG "iButtonApp"
|
||||
#define TAG "IButtonApp"
|
||||
|
||||
static const NotificationSequence sequence_blink_set_yellow = {
|
||||
&message_blink_set_color_yellow,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <lib/toolbox/path.h>
|
||||
|
||||
#define RAW_FILE_NAME "Raw_signal_"
|
||||
#define TAG "SubGhzSceneReadRAW"
|
||||
#define TAG "SubGhzSceneReadRaw"
|
||||
|
||||
bool subghz_scene_read_raw_update_filename(SubGhz* subghz) {
|
||||
bool ret = false;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#define SUBGHZ_REGION_FILENAME "/int/.region_data"
|
||||
|
||||
#define TAG "SubGhz CLI"
|
||||
#define TAG "SubGhzCli"
|
||||
|
||||
static void subghz_cli_radio_device_power_on() {
|
||||
uint8_t attempts = 5;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <assets_icons.h>
|
||||
#define SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE 100
|
||||
#define TAG "SubGhzReadRAW"
|
||||
#define TAG "SubGhzReadRaw"
|
||||
|
||||
struct SubGhzReadRAW {
|
||||
View* view;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "hmac_sha256.h"
|
||||
#include "micro-ecc/uECC.h"
|
||||
|
||||
#define TAG "U2F"
|
||||
#define TAG "U2f"
|
||||
#define WORKER_TAG TAG "Worker"
|
||||
|
||||
#define U2F_CMD_REGISTER 0x01
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <furi_hal_random.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
|
||||
#define TAG "U2F"
|
||||
#define TAG "U2f"
|
||||
|
||||
#define U2F_DATA_FOLDER EXT_PATH("u2f/")
|
||||
#define U2F_CERT_FILE U2F_DATA_FOLDER "assets/cert.der"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include <furi_hal_console.h>
|
||||
|
||||
#define TAG "U2FHID"
|
||||
#define TAG "U2fHid"
|
||||
#define WORKER_TAG TAG "Worker"
|
||||
|
||||
#define U2F_HID_MAX_PAYLOAD_LEN ((HID_U2F_PACKET_LEN - 7) + 128 * (HID_U2F_PACKET_LEN - 5))
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#define ICON_SD_MOUNTED &I_SDcardMounted_11x8
|
||||
#define ICON_SD_ERROR &I_SDcardFail_11x8
|
||||
|
||||
#define TAG RECORD_STORAGE
|
||||
#define TAG "Storage"
|
||||
|
||||
static void storage_app_sd_icon_draw_callback(Canvas* canvas, void* context) {
|
||||
furi_assert(canvas);
|
||||
|
||||
@@ -334,12 +334,20 @@ const char* storage_file_get_error_desc(File* file);
|
||||
*/
|
||||
FS_Error storage_sd_format(Storage* api);
|
||||
|
||||
/** Will unmount the SD card
|
||||
/** Will unmount the SD card.
|
||||
* Will return FSE_NOT_READY if the SD card is not mounted.
|
||||
* Will return FSE_DENIED if there are open files on the SD card.
|
||||
* @param api pointer to the api
|
||||
* @return FS_Error operation result
|
||||
*/
|
||||
FS_Error storage_sd_unmount(Storage* api);
|
||||
|
||||
/** Will mount the SD card
|
||||
* @param api pointer to the api
|
||||
* @return FS_Error operation result
|
||||
*/
|
||||
FS_Error storage_sd_mount(Storage* api);
|
||||
|
||||
/** Retrieves SD card information
|
||||
* @param api pointer to the api
|
||||
* @param info pointer to the info
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#define MAX_EXT_LEN 16
|
||||
#define FILE_BUFFER_SIZE 512
|
||||
|
||||
#define TAG "StorageAPI"
|
||||
#define TAG "StorageApi"
|
||||
|
||||
#define S_API_PROLOGUE FuriApiLock lock = api_lock_alloc_locked();
|
||||
|
||||
@@ -781,6 +781,14 @@ FS_Error storage_sd_unmount(Storage* storage) {
|
||||
return S_RETURN_ERROR;
|
||||
}
|
||||
|
||||
FS_Error storage_sd_mount(Storage* storage) {
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {};
|
||||
S_API_MESSAGE(StorageCommandSDMount);
|
||||
S_API_EPILOGUE;
|
||||
return S_RETURN_ERROR;
|
||||
}
|
||||
|
||||
FS_Error storage_sd_info(Storage* storage, SDInfo* info) {
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "storage_glue.h"
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define TAG "StorageGlue"
|
||||
|
||||
/****************** storage file ******************/
|
||||
|
||||
void storage_file_init(StorageFile* obj) {
|
||||
@@ -149,3 +151,8 @@ bool storage_pop_storage_file(File* file, StorageData* storage) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t storage_open_files_count(StorageData* storage) {
|
||||
size_t count = StorageFileList_size(storage->files);
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ void* storage_get_storage_file_data(const File* file, StorageData* storage);
|
||||
void storage_push_storage_file(File* file, FuriString* path, StorageData* storage);
|
||||
bool storage_pop_storage_file(File* file, StorageData* storage);
|
||||
|
||||
size_t storage_open_files_count(StorageData* storage);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -141,6 +141,7 @@ typedef enum {
|
||||
StorageCommandSDInfo,
|
||||
StorageCommandSDStatus,
|
||||
StorageCommandCommonResolvePath,
|
||||
StorageCommandSDMount,
|
||||
} StorageCommand;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -418,12 +418,38 @@ static FS_Error storage_process_sd_format(Storage* app) {
|
||||
static FS_Error storage_process_sd_unmount(Storage* app) {
|
||||
FS_Error ret = FSE_OK;
|
||||
|
||||
if(storage_data_status(&app->storage[ST_EXT]) == StorageStatusNotReady) {
|
||||
ret = FSE_NOT_READY;
|
||||
} else {
|
||||
sd_unmount_card(&app->storage[ST_EXT]);
|
||||
storage_data_timestamp(&app->storage[ST_EXT]);
|
||||
}
|
||||
do {
|
||||
StorageData* storage = &app->storage[ST_EXT];
|
||||
if(storage_data_status(storage) == StorageStatusNotReady) {
|
||||
ret = FSE_NOT_READY;
|
||||
break;
|
||||
}
|
||||
|
||||
if(storage_open_files_count(storage)) {
|
||||
ret = FSE_DENIED;
|
||||
break;
|
||||
}
|
||||
|
||||
sd_unmount_card(storage);
|
||||
storage_data_timestamp(storage);
|
||||
} while(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FS_Error storage_process_sd_mount(Storage* app) {
|
||||
FS_Error ret = FSE_OK;
|
||||
|
||||
do {
|
||||
StorageData* storage = &app->storage[ST_EXT];
|
||||
if(storage_data_status(storage) != StorageStatusNotReady) {
|
||||
ret = FSE_NOT_READY;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = sd_mount_card(storage, true);
|
||||
storage_data_timestamp(storage);
|
||||
} while(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -630,6 +656,9 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
||||
case StorageCommandSDUnmount:
|
||||
message->return_data->error_value = storage_process_sd_unmount(app);
|
||||
break;
|
||||
case StorageCommandSDMount:
|
||||
message->return_data->error_value = storage_process_sd_mount(app);
|
||||
break;
|
||||
case StorageCommandSDInfo:
|
||||
message->return_data->error_value =
|
||||
storage_process_sd_info(app, message->data->sdinfo.info);
|
||||
|
||||
@@ -24,7 +24,7 @@ static FS_Error storage_ext_parse_error(SDError error);
|
||||
|
||||
/******************* Core Functions *******************/
|
||||
|
||||
static bool sd_mount_card(StorageData* storage, bool notify) {
|
||||
static bool sd_mount_card_internal(StorageData* storage, bool notify) {
|
||||
bool result = false;
|
||||
uint8_t counter = sd_max_mount_retry_count();
|
||||
uint8_t bsp_result;
|
||||
@@ -106,6 +106,32 @@ FS_Error sd_unmount_card(StorageData* storage) {
|
||||
return storage_ext_parse_error(error);
|
||||
}
|
||||
|
||||
FS_Error sd_mount_card(StorageData* storage, bool notify) {
|
||||
sd_mount_card_internal(storage, notify);
|
||||
FS_Error error;
|
||||
|
||||
if(storage->status != StorageStatusOK) {
|
||||
FURI_LOG_E(TAG, "sd init error: %s", storage_data_status_text(storage));
|
||||
if(notify) {
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
sd_notify_error(notification);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
error = FSE_INTERNAL;
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "card mounted");
|
||||
if(notify) {
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
sd_notify_success(notification);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
|
||||
error = FSE_OK;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
FS_Error sd_format_card(StorageData* storage) {
|
||||
#ifdef FURI_RAM_EXEC
|
||||
UNUSED(storage);
|
||||
@@ -222,25 +248,8 @@ static void storage_ext_tick_internal(StorageData* storage, bool notify) {
|
||||
if(sd_data->sd_was_present) {
|
||||
if(hal_sd_detect()) {
|
||||
FURI_LOG_I(TAG, "card detected");
|
||||
sd_mount_card(storage, notify);
|
||||
|
||||
if(storage->status != StorageStatusOK) {
|
||||
FURI_LOG_E(TAG, "sd init error: %s", storage_data_status_text(storage));
|
||||
if(notify) {
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
sd_notify_error(notification);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "card mounted");
|
||||
if(notify) {
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
sd_notify_success(notification);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
}
|
||||
|
||||
sd_data->sd_was_present = false;
|
||||
sd_mount_card(storage, notify);
|
||||
|
||||
if(!hal_sd_detect()) {
|
||||
FURI_LOG_I(TAG, "card removed while mounting");
|
||||
|
||||
@@ -8,6 +8,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
void storage_ext_init(StorageData* storage);
|
||||
FS_Error sd_mount_card(StorageData* storage, bool notify);
|
||||
FS_Error sd_unmount_card(StorageData* storage);
|
||||
FS_Error sd_format_card(StorageData* storage);
|
||||
FS_Error sd_card_info(StorageData* storage, SDInfo* sd_info);
|
||||
|
||||
@@ -31,12 +31,24 @@ void storage_settings_scene_start_on_enter(void* context) {
|
||||
StorageSettingsStartSubmenuIndexSDInfo,
|
||||
storage_settings_scene_start_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Unmount SD Card",
|
||||
StorageSettingsStartSubmenuIndexUnmount,
|
||||
storage_settings_scene_start_submenu_callback,
|
||||
app);
|
||||
|
||||
FS_Error sd_status = storage_sd_status(app->fs_api);
|
||||
if(sd_status != FSE_OK) {
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Mount SD Card",
|
||||
StorageSettingsStartSubmenuIndexUnmount,
|
||||
storage_settings_scene_start_submenu_callback,
|
||||
app);
|
||||
} else {
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Unmount SD Card",
|
||||
StorageSettingsStartSubmenuIndexUnmount,
|
||||
storage_settings_scene_start_submenu_callback,
|
||||
app);
|
||||
}
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Format SD Card",
|
||||
|
||||
+9
-5
@@ -12,13 +12,17 @@ void storage_settings_scene_unmount_confirm_on_enter(void* context) {
|
||||
DialogEx* dialog_ex = app->dialog_ex;
|
||||
|
||||
FS_Error sd_status = storage_sd_status(app->fs_api);
|
||||
|
||||
if(sd_status == FSE_NOT_READY) {
|
||||
dialog_ex_set_icon(dialog_ex, 72, 17, &I_DolphinCommon_56x48);
|
||||
dialog_ex_set_header(dialog_ex, "SD Card Not Mounted", 64, 3, AlignCenter, AlignTop);
|
||||
dialog_ex_set_header(dialog_ex, "Mount SD Card?", 64, 10, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(
|
||||
dialog_ex, "Try to reinsert\nor format SD\ncard.", 3, 19, AlignLeft, AlignTop);
|
||||
dialog_ex_set_center_button_text(dialog_ex, "Ok");
|
||||
dialog_ex,
|
||||
"This may turn off power\nfor external modules",
|
||||
64,
|
||||
32,
|
||||
AlignCenter,
|
||||
AlignCenter);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Cancel");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "Mount");
|
||||
} else {
|
||||
dialog_ex_set_header(dialog_ex, "Unmount SD Card?", 64, 10, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(
|
||||
|
||||
@@ -9,22 +9,41 @@ static void
|
||||
|
||||
void storage_settings_scene_unmounted_on_enter(void* context) {
|
||||
StorageSettings* app = context;
|
||||
FS_Error error = storage_sd_unmount(app->fs_api);
|
||||
DialogEx* dialog_ex = app->dialog_ex;
|
||||
|
||||
FS_Error sd_status = storage_sd_status(app->fs_api);
|
||||
if(sd_status == FSE_NOT_READY) {
|
||||
FS_Error error = storage_sd_mount(app->fs_api);
|
||||
if(error == FSE_OK) {
|
||||
dialog_ex_set_header(dialog_ex, "SD Card Mounted", 64, 3, AlignCenter, AlignTop);
|
||||
dialog_ex_set_text(
|
||||
dialog_ex, "Flipper can use\nSD card now.", 3, 22, AlignLeft, AlignTop);
|
||||
notification_message(app->notification, &sequence_blink_green_100);
|
||||
} else {
|
||||
dialog_ex_set_header(dialog_ex, "Cannot Mount SD Card", 64, 3, AlignCenter, AlignTop);
|
||||
dialog_ex_set_text(
|
||||
dialog_ex, storage_error_get_desc(error), 3, 22, AlignLeft, AlignTop);
|
||||
notification_message(app->notification, &sequence_blink_red_100);
|
||||
}
|
||||
} else {
|
||||
FS_Error error = storage_sd_unmount(app->fs_api);
|
||||
if(error == FSE_OK) {
|
||||
dialog_ex_set_header(dialog_ex, "SD Card Unmounted", 64, 3, AlignCenter, AlignTop);
|
||||
dialog_ex_set_text(
|
||||
dialog_ex, "You can remove\nSD card now.", 3, 22, AlignLeft, AlignTop);
|
||||
notification_message(app->notification, &sequence_blink_green_100);
|
||||
} else {
|
||||
dialog_ex_set_header(
|
||||
dialog_ex, "Cannot Unmount SD Card", 64, 3, AlignCenter, AlignTop);
|
||||
dialog_ex_set_text(
|
||||
dialog_ex, storage_error_get_desc(error), 3, 22, AlignLeft, AlignTop);
|
||||
notification_message(app->notification, &sequence_blink_red_100);
|
||||
}
|
||||
}
|
||||
|
||||
dialog_ex_set_center_button_text(dialog_ex, "OK");
|
||||
dialog_ex_set_icon(dialog_ex, 72, 17, &I_DolphinCommon_56x48);
|
||||
|
||||
if(error == FSE_OK) {
|
||||
dialog_ex_set_header(dialog_ex, "SD Card Unmounted", 64, 3, AlignCenter, AlignTop);
|
||||
dialog_ex_set_text(dialog_ex, "You can remove\nSD card now.", 3, 22, AlignLeft, AlignTop);
|
||||
notification_message(app->notification, &sequence_blink_green_100);
|
||||
} else {
|
||||
dialog_ex_set_header(dialog_ex, "Cannot Unmount SD Card", 64, 3, AlignCenter, AlignTop);
|
||||
dialog_ex_set_text(dialog_ex, storage_error_get_desc(error), 3, 22, AlignLeft, AlignTop);
|
||||
notification_message(app->notification, &sequence_blink_red_100);
|
||||
}
|
||||
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
dialog_ex_set_result_callback(dialog_ex, storage_settings_scene_unmounted_dialog_callback);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <toolbox/tar/tar_archive.h>
|
||||
#include <toolbox/crc32_calc.h>
|
||||
|
||||
#define TAG "UpdWorkerRAM"
|
||||
#define TAG "UpdWorkerRam"
|
||||
|
||||
#define STM_DFU_VENDOR_ID 0x0483
|
||||
#define STM_DFU_PRODUCT_ID 0xDF11
|
||||
|
||||
Reference in New Issue
Block a user