mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
fatfs: small optimization
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user