fatfs: small optimization

This commit is contained in:
Matheus
2025-10-04 20:04:37 -03:00
parent 2eb7d332c2
commit 5814a33cb6
5 changed files with 20 additions and 3 deletions
+12 -2
View File
@@ -1,9 +1,13 @@
#include <kernel/fatfs.h>
#include <logging.h>
// TODO optimize this by keeping some metadata in the fatfs node
int fatfs_get_cluster_from_index(fatfs_t *fs, fatnode_t *node, uintmax_t index, fatfs_cluster_t *cluster) {
fatfs_cluster_t iterator = node->cluster;
if (node->saved_cluster == 0 || node->saved_index > index) {
node->saved_cluster = node->cluster;
node->saved_index = 0;
}
fatfs_cluster_t iterator = node->saved_cluster;
// empty file?
if (iterator == 0) {
@@ -42,6 +46,12 @@ int fatfs_get_cluster_from_index(fatfs_t *fs, fatnode_t *node, uintmax_t index,
}
}
if (fatfs_is_cluster_eof(fs, iterator) == false) {
// update the last found index
node->saved_index = index;
node->saved_cluster = iterator;
}
*cluster = iterator;
return 0;
}