Hi,
I had the same issue with 0Bytes size if I don't do fclose(file_descriptor). I tried your fix but it still gives the same results. I did try with both MQX3.8 and MQX4.0 ...
I think it's not a cache issue because I disabled it with:
param = MFS_WRITE_THROUGH_CACHE;
error_code = ioctl(filesystem_handle, IO_IOCTL_SET_FAT_CACHE_MODE, ¶m);
param = MFS_WRITE_THROUGH_CACHE;
error_code = ioctl(filesystem_handle, IO_IOCTL_SET_WRITE_CACHE_MODE, ¶m);
error_code = ioctl(filesystem_handle, IO_IOCTL_FAT_CACHE_OFF, NULL);
Without cache, when I step into fflush(fd_ptr), I run MFS_Flush_directory_sector_buffer and I have drive_ptr->DIR_SECTOR_DIRTY set to FALSE. However if I set caches options to MIXED_MODE (or WRITE_BACK), I have it set to TRUE and I run MFS_Write_device_sector(...). fflush(fd_ptr) returns no error. However if I remove the SD card at this point, I still have a file with 0 bytes...
The only difference I can see with fclose is that it runs MFS_Update_entry before the flush.
the dosfsck (linux utility) shows this:
emilien@Helferi:~$ sudo dosfsck -v /dev/sdd1
dosfsck 3.0.9 (31 Jan 2010)
dosfsck 3.0.9, 31 Jan 2010, FAT32, LFN
Checking we can access the last sector of the filesystem
Boot sector contents:
System ID "MFS30000"
Media byte 0xf8 (hard disk)
512 bytes per logical sector
16384 bytes per cluster
32 reserved sectors
First FAT starts at byte 16384 (sector 32)
2 FATs, 32 bit entries
7814144 bytes per FAT (= 15262 sectors)
Root directory start at cluster 2 (arbitrary size)
Data area starts at byte 15644672 (sector 30556)
1953028 data clusters (31998410752 bytes)
0 sectors/track, 0 heads
0 hidden sectors
62527456 sectors total
Checking for unused clusters.
Reclaimed 2 unused clusters (32768 bytes).
Checking free cluster summary.
Free cluster summary wrong (1953022 vs. really 1953024)