Hi!
I am currently looking into using a file system to store logged data as files in my QSPI flash memory. To get started I looked around on the devzone and found the usbd_msc example. This works quite well so far. My question however is: I would like to add some sort of metadata to the top of my file. In this metadata I would like to have some fields to indicate how many the files has been opened or if it has been synced with my BLE app. To achieve this I want to read this data first, modify it and write it again. I have noticed that if I read the data and try to overwrite the metadata with modified data, the new data gets written a bit lower in the file. I did some debugging and I noticed the file pointer contains a read/write pointer (fptr) that is modified after the read which probably explains why I am not starting to write at the top of the file.
/* File object structure (FIL) */ typedef struct { _FDID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */ BYTE flag; /* File status flags */ BYTE err; /* Abort flag (error code) */ FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */ DWORD clust; /* Current cluster of fpter (invalid when fprt is 0) */ DWORD sect; /* Sector number appearing in buf[] (0:invalid) */ #if !_FS_READONLY DWORD dir_sect; /* Sector number containing the directory entry */ BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */ #endif #if _USE_FASTSEEK DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */ #endif #if !_FS_TINY BYTE buf[_MAX_SS]; /* File private data read/write window */ #endif } FIL;
So to avoid this issue should I modify the value of this pointer manually. As in set this pointer to zero before my write operation? Or should I close and open the file again to reset this value (seems like it would be slow). I wonder what the rationale is in having the read and the write pointer as the same thing, but I'm not by any means a file system expert.
As a side question I was wondering if anybody has had good experiences using littlefs as an alternative to FAT on the nRF52840? I understand that it is more resilient to power drops and that it has basic wear levering. Certainly the wear leveling might be interesting for my application. How is the performance compared to the FAT example? I am less worried about the space it taking up in my external flash. The code footprint, RAM usage and speed are more critical to me.
Cheers!
Michiel