seekUserFile MDot API fails, when fetching last byte in the file.

Home Forums mDot/xDot seekUserFile MDot API fails, when fetching last byte in the file.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30283
    Ajay K
    Participant

    I have a requirement to read the last byte from a custom file we store in the flash using the MDot File Api.

    Here is a log information, when attempting to read the last byte of the file.

    [TRACE] File Name: DeviceInfoBkp.dat, Size: 162 bytes.
    [ERROR] SPIFFS_lseek failed -10003

    This is the version of the production mbed mdot library we are using.
    MDOT Library version: 3.1.0 and MBED OS Version: 5.7.7.

    Also here is the code that we are using

    uint8_t nChannelPlan = 0;
        
    //check and see if the bkp file exists, if so read the file and read the last //byte of the file.
    mDot::mdot_file file = m_pDot->openUserFile(DeviceInfoBkpFileName, mDot::FM_RDONLY);
    
    //check if the file exists.    
    if(file.fd >= 0 && file.size > 0) {
         if(m_pDot->seekUserFile(file, 1, SEEK_END)) {
             if(m_pDot->readUserFile(file, &nChannelPlan , sizeof(uint8_t))){
                logDebug("Channel Plan: %u", nChannelPlan);
             }
         }
    }
    
    m_pDot->closeUserFile(file);

    Thanks,
    Ajay.

    #30293
    Jason Reiss
    Keymaster

    Did you try to seek using offset -1 from the end to get the last byte.

    https://fresh2refresh.com/c-programming/c-file-handling/fseek-seek_set-seek_cur-seek_end-functions-c/

    #30299
    Ajay K
    Participant

    Hi Jason,

    Thanks for taking the time to respond, isn’t size_t below an unsigned integer type? Can I pass a negative number?

    bool seekUserFile(mDot::mdot_file& file, size_t offset, int whence);

    Thanks,
    Ajay

    #30306
    Jason Reiss
    Keymaster

    It should be signed, that will be an issue for using SEEK_END. I will have to change that in the future.

    Can you use the size to seek from the beginning?

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.