fopen - append bug

Showing results for 
Show  only  | Search instead for 
Did you mean: 

fopen - append bug

Contributor III



I'm using MQX3.6 and I think I found a bug on MFS in conjuction with a USB Pen Drive...


I open a file in the USB to append data to it with:

fd = fopen("c:\\log.txt", "a")


I write data to it and close it, and it works fine. Every time I log something, it goes to the end of the file preserving previous data.


But if I insert the USB stick and try loging, it overwrites several bytes in the end of the file.


If I insert the USB Stick and type in the shell: "type log.txt" before I write data into it, it works fine.


Have you guys seen it? Has that been fixed in MQX3.7?

Labels (1)
Tags (1)
0 Kudos
3 Replies

Contributor II



I saw a bunch of suggestions about using removable media while I was reading about my formatting issues.


Have you looked into the MQX MFS User's guide, it talks about Buffering and Caching on page 15.


Also, I thought that maybe you can set a flag on stick insertion that would cause a

error = MFS_Read_data_sector(drive_ptr, handle_ptr, sector_number, TRUE); and

error = MFS_Read_data_sector(drive_ptr, handle_ptr, sector_number, False); if not, which may speed up reading.


Contributor III

Thank you for your reply JKadin,


I just read theBuffering and Caching on the MQXMFSUG but that's not the problem I am reporting.


Try it your self and you'll see it (MQX3.6)


Open a txt file on any PC and write some lines on it. Save file in USB Pen Drive.


Plug it in a kit running MQX3.6 MFS and execute fopen with "a" for append


Write some data to it. You'll see it ovewrites some bytes of the file you created even on another platform...


I'll consider setting the flag as you suggested. Thanks!



0 Kudos

Contributor III

Ok... I changed MFS driver a bit and the problem seems to be solved, though I would like to know from you guys the setback of what I did:


In "Freescale MQX 3.6\mfs\source\generic\mfs_write.c", line 179


I changed it to:


error = MFS_Read_data_sector(drive_ptr, handle_ptr, sector_number, TRUE);


If set to FALSE, it does not read the sector because I guess usually the buffer is already filled?


Anyway, let me know what you think of it



0 Kudos