From d79167c9881dc841d4079c91ea09dd9ba2f119b6 Mon Sep 17 00:00:00 2001 From: chengyj1985 Date: Fri, 16 Sep 2022 10:35:32 +0800 Subject: [PATCH] Loss some precision while cast from 8 byte long to double Change-Id: I61bf0745de53bfc3b9e4ac677b85e0179603b180 --- lib/include/media-util.h | 6 +++--- src/common/include/media-common-utils.h | 5 +++-- src/common/media-common-utils.c | 8 ++++---- src/scanner-v2/media-scanner-db-manage-v2.c | 10 +++++----- src/scanner-v2/media-scanner-extract-v2.c | 2 +- src/scanner-v2/media-scanner-scan-v2.c | 22 +++++++++++----------- src/server/media-server-db-manage.c | 6 +++--- src/server/media-server-main.c | 6 +++--- 8 files changed, 33 insertions(+), 32 deletions(-) diff --git a/lib/include/media-util.h b/lib/include/media-util.h index e21e099..a99f7f8 100755 --- a/lib/include/media-util.h +++ b/lib/include/media-util.h @@ -42,9 +42,9 @@ #define MEDIA_SHARE_PATH tzplatform_getenv(TZ_SYS_MEDIASHARED) #endif -#define MEDIA_DB_SIZE_LIMIT_2 20000000.0 -#define MEDIA_DB_SIZE_LIMIT_1 10000000.0 -#define MEDIA_DB_SPACE_LIMIT 20971520.0 +#define MEDIA_DB_SIZE_LIMIT_2 20000000 +#define MEDIA_DB_SIZE_LIMIT_1 10000000 +#define MEDIA_DB_SPACE_LIMIT 20971520 #define MEDIA_DEFAULT_UID 5001 diff --git a/src/common/include/media-common-utils.h b/src/common/include/media-common-utils.h index c96b053..87604ae 100755 --- a/src/common/include/media-common-utils.h +++ b/src/common/include/media-common-utils.h @@ -23,13 +23,14 @@ #ifndef _MEDIA_SERVER_UTILS_H__ #define _MEDIA_SERVER_UTILS_H__ +#include #include "media-util.h" #include "media-common-types.h" bool ms_config_get_int(const char *key, int *value); bool ms_config_set_int(const char *key, int value); bool ms_config_get_str(const char *key, char **value); -int ms_get_remain_space(double *free_space); +int ms_get_remain_space(uint64_t *free_space); bool ms_is_valid_symlink(const char *path); int ms_check_file_path(const char *file_path, uid_t uid); @@ -39,7 +40,7 @@ bool ms_storage_mount_status(const char* start_path); int ms_set_db_status(ms_db_status_type_t status, ms_user_storage_type_e storage_type); int ms_set_power_mode(ms_db_status_type_t status); void ms_trim_dir_path(char *dir_path); -int ms_check_size_mediadb(uid_t uid, double *db_size); +int ms_check_size_mediadb(uid_t uid, uint64_t *db_size); #ifdef _USE_TVPD_MODE bool ms_is_support_pvr(void); int ms_set_vip_process(void); diff --git a/src/common/media-common-utils.c b/src/common/media-common-utils.c index 0901fe8..a90ead4 100644 --- a/src/common/media-common-utils.c +++ b/src/common/media-common-utils.c @@ -96,7 +96,7 @@ bool ms_config_get_str(const char *key, char **value) return false; } -int ms_get_remain_space(double *free_space) +int ms_get_remain_space(uint64_t *free_space) { int ret = MS_MEDIA_ERR_NONE; const char *path = "/opt"; @@ -110,7 +110,7 @@ int ms_get_remain_space(double *free_space) } /* f_bsize:unsigned long, f_bavail:fsblkcnt_t(unsigned long) */ - *free_space = (double)(s.f_bsize * s.f_bavail); + *free_space = (uint64_t)s.f_bsize * (uint64_t)s.f_bavail; return MS_MEDIA_ERR_NONE; } @@ -389,7 +389,7 @@ void ms_trim_dir_path(char *dir_path) dir_path[len -1] = '\0'; } -int ms_check_size_mediadb(uid_t uid, double *db_size) +int ms_check_size_mediadb(uid_t uid, uint64_t *db_size) { int ret = MS_MEDIA_ERR_NONE; char *db_path = NULL; @@ -398,7 +398,7 @@ int ms_check_size_mediadb(uid_t uid, double *db_size) ret = ms_user_get_media_db_path(uid, &db_path); if (stat(db_path, &buf) == 0) { - *db_size = buf.st_size; + *db_size = (uint64_t)buf.st_size; } else { MS_DBG_STRERROR("stat failed"); ret = MS_MEDIA_ERR_INTERNAL; diff --git a/src/scanner-v2/media-scanner-db-manage-v2.c b/src/scanner-v2/media-scanner-db-manage-v2.c index 074ec45..22b405c 100755 --- a/src/scanner-v2/media-scanner-db-manage-v2.c +++ b/src/scanner-v2/media-scanner-db-manage-v2.c @@ -28,20 +28,20 @@ int msc_check_db_size(uid_t uid, ms_msg_type_e msg_type) { - double db_size = 0.0; - double free_space = 0.0; + uint64_t db_size = 0; + uint64_t free_space = 0; int err = MS_MEDIA_ERR_NONE; ms_check_size_mediadb(uid, &db_size); if (msg_type == MS_MSG_STORAGE_ALL || msg_type == MS_MSG_STORAGE_PARTIAL) { if (db_size >= MEDIA_DB_SIZE_LIMIT_1) { - MS_DBG_ERR("DB SIZE [%lf] reach the MEDIA_DB_SIZE_LIMIT_1[%lf]", db_size, MEDIA_DB_SIZE_LIMIT_1); + MS_DBG_ERR("DB SIZE [%" PRIu64"] reach the MEDIA_DB_SIZE_LIMIT_1[%d]", db_size, MEDIA_DB_SIZE_LIMIT_1); return MS_MEDIA_ERR_DB_LIMIT_1; } } else if (msg_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE || msg_type == MS_MSG_DIRECTORY_SCANNING) { if (db_size >= MEDIA_DB_SIZE_LIMIT_2) { - MS_DBG_ERR("DB SIZE [%lf] reach the MEDIA_DB_SIZE_LIMIT_2[%lf]", db_size, MEDIA_DB_SIZE_LIMIT_2); + MS_DBG_ERR("DB SIZE [%" PRIu64"] reach the MEDIA_DB_SIZE_LIMIT_2[%d]", db_size, MEDIA_DB_SIZE_LIMIT_2); MS_DBG_WARN("START REMOVE INVALID DATA"); msc_cleanup_invalid_values(uid); @@ -64,7 +64,7 @@ int msc_check_db_size(uid_t uid, ms_msg_type_e msg_type) MS_DBG_ERR("ms_get_remain_space failed"); } else { if (free_space < MEDIA_DB_SPACE_LIMIT) { - MS_DBG_ERR("FREE SPACE [%lf] DB SIZE [%lf]", free_space, db_size); + MS_DBG_ERR("FREE SPACE [%" PRIu64"] DB SIZE [%" PRIu64"]", free_space, db_size); return MS_MEDIA_ERR_NOT_ENOUGH_SPACE; } } diff --git a/src/scanner-v2/media-scanner-extract-v2.c b/src/scanner-v2/media-scanner-extract-v2.c index 7b04768..35afee3 100644 --- a/src/scanner-v2/media-scanner-extract-v2.c +++ b/src/scanner-v2/media-scanner-extract-v2.c @@ -591,7 +591,7 @@ static int __msc_check_extract_stop_status(ms_msg_type_e msg_type, const char *s if ((strncmp(cancel_extract_item->path, start_path, strlen(cancel_extract_item->path)) == 0) && (cancel_extract_item->pid == -1 || cancel_extract_item->pid == pid)) { MS_DBG_SWARN("Receive cancel request [%s][%s]. STOP scan!!", cancel_extract_item->path, start_path); - unsigned int path_len = strlen(cancel_extract_item->path); + size_t path_len = strlen(cancel_extract_item->path); if (strlen(start_path) > path_len) { if (start_path[path_len] == '/') { diff --git a/src/scanner-v2/media-scanner-scan-v2.c b/src/scanner-v2/media-scanner-scan-v2.c index 0944f1a..d3406da 100644 --- a/src/scanner-v2/media-scanner-scan-v2.c +++ b/src/scanner-v2/media-scanner-scan-v2.c @@ -143,7 +143,7 @@ static int __msc_check_stop_status(ms_msg_type_e msg_type, const char *start_pat if ((strncmp(cancel_scan_item->path, start_path, strlen(cancel_scan_item->path)) == 0) && (cancel_scan_item->pid == -1 || cancel_scan_item->pid == pid)) { MS_DBG_SWARN("Receive cancel request [%s][%s]. STOP scan!!", cancel_scan_item->path, start_path); - unsigned int path_len = strlen(cancel_scan_item->path); + size_t path_len = strlen(cancel_scan_item->path); if (strlen(start_path) > path_len) { if (start_path[path_len] == '/') { @@ -617,7 +617,7 @@ static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_ static int __msc_check_scan_same_path(char *scan_path) { int ret = MS_MEDIA_ERR_NONE; - unsigned int storage_len, folder_len, min_len; + size_t storage_len, folder_len, min_len; g_mutex_lock(&storage_scan_mutex2); @@ -651,11 +651,11 @@ static void __msc_set_storage_scan_cur_path(char *scan_path) static int __msc_dir_and_storage_scan_same_path(char *start_path) { int ret = MS_MEDIA_ERR_NONE; - unsigned int storage_len, folder_len; + size_t storage_len, folder_len; char *storage_path = NULL; char *remain_path = NULL; - int remain_len = 0; + size_t remain_len = 0; if (!MS_STRING_VALID(MEDIA_ROOT_PATH_USB)) { MS_DBG_ERR("Fail to get USB path"); @@ -1267,7 +1267,7 @@ static void __msc_del_blocked_path(void) static int __msc_check_memory_status(uid_t uid) { int ret = MS_MEDIA_ERR_NONE; - double db_size = 0.0; + uint64_t db_size = 0; /*check remain space*/ ret = __msc_check_remain_space(uid); @@ -1276,7 +1276,7 @@ static int __msc_check_memory_status(uid_t uid) /*check db size*/ ms_check_size_mediadb(uid, &db_size); if (db_size >= MEDIA_DB_SIZE_LIMIT_1) { - MS_DBG_ERR("DB SIZE [%lf] REACH THE FIRST LIMIT [%lf]", db_size, MEDIA_DB_SIZE_LIMIT_1); + MS_DBG_ERR("DB SIZE [%" PRIu64"] REACH THE FIRST LIMIT [%d]", db_size, MEDIA_DB_SIZE_LIMIT_1); return MS_MEDIA_ERR_DB_LIMIT_1; } @@ -1286,15 +1286,15 @@ static int __msc_check_memory_status(uid_t uid) static int __msc_check_remain_space(uid_t uid) { int err = MS_MEDIA_ERR_NONE; - double free_space = 0.0; - double db_size = 0.0; + uint64_t free_space = 0; + uint64_t db_size = 0; err = ms_get_remain_space(&free_space); if (err != MS_MEDIA_ERR_NONE) { MS_DBG_ERR("ms_get_remain_space failed"); } else { if (free_space < MEDIA_DB_SPACE_LIMIT) { - MS_DBG_ERR("NOT ENOUGH SPACE WE DO NOT UPDATE MEDIA DB FREE SPACE [%lf]", free_space); + MS_DBG_ERR("NOT ENOUGH SPACE WE DO NOT UPDATE MEDIA DB FREE SPACE [%" PRIu64"]", free_space); ms_config_set_int(MS_DB_LIMIT, 0); @@ -1307,7 +1307,7 @@ static int __msc_check_remain_space(uid_t uid) MS_DBG_ERR("msc_check_dbsize failed"); } else { if (db_size >= MEDIA_DB_SIZE_LIMIT_2) { - MS_DBG_ERR("REACH LIMIT DB SIZE [%lf]", db_size); + MS_DBG_ERR("REACH LIMIT DB SIZE [%" PRIu64"]", db_size); MS_DBG_ERR("START REMOVE INVALID DATA"); msc_cleanup_invalid_values(uid); @@ -1318,7 +1318,7 @@ static int __msc_check_remain_space(uid_t uid) ms_config_set_int(MS_DB_LIMIT, 0); - MS_DBG_ERR("DB IS FULL. CANNOT UPDATE[%lf]", db_size); + MS_DBG_ERR("DB IS FULL. CANNOT UPDATE[%" PRIu64"]", db_size); return MS_MEDIA_ERR_DB_FULL_FAIL; } } diff --git a/src/server/media-server-db-manage.c b/src/server/media-server-db-manage.c index 5c9bd45..ad7e28d 100755 --- a/src/server/media-server-db-manage.c +++ b/src/server/media-server-db-manage.c @@ -102,14 +102,14 @@ static int __ms_remake_mediadb(uid_t uid) int ms_check_mediadb(uid_t uid, bool *is_reset) { - double db_size = 0.0; + uint64_t db_size = 0; ms_check_size_mediadb(uid, &db_size); - MS_DBG_WARN("[DB SIZE : %lf] [LIMIT1 : %lf] [LIMIT2 : %lf]", db_size, MEDIA_DB_SIZE_LIMIT_1, MEDIA_DB_SIZE_LIMIT_2); + MS_DBG_WARN("[DB SIZE : %" PRIu64"] [LIMIT1 : %d] [LIMIT2 : %d]", db_size, MEDIA_DB_SIZE_LIMIT_1, MEDIA_DB_SIZE_LIMIT_2); if (db_size > MEDIA_DB_SIZE_LIMIT_2) { MS_DBG_ERR("THE SIZE OF MEDIA DB REACH THE LIMIT. RESET MEDIA DB."); - MS_DBG_ERR("[DB SIZE : %lf] [LIMIT1 : %lf] [LIMIT2 : %lf]", db_size, MEDIA_DB_SIZE_LIMIT_1, MEDIA_DB_SIZE_LIMIT_2); + MS_DBG_ERR("[DB SIZE : %" PRIu64"] [LIMIT1 : %d] [LIMIT2 : %d]", db_size, MEDIA_DB_SIZE_LIMIT_1, MEDIA_DB_SIZE_LIMIT_2); __ms_remake_mediadb(uid); *is_reset = true; } diff --git a/src/server/media-server-main.c b/src/server/media-server-main.c index af06590..87dfd6e 100644 --- a/src/server/media-server-main.c +++ b/src/server/media-server-main.c @@ -285,8 +285,8 @@ int main(int argc, char **argv) #ifdef _USE_TVPD_MODE uid_t uid = MEDIA_DEFAULT_UID; - double db_size = 0.0; - double free_space = 0.0; + uint64_t db_size = 0; + uint64_t free_space = 0; __ms_deal_reset_status(); #endif @@ -297,7 +297,7 @@ int main(int argc, char **argv) #ifdef _USE_TVPD_MODE ms_check_size_mediadb(uid, &db_size); ms_get_remain_space(&free_space); - MS_DBG_WARN("DB SIZE[%lf] LIMIT1[%lf] LIMIT2[%lf] FREE SPACE[%lf] SPACE LIMIT[%lf]", db_size, MEDIA_DB_SIZE_LIMIT_1, MEDIA_DB_SIZE_LIMIT_2, free_space, MEDIA_DB_SPACE_LIMIT); + MS_DBG_WARN("DB SIZE[%" PRIu64"] LIMIT1[%d] LIMIT2[%d] FREE SPACE[%" PRIu64"] SPACE LIMIT[%d]", db_size, MEDIA_DB_SIZE_LIMIT_1, MEDIA_DB_SIZE_LIMIT_2, free_space, MEDIA_DB_SPACE_LIMIT); if (db_size > MEDIA_DB_SIZE_LIMIT_2) { MS_DBG_ERR("THE SIZE OF MEDIA DB REACH THE LIMIT. RESET MEDIA DB."); -- 2.7.4