Hello,
I have the same problem.
I want to write some files in the internal Flash using the MFS.
This is my code:
/*************************************************/
flash_handle = fopen("flashx:bank1", NULL);
if (flash_handle == NULL)
_task_block();
param = IO_O_RDWR; // Read and Write FLASH, just in case
if (IO_OK != ioctl(flash_handle, IO_IOCTL_SET_FLAGS, (char_ptr) ¶m))
_task_block();
// FILE SYSTEM installation over FLASH
error_code = _io_mfs_install(flash_handle, filesystem_name, (_file_size)0);
if (error_code != MFS_NO_ERROR)
_task_block();
//Open FILE SYSTEM
filesystem_handle = fopen(filesystem_name, NULL);
error_code = ferror (filesystem_handle);
if ((error_code != MFS_NO_ERROR) && (error_code != MFS_NOT_A_DOS_DISK))
_task_block();
// if not Formated, I do Format
if (error_code == MFS_NOT_A_DOS_DISK)
ioctl(filesystem_handle, IO_IOCTL_DEFAULT_FORMAT, NULL);
ioctl( filesystem_handle, IO_IOCTL_FAT_CACHE_OFF, NULL); // without CACHE
// Open and close a file, if it do not exist, it is created
file_0 = NULL;
file_0 = fopen(FullFileName, "a");
fclose(file_0);
ioctl( filesystem_handle, IO_IOCTL_FLUSH_FAT, NULL); // flush file system
// Open the file
file_0 = fopen(FullFileName, "r+");
if (file_0 == NULL)
_task_block();
memset(buffer, 0, sizeof buffer);
len = read(file_0, buffer, 32);
if( strcmp( buffer, "HELLO") ) {
strcpy(buffer, "HELLO");
fseek(file_0, -32, IO_SEEK_END);
write(file_0, buffer, 32);
fflush(file_0);
}
fclose(file_0);
ioctl( filesystem_handle, IO_IOCTL_FLUSH_FAT, NULL); // Fluch file system
/********************************************************/
I can write the files, but when I try to access again, I cannot find the file. I always have to create it again. I inspect the flash, and I can see the file contents, but the file system do not see it.
I think the problem is that IO_IOCTL_FLUSH_FAT is not working or something like that.
Can anyone help me?
thank you!