This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Flash Data Storage: fds_stat only returns with uint16_t

Hello,

For the function to acquire the FDS file system status, I noticed that the struct member variables are held in uint16_t. Some values, such as words_used and freeable_words, can overflow during regular usage when the amount of flash allocated to FDS exceeds 65535 words (262kB).

In our application, this case applies, so we have changed some of the fds stat variables to uint32_t. Is there any reason why 16 bits was used for these variables, and is directly changing them to 32-bits safe?

Thank you.

Parents
  • Hello,

     

    In our application, this case applies, so we have changed some of the fds stat variables to uint32_t

     By this, does it mean that you changed some of the parameters in this struct to uint32_t?

    typedef struct
    {
        uint16_t pages_available;   //!< The number of pages available.
        uint16_t open_records;      //!< The number of open records.
        uint16_t valid_records;     //!< The number of valid records.
        uint16_t dirty_records;     //!< The number of deleted ("dirty") records.
        uint16_t words_reserved;    //!< The number of words reserved by @ref fds_reserve().
    
        /**@brief The number of words written to flash, including those reserved for future writes. */
        uint16_t words_used;
    
        /**@brief The largest number of free contiguous words in the file system.
         *
         * This number indicates the largest record that can be stored by FDS.
         * It takes into account all reservations for future writes.
         */
        uint16_t largest_contig;
    
        /**@brief The largest number of words that can be reclaimed by garbage collection.
         *
         * The actual amount of space freed by garbage collection might be less than this value if
         * records are open while garbage collection is run.
         */
        uint16_t freeable_words;
    
        /**@brief Filesystem corruption has been detected.
         *
         * One or more corrupted records were detected. FDS will heal the filesystem automatically
         * next time garbage collection is run, but some data may be lost.
         *
         * @note: This flag is unrelated to CRC failures.
         */
        bool corruption;
    } fds_stat_t;

    Did you change any other types outside this as well? I haven't looked into the details, but I suspect that you at least need to change some types in fds_stat()

    I suspect that some parameters, such as:

    uint16_t const words_in_page = FDS_PAGE_SIZE;

    can remain an uint16_t, but perhaps uint16_t contig_words should be an unt32_t.

    Another place where you at least need to change from uint16_t to uint32_t is inside records_stat(), since this only contains uint16_t pointers for valid_records, dirty_records and freeable_words. as long as these are uint16_t it can never return uint32_t values. 

    Try this, and see how it behaves. It may require you to do some debugging.

    Best regards,

    Edvin

  • The only values that we anticipate will overflow the uint16 limit are words_used and freeable_words in our application. 

    As such, we made the following modifications:

    • Change words_used and freeable_words in fds_stat_t to uint32_t
    • Change *p_freeable_words to uint32_t pointer

    Afterwards, we are able to get valid values of words_used and freeable_words that exceed 65535 without overflowing.

Reply
  • The only values that we anticipate will overflow the uint16 limit are words_used and freeable_words in our application. 

    As such, we made the following modifications:

    • Change words_used and freeable_words in fds_stat_t to uint32_t
    • Change *p_freeable_words to uint32_t pointer

    Afterwards, we are able to get valid values of words_used and freeable_words that exceed 65535 without overflowing.

Children
No Data
Related