Append to file with f_lseek


#1

hi,

i use this example code:

http://elm-chan.org/fsw/ff/res/app1.c

to append data to a file that is already on sdcard. it works, but i get some random wrong written bytes when i append big chunks (ca. 1500 bytes or more)

here is the object i created. non appending mode does work as intended. as soon as i try to append, things go strange. with small arrays it works with big ones it fails. any clues on this? the wrong bytes are not in the beginning of the appended data, but somewhere in the middle. the file has the right length. for example 3 bytes might get inserted at one place and 3 bytes are omitted in another place... very strange.

lpcwizard3.axo (3.7 KB)

on a related note, there is a flag FA_OPEN_APPEND in fatfs r0.12a and higher, any chance axoloti would incorporate the new version?


#2

ok to make this a little easier, i created a patch with the object embedded and already filled with data.

just take the patch live, once with append set to no once with append set to yes.

lpcwizardwithdata.axp (12.6 KB)

and here is a version with the same data doubled. take this patch live (only once) and the data should be identical to the first version. however they are not. only the second one is ok. you can check this easily with a hex editor...

lpcwizardwithdatadoubled.axp (20.6 KB)

since the data is written correctly with the second version, i think there is a bug with f_lseek on axoloti/chibios? this happens with two sdcards i have tried.


#3

anyone? @johannes or @thetechnobear? this is driving me insane...(and not in a good way)


#4

I'm working on migrating the Axoloti firmware to Chibios 18.2.0, that will also upgrade the FatFS library to revision 0.13. It's just not ready for consumption yet...
I read your code, but did not spot issues, but I have not tried to reproduce or debug this issue yet.


#5

ok, thanks! i hope the FA_OPEN_APPEND will work as intended once you update chibios. if you find the time to test my issue with the current firmware, that would be great.