Skip to content

Commit

Permalink
Merge pull request #5503 from infinnovation/rewinddir
Browse files Browse the repository at this point in the history
FATFileSystem: provide working dir_rewind and dir_seek
  • Loading branch information
theotherjimmy committed Nov 20, 2017
2 parents 08f3402 + 452e290 commit ac891af
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions features/filesystem/fat/FATFileSystem.cpp
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) {
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();
}

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();
}

0 comments on commit ac891af

Please sign in to comment.