From 17f66c614f9470cf718efef384f734c7d551c628 Mon Sep 17 00:00:00 2001 From: Silent Date: Wed, 24 Jan 2024 18:56:31 +0100 Subject: [PATCH] SavedStruct: const-qualify saved_struct_save --- applications/services/bt/bt_settings.c | 2 +- applications/services/bt/bt_settings.h | 2 +- .../services/expansion/expansion_settings.c | 2 +- .../services/expansion/expansion_settings.h | 2 +- lib/toolbox/saved_struct.c | 13 +++++++++---- lib/toolbox/saved_struct.h | 7 ++++++- targets/f18/api_symbols.csv | 2 +- targets/f7/api_symbols.csv | 2 +- 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/applications/services/bt/bt_settings.c b/applications/services/bt/bt_settings.c index 1eaf6c7d70b..8a505f9e3f6 100644 --- a/applications/services/bt/bt_settings.c +++ b/applications/services/bt/bt_settings.c @@ -15,7 +15,7 @@ bool bt_settings_load(BtSettings* bt_settings) { BT_SETTINGS_PATH, bt_settings, sizeof(BtSettings), BT_SETTINGS_MAGIC, BT_SETTINGS_VERSION); } -bool bt_settings_save(BtSettings* bt_settings) { +bool bt_settings_save(const BtSettings* bt_settings) { furi_assert(bt_settings); return saved_struct_save( diff --git a/applications/services/bt/bt_settings.h b/applications/services/bt/bt_settings.h index 9ed8be89c4a..da43e149879 100644 --- a/applications/services/bt/bt_settings.h +++ b/applications/services/bt/bt_settings.h @@ -15,7 +15,7 @@ typedef struct { bool bt_settings_load(BtSettings* bt_settings); -bool bt_settings_save(BtSettings* bt_settings); +bool bt_settings_save(const BtSettings* bt_settings); #ifdef __cplusplus } diff --git a/applications/services/expansion/expansion_settings.c b/applications/services/expansion/expansion_settings.c index 586bf6e9cf8..691c454a57a 100644 --- a/applications/services/expansion/expansion_settings.c +++ b/applications/services/expansion/expansion_settings.c @@ -19,7 +19,7 @@ bool expansion_settings_load(ExpansionSettings* settings) { EXPANSION_SETTINGS_VERSION); } -bool expansion_settings_save(ExpansionSettings* settings) { +bool expansion_settings_save(const ExpansionSettings* settings) { furi_assert(settings); return saved_struct_save( EXPANSION_SETTINGS_PATH, diff --git a/applications/services/expansion/expansion_settings.h b/applications/services/expansion/expansion_settings.h index e7663f1b957..38e9f8d0258 100644 --- a/applications/services/expansion/expansion_settings.h +++ b/applications/services/expansion/expansion_settings.h @@ -36,7 +36,7 @@ bool expansion_settings_load(ExpansionSettings* settings); * @param[in] settings pointer to an ExpansionSettings instance to save settings from. * @returns true if the settings were successfully saved, false otherwise. */ -bool expansion_settings_save(ExpansionSettings* settings); +bool expansion_settings_save(const ExpansionSettings* settings); #ifdef __cplusplus } diff --git a/lib/toolbox/saved_struct.c b/lib/toolbox/saved_struct.c index 7ce0747b10a..db7e4de6e41 100644 --- a/lib/toolbox/saved_struct.c +++ b/lib/toolbox/saved_struct.c @@ -13,7 +13,12 @@ typedef struct { uint32_t timestamp; } SavedStructHeader; -bool saved_struct_save(const char* path, void* data, size_t size, uint8_t magic, uint8_t version) { +bool saved_struct_save( + const char* path, + const void* data, + size_t size, + uint8_t magic, + uint8_t version) { furi_check(path); furi_check(data); furi_check(size); @@ -35,7 +40,7 @@ bool saved_struct_save(const char* path, void* data, size_t size, uint8_t magic, if(result) { // Calculate checksum uint8_t checksum = 0; - uint8_t* source = data; + const uint8_t* source = data; for(size_t i = 0; i < size; i++) { checksum += source[i]; } @@ -162,8 +167,8 @@ bool saved_struct_get_metadata( *version = header.version; } if(payload_size) { - uint64_t file_size = storage_file_size(file); - *payload_size = file_size - sizeof(SavedStructHeader); + uint64_t file_size = storage_file_size(file); + *payload_size = file_size - sizeof(SavedStructHeader); } result = true; diff --git a/lib/toolbox/saved_struct.h b/lib/toolbox/saved_struct.h index fc87e23ae94..1baccaeac22 100644 --- a/lib/toolbox/saved_struct.h +++ b/lib/toolbox/saved_struct.h @@ -10,7 +10,12 @@ extern "C" { bool saved_struct_load(const char* path, void* data, size_t size, uint8_t magic, uint8_t version); -bool saved_struct_save(const char* path, void* data, size_t size, uint8_t magic, uint8_t version); +bool saved_struct_save( + const char* path, + const void* data, + size_t size, + uint8_t magic, + uint8_t version); bool saved_struct_get_metadata( const char* path, diff --git a/targets/f18/api_symbols.csv b/targets/f18/api_symbols.csv index c64f80f8a92..9133ea5c852 100644 --- a/targets/f18/api_symbols.csv +++ b/targets/f18/api_symbols.csv @@ -2304,7 +2304,7 @@ Function,+,rpc_system_app_set_error_text,void,"RpcAppSystem*, const char*" Function,-,rpmatch,int,const char* Function,+,saved_struct_get_metadata,_Bool,"const char*, uint8_t*, uint8_t*, size_t*" Function,+,saved_struct_load,_Bool,"const char*, void*, size_t, uint8_t, uint8_t" -Function,+,saved_struct_save,_Bool,"const char*, void*, size_t, uint8_t, uint8_t" +Function,+,saved_struct_save,_Bool,"const char*, const void*, size_t, uint8_t, uint8_t" Function,-,scalbln,double,"double, long int" Function,-,scalblnf,float,"float, long int" Function,-,scalblnl,long double,"long double, long" diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index 29b7d64f3db..9457f48c0d9 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -2864,7 +2864,7 @@ Function,+,rpc_system_app_set_error_text,void,"RpcAppSystem*, const char*" Function,-,rpmatch,int,const char* Function,+,saved_struct_get_metadata,_Bool,"const char*, uint8_t*, uint8_t*, size_t*" Function,+,saved_struct_load,_Bool,"const char*, void*, size_t, uint8_t, uint8_t" -Function,+,saved_struct_save,_Bool,"const char*, void*, size_t, uint8_t, uint8_t" +Function,+,saved_struct_save,_Bool,"const char*, const void*, size_t, uint8_t, uint8_t" Function,-,scalbln,double,"double, long int" Function,-,scalblnf,float,"float, long int" Function,-,scalblnl,long double,"long double, long"