Skip to content

Commit

Permalink
fio-ml in MB
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-sintes committed Nov 6, 2023
1 parent 7b1e4cc commit 6c977fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
20 changes: 9 additions & 11 deletions src/fio-ml.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,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;
Expand All @@ -99,9 +98,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;
}

static CONFIG_INT("card.test", card_test_enabled, 1);
Expand Down Expand Up @@ -368,25 +366,25 @@ 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);
if (IS_ERROR(dirent))
{
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)
Expand Down
8 changes: 4 additions & 4 deletions src/fio-ml.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,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
Expand Down Expand Up @@ -159,8 +159,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(
Expand Down
8 changes: 6 additions & 2 deletions src/lens.c
Original file line number Diff line number Diff line change
Expand Up @@ -2950,15 +2950,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);
}
}

Expand Down

0 comments on commit 6c977fc

Please sign in to comment.