Skip to content
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

FATFileSystem: provide working dir_rewind and dir_seek #5503

Merged
merged 1 commit into from
Nov 20, 2017

Conversation

infinnovation-dev
Copy link
Contributor

Description

Working implementations of dir_rewind and dir_seek are provided for FATFileSystem,
I believe that this fixes #5440 and obviates the need for API changes proposed in #5441.

Status

READY

Migrations

NO

@deepikabhavnani
Copy link

@infinnovation - We will upgrade to ChanFs 0.13a version and index element is not available in directory structure.
Please see : #5490

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.

@@ -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.

@infinnovation-dev
Copy link
Contributor Author

@deepikabhavnani Although index is not present in 0.13a, it appears that dptr has similar properties so could be used for the telldir / seekdir token.

My priority is to have a working rewinddir.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 16, 2017

My priority is to have a working rewinddir.

Thanks for this patch ! As the update is already up, would it be possible to rebase this on top of the updated version ?

@deepikabhavnani please advise

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.
@deepikabhavnani
Copy link

@0xc0170 - Patch will require changes (apart from rebase) to be compatible with FAT upgrade, we can go ahead with this fix for old version, and I can update the patch to be compatible with FAT upgrade. This way we can have working API's in both versions.

Copy link
Contributor

@geky geky left a comment

Choose a reason for hiding this comment

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

This looks great, thanks for this 👍

LGTM

@deepikabhavnani
Copy link

/morph build

1 similar comment
@studavekar
Copy link
Contributor

/morph build

@mbed-ci
Copy link

mbed-ci commented Nov 17, 2017

Build : SUCCESS

Build number : 539
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5503/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@mbed-ci
Copy link

mbed-ci commented Nov 17, 2017

@mbed-ci
Copy link

mbed-ci commented Nov 17, 2017

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 17, 2017

uvisor CI manually triggered, should be completed soon

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 20, 2017

Restart uvisor, as the last one did not report back the status.

@bmcdonnell-ionx
Copy link
Contributor

I get (2) compiler warnings when building mbed OS 5.7.2 on ARM_GCC:

../mbed-os/features/filesystem/fat/FATFileSystem.cpp: In member function 'virtual void FATFileSystem::dir_seek(mbed::fs_dir_t, off_t)':
../mbed-os/features/filesystem/fat/FATFileSystem.cpp:661:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (offset < dh->dptr) {
         ~~~~~~~^~~~~~~~~~
../mbed-os/features/filesystem/fat/FATFileSystem.cpp:664:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (dh->dptr < offset) {
            ~~~~~~~~~^~~~~~~~

I think the right thing to do would be to static_cast<off_t>(dh->dptr). But can dh->dptr be > max off_t? In which case it would do the wrong thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FAT Filesystem : dir_rewind / dir_seek not working
8 participants