This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

fds_file_delete delete all files with given id?

Hi

I'm trying to delete all files with a given file id. Will fds_file_delete() delete all files with a given file id, or just the first one it finds?

thanks

SDK14

  • According to the documentation...

    ret_code_t fds_file_delete	(	uint16_t 	file_id	)
    
    Function for deleting all records in a file.
    
    This function deletes a file, including all its records. Deleted records cannot be located using fds_record_find, fds_record_find_by_key, or fds_record_find_in_file. Additionally, they can no longer be opened using fds_record_open.
    
    Note that deleting records does not free the space they occupy in flash memory. To reclaim flash space used by deleted records, call fds_gc to run garbage collection.
    
    This function is asynchronous. Completion is reported through an event that is sent to the registered event handler function.
    
  • The documentation is ambiguous. You can have multiple files with the same file_id, and calling (for example) fds_record_find() can return any one of those files with the provided file_id. You have to loop through fds_record_find() and fds_record_open() to find/open every file with a given file_id, so it's plausible one would have to do the same thing with fds_file_delete().

  • The documentation is not ambiguous at all. It is crystal clear. You do not need to iterate through fds_record_find() as you are deleting the entire file, not just one record of many with the same FILE_ID & REC_ID as in the case of fds_record_delete(). If you notice the fds_record_delete() you need to pass the &record_desc and the most efficient way to get this is to perform a search beforehand. For fds_file_delete(), you just give it the FILE_ID, and viola all records with that FILE_ID are marked deleted until gc called and then truly deleted thereafter.

  • Ah I see where my confusion was. I was thinking you could have multiple files with the same FILE_ID just as you can have multiple records with the same REC_ID and FILE_ID, but a file is no more than an organizational scheme (whereas records actually hold information).

    Thanks for clarifying!

Related