Calculate and cache the file count during llfs init

This commit is contained in:
L-diy
2023-11-16 16:13:22 +01:00
parent b2b5076af1
commit b051e12c20

View File

@@ -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;
}