From 4f50942937955ca7e811ea36f7ea1f7ce66e2038 Mon Sep 17 00:00:00 2001 From: Arnaud SINTES Date: Mon, 6 Nov 2023 09:14:42 +0100 Subject: [PATCH] fio in MB --- src/fio-ml.c | 20 +++++++++----------- src/fio-ml.h | 8 ++++---- src/lens.c | 8 ++++++-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/fio-ml.c b/src/fio-ml.c index 0f9f2ba15..245eb51ca 100644 --- a/src/fio-ml.c +++ b/src/fio-ml.c @@ -83,10 +83,9 @@ struct actual_cards_t *get_actual_cards() // reference active cards and increment actual card count: actual_cards.infos[actual_cards.count++] = p_card_info; // compute card total space: - double free_space_GB = ((double)(((uint64_t)get_free_space_32k(p_card_info)) << 5) / (1024 * 1024)); - p_card_info->total_space_GB = free_space_GB + get_folder_size_GB(get_dcim_dir_ex(p_card_info)); - // compute free space approximation: - update_free_space(p_card_info); + p_card_info->free_space_MB = ((uint64_t)get_free_space_32k(p_card_info)) >> 5; + uint64_t dcim_size_MB = get_folder_size_MB(get_dcim_dir_ex(p_card_info)); + p_card_info->total_space_MB = p_card_info->free_space_MB + dcim_size_MB; } } return &actual_cards; @@ -100,9 +99,8 @@ int get_free_space_32k(const struct card_info* card) void update_free_space(struct card_info *_p_card_info) { // approximate free space based of total space and current DCIM folder content size: - double dcim_size_GB = get_folder_size_GB(get_dcim_dir_ex(_p_card_info)); - int free_space_GB = (int)(_p_card_info->total_space_GB - dcim_size_GB); - _p_card_info->free_space_GB = (free_space_GB > 999) ? 999 : free_space_GB; + uint64_t dcim_size_MB = get_folder_size_MB(get_dcim_dir_ex(_p_card_info)); + _p_card_info->free_space_MB = _p_card_info->total_space_MB - dcim_size_MB; } @@ -370,7 +368,7 @@ const char* get_dcim_dir() return get_dcim_dir_ex(SHOOTING_CARD); } -double get_folder_size_GB(char *_folder) +uint64_t get_folder_size_MB(const char *_folder) { struct fio_file file; struct fio_dirent *dirent = FIO_FindFirstEx(_folder, &file); @@ -378,17 +376,17 @@ double get_folder_size_GB(char *_folder) { return 0; } - double cumulated_size_GB = 0; + uint64_t cumulated_size_KB = 0; do { if (file.name[0] == 0 || file.name[0] == '.' || (file.mode & ATTR_DIRECTORY)) { continue; } - cumulated_size_GB += (((double)file.size) / (1024 * 1024 * 1024)); + cumulated_size_KB += ((uint64_t)file.size) >> 10; } while (FIO_FindNextEx(dirent, &file) == 0); FIO_FindClose(dirent); - return cumulated_size_GB; + return cumulated_size_KB >> 10; } static void fixup_filename(char* new_filename, const char* old_filename, int size) diff --git a/src/fio-ml.h b/src/fio-ml.h index b5b3d09b4..9e6f91ba1 100644 --- a/src/fio-ml.h +++ b/src/fio-ml.h @@ -16,8 +16,8 @@ struct card_info { int folder_number; char * maker; /* only for some cameras; NULL otherwise */ char * model; - double total_space_GB; // initial estimation of total card space (GB) - int free_space_GB; // dynamic free space (GB) estimation + uint64_t total_space_MB; // initial estimation of total card space (MB) + uint64_t free_space_MB; // dynamic free space (MB) estimation }; struct actual_cards_t @@ -169,8 +169,8 @@ const char *get_dcim_dir_ex(struct card_info *_p_card_info); const char* get_dcim_dir(); const char* get_dcim_dir_suffix(); -// compute the cumulated file size (GB) of a given folder -double get_folder_size_GB(char *_folder); +// compute the cumulated file size (MB) of a given folder +uint64_t get_folder_size_MB(const char *_folder); extern int __attribute__((format(printf,2,3))) my_fprintf( diff --git a/src/lens.c b/src/lens.c index dfb5b79d1..c2a909e89 100644 --- a/src/lens.c +++ b/src/lens.c @@ -2955,15 +2955,19 @@ static LVINFO_UPDATE_FUNC(free_space_update) // setup display for 1 slot: struct card_info *p_card_1 = p_actual_cards->infos[0]; + int free_space_card_1_GB = (int)p_card_1->free_space_MB >> 10; + free_space_card_1_GB = (free_space_card_1_GB > 999) ? 999 : free_space_card_1_GB; if (p_actual_cards->count == 1) { - snprintf(buffer, sizeof(buffer), "%s:%d", p_card_1->type, p_card_1->free_space_GB); + snprintf(buffer, sizeof(buffer), "%s:%d", p_card_1->type, free_space_card_1_GB); } // setup display for 2 slots: else { struct card_info *p_card_2 = p_actual_cards->infos[1]; - snprintf(buffer, sizeof(buffer), "%s:%d %s:%d", p_card_1->type, p_card_1->free_space_GB, p_card_2->type, p_card_2->free_space_GB); + int free_space_card_2_GB = (int)p_card_2->free_space_MB >> 10; + free_space_card_2_GB = (free_space_card_2_GB > 999) ? 999 : free_space_card_2_GB; + snprintf(buffer, sizeof(buffer), "%s:%d %s:%d", p_card_1->type, free_space_card_1_GB, p_card_2->type, free_space_card_2_GB); } }