Skip to content

UFile::available() does not work correctly with QSPI flash and other issues #41

Open
@ddmesh

Description

@ddmesh

The Finder Opta device contains a 2Mbyte QSPI flash.
When calling UFile::available() to get the file size (file position still at 0 after opening), I would expect the file size. But I get almost flash size.

  • Firstly I have seen that when you call ftell() you use integer type instead of the required
    type long. On different platforms, int can use from one to 4 bytes.
  • UFile::available() return type is uint32_t, but typically size_t should be used, as this
    is semantically the same as file position or number of bytes written/read.
  • In this function there are no check if the call to ftell() was successful. The returned data are just used. but those could be wrong if seeking failed.
  • Using ftell(,,SEEK_END) is not implemented on every platform.
    please see https://en.cppreference.com/w/c/io/fseek (right at the beginning).
    For this Finder Opta device (supported by Arduino) the current position returned after
    seeking to end and calling tell(), returns 1966048 bytes. Same file on USB returns the correct size (e.g. 128780)
  • Also UFile should support ftell and fflush as API (see end of page under section "Notes").

If you like you may create several issues for this one and separate it. I just wanted to tell you my findings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions