mirror of https://github.com/ARMmbed/mbed-os.git
FATFileSystem: provide working dir_rewind and dir_seek
The index field of FATFS_DIR does not encapsulate all the context required to reposition the directory traversal. ChaN provides f_rewinddir() but no directory seek, so rewind if necessary then step through until the desired index is reached.pull/5503/head
parent
41eb565d9c
commit
452e290821
|
@ -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);
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue