-
Notifications
You must be signed in to change notification settings - Fork 3k
FATFileSystem: provide working dir_rewind and dir_seek #5503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return value/error here will not be propagated to application. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
|
||
|
@@ -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(); | ||
} | ||
|
There was a problem hiding this comment.
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.