Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions features/filesystem/fat/FATFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,24 @@ void FATFileSystem::dir_seek(fs_dir_t dir, off_t offset) {
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);

lock();
dh->index = offset;
if (offset < dh->index) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This optimisation assumes that index is monotonic increasing (which appears to be the case in the current version of ChaN FatFs). If not, rewind unconditionally and use an equality test in the while loop.

f_rewinddir(dh);
}
while (dh->index < offset) {
FILINFO finfo;
FRESULT res;
#if _USE_LFN
char lfname[NAME_MAX];
finfo.lfname = lfname;
finfo.lfsize = NAME_MAX;
#endif // _USE_LFN
res = f_readdir(dh, &finfo);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return value/error here will not be propagated to application.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only useful thing an application can do after dir_seek() is dir_read(), at which point it will receive an error.

if (res != FR_OK) {
break;
} else if (finfo.fname[0] == 0) {
break;
}
}
unlock();
}

Expand All @@ -678,7 +695,7 @@ void FATFileSystem::dir_rewind(fs_dir_t dir) {
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);

lock();
dh->index = 0;
f_rewinddir(dh);
unlock();
}