Author Topic: uFileSystem "Append"  (Read 8094 times)

Offline texgabry

  • Newbie
  • *
  • Posts: 1
    • View Profile
uFileSystem "Append"
« on: April 28, 2009, 09:57:32 AM »
Hi everybody,
I'm trying to implement a kind of "log file" with the uFileSystem.
The procedure should be something like:
* open the file (the function already exists)
* seek at the end of file (???)
* write a new chunk of file (the function already exists)
* close the file (the function already exists)
Is this possible?  Or can the code be tweaked to allow it?
Thanks in advance!!!
texgabry

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: uFileSystem "Append"
« Reply #1 on: April 28, 2009, 02:02:05 PM »
Hi

It is possible to find the end of the file by its start address plus its length.

eg:
        MEMORY_RANGE_POINTER ptrFile = uOpenFile("0");
        ptrFile +=  uGetFileLength(ptrFile) + FILE_HEADER;


Then it is possible to add extra data to the end of the file by using lower level FLASH write calls.

There are however complications.
a) When adding data it may be necessary to delete a following file which may already exist there in FLASH ('bulldozing' it out of the way - as the uFileSystem does)
b) In order to write the new length (after adding the extra data) it is necessary to make a backup of the first FLASH sector of the file  (in RAM - sector size being FLASH type dependent), delete this sector in FLASH, modify the length in RAM and then write the complete sector back to FLASH.
c) If there is a reset during the process a corrupted file may result.

Therefore the uFileSystem doesn't inherently support adding additional data to a file but it is possible (with a few possible risks) to achieve the effect.

Regards

Mark