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

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

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

1,558 Views
chrissolomon
Contributor III

Hi,

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?

Thanks

Chris

P.S.

Easy to replicate, just use the sh_write test app.

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

723 Views
ironsean
Contributor V

Wouldn't it make more sense to change the code that finds Cluster_EOF to simply not throw an MFS_EOF instead? Have you had any issues with that change?

0 Kudos

723 Views
chrissolomon
Contributor III

Sorry for the late reply, been off the forums for a while. We have been using this for a few months now, in production, with no issues

723 Views
RadekS
NXP Employee
NXP Employee

Hi Chris,

thank you for confirmation.

Just for make it sure. Did you use fix from your initial topic (edit mfs_init.c) or recommended solution with use r+/w/w+ modes instead of append mode?

Anyway, current MFS in MQX 4.2 was reworked and do not suffer this by this bug.

Have a great day,
RadekS

0 Kudos

723 Views
ironsean
Contributor V

I can confirm I've been using the edit mfs_init.c solution since January without issue. Now that MQX 4.2 is out and should have the issue resolved I will try that, if I can get past the printf linking issue I've been getting with my code in MQX 4.2.

0 Kudos

723 Views
juarez
Contributor I

Hi Chris Solomon

I'm having this problem. I would like know if your solution solved the problem without side effect.

Thanks.

0 Kudos

723 Views
RadekS
NXP Employee
NXP Employee

Thank you for your bug report.

Yes, you are right. It is known issue. Unfortunately, append mode is implemented wrongly.

As workaround, please use r+/w/w+ modes instead of append mode and seeks manually according your needs.

Next MQX release will contain complete redesigned MFS subsystem which will solve this issue.


Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos