diff --git a/project/Core/Src/llfs.c b/project/Core/Src/llfs.c index 31e1f1c..818051f 100644 --- a/project/Core/Src/llfs.c +++ b/project/Core/Src/llfs.c @@ -41,6 +41,14 @@ int8_t llfs_init(void) { file_table[STDOUT_FILENO] = stdout; file_table[STDERR_FILENO] = stderr; + // Calculate the number of files in the filesystem and cache it + const struct llfs_data_file* file = llfs_root; + file_count = 0; + while (file != NULL) { + file_count++; + file = file->next; + } + return 0; } @@ -130,13 +138,6 @@ llfs_file_t* llfs_next_file(void** mem, char* filter) { } size_t llfs_file_count(void) { - if (file_count == 0) { - const struct llfs_data_file* file = llfs_root; - while (file != NULL) { - file_count++; - file = file->next; - } - } return file_count; }