AnsweredAssumed Answered

Bug Report: MFS File Open fails for append when file size = cluster size

Question asked by Chris Solomon on Oct 5, 2014
Latest reply on May 21, 2015 by Sean MacKay


Still working on getting MQX 4.1.1 on a K70 stable enough for for an update to our product. 6 weeks and counting.

My CTO wants me to ask if you guys have heard of unit tests. There cool. Give them a look on wikipedia.

Anyway, here's the bug:

We have found that when a file is exactly a multiple of the cluster size (in our case 4096 bytes) opening with filemode a or a+ fails (fopen returns null).


Looking through the code it seems that MFS_Move_file_pointer returns sets the error_code to MFS_EOF.

It seems that when the data ends exactly at the end of a cluster, MFS_get_cluster_from_fat returns CLUSTER_EOF as the new "current_cluster".

This sets the error_code to MFS_EOF, which doesn't seem unreasonable since we are seeking to the end of the file, however when we get back to _io_mfs_open, it sees this error and fails.


I *think* a simple fix is to check if the error_code is

if( error_code == MFS_EOF ) {
     error_code = MFS_NO_ERROR;


at line 462 of mfs_init.c (or thereabouts), but I am not an expert on FAT file systems, so I'm looking for confirmation?







Easy to replicate, just use the sh_write test app.