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

feat(fs): file writes update the file cache #6186

Merged
merged 7 commits into from May 13, 2024

Conversation

liamHowatt
Copy link
Collaborator

Description of the feature or fix

Continuing PR #5172

PR #5172 adds updating the file cache upon write. Data written out will now be reflected in the cache so file caching is no longer read-only.

This PR is a continuation of the other PR that also adds:

  • a test case that writes to a file "randomly", intermixed with read and seek operations.
  • Adds more docs for the FS to clarify exactly what kind of caching/buffering the file cache does and when it should and should not be used.
  • Refactors the caching code in lv_fs.c. The formatting and sequence of operations is easier to visually parse now. It's easier to see the difference in the refactor if you open the old and new file and review them separately without the diff. I did not touch the implementations of the caching logic. The only thing I changed was remove the driver seek for SEEK_SET and SEEK_CUR when caching is active.

At the time of opening this PR, this is what the new docs look like:
image

Here is the mermaid flowchart embedded.

   flowchart LR
       A["call lv_fs_read and
          the cache is enabled"] --> B{{"is there cached data
                                         at the file position?"}}
       B -->|yes| C{{"does the cache have
                      all required bytes available?"}}
       C -->|yes| D["copy all required bytes from
                     the cache to the destination
                     buffer"]
       C -->|no| F["copy the available
                    required bytes
                    until the end of the cache
                    into the destination buffer"]
             --> G["seek the real file to the end
                    of what the cache had available"]
             --> H{{"is the number of remaining bytes
                     larger than the size of the whole cache?"}}
       H -->|yes| I["read the remaining bytes
                     from the real file to the
                     destination buffer"]
       H -->|no| J["eagerly read the real file
                    to fill the whole cache
                    or as many bytes as the
                    read call can"]
             --> O["copy the required bytes
                    to the destination buffer"]
       B -->|no| K["seek the real file to
                    the file position"]
             --> L{{"is the number of required
                     bytes greater than the
                     size of the entire cache?"}}
       L -->|yes| M["read the real file to
                     the destination buffer"]
       L -->|no| N["eagerly read the real file
                    to fill the whole cache
                    or as many bytes as the
                    read call can"]
             --> P["copy the required bytes
                    to the destination buffer"]

Notes

@liamHowatt liamHowatt changed the title Feat/fs cache write feat(fs): file writes update the file cache May 6, 2024
Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

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

Very nice! The use of mermaid is especially cool. We haven't used it so far.

It's hard to spot any issues just by reading the code, so if the test passes it should be good 🙂

@kisvegabor kisvegabor merged commit 4e85b0f into lvgl:master May 13, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants