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

Help in using FDS

Hi all,

I have some questions regarding the use of FDS. I understand that every record is assigned a key and file ID. I manage to get basic delete, read and write functions to work.

Assuming that I am using the following:

fileID = 0x1000; recordKey = 0x2000;

When I create a new record using fds_write(), I get the following log information:

APP: INFO: Writing Record ID = 1

Using the same fileID and recordKey, I can read what I have written into Flash Memory.

However, when I try to issue the following commands:

  1. fds_write()
  2. fds_read()
  3. fds_delete()
  4. fds_write()
  5. fds_read()

The first 1st fds_write creates a Record ID =1. And I can read back successfully. When I call fds_delete, the log gives "Deleted Record ID: 1". And the subsequent fds_write with some new different data now creates a Record ID = 2. But Record ID 1 has already been deleted, so why is a Record ID 2 created instead of Record ID 1? And when I try to call a fds_read() using the same fileID and RecordKey, it reads back the old data from Record ID 1 (even though its been deleted).

I am basically trying to update the record with new data, and the function fds_update gives the problem as above.

Any one can help?

  • Hi,

    I think you might be confusing record keys and record IDs. Record keys identify records within a file. You can have two or more files, each containing one or more records with keys that might be identical to records in other files. Record IDs however, contain an ID that is globally unique for all records in all files. This field is computed by the system and should be invisible to the user. So even though you can access the record ID through the fds_record_desc_t structure you should never use it. The largest record ID is retrieved upon initialization and incremented automatically every time a record is written to flash (or updated). If a record is deleted its ID will not be used again.

    image description

    I tried to reproduce your 5 steps, but it seemed to work fine for me. On the second read operation I read out the value from the second write operation. When I tested I used a global fds_record_desc_t descriptor.

  • Thanks Martin for the description on how records are organised. I am however still having the same problem.

    I am attaching my codes in the link here:

    gist.github.com/.../ad87c11e4083fa028b7857305016c423

Related