AnsweredAssumed Answered

Howto flush MFS? (Use case: mfs onto ramdisk)

Question asked by Fabi on May 16, 2012
Latest reply on May 6, 2014 by Christian Leeb

Hi all,
Assume the following use case:
1. setup MFS on ramdisk
2. open file, stored on MFS, and update the content
3. readout ramdisk raw data
In step 3 the content of ramdisk is unchanged. Why? Is where a double buffer or so for storing the file content?

I need up-to-date raw data to transmit it over USB device periodically.

 

The stripped (i.e. error handling and remarks are deleted) setup code is as follows:
_io_mem_install ( "ramdisk:", NULL, DISK_SIZE );
ramdisk_handle = fopen ( "ramdisk:", 0 );
_io_mfs_install ( ramdisk_handle, "ram:", 0 );
fat_handle = fopen ( "ram:", NULL );
ioctl ( fat_handle, IO_IOCTL_DEFAULT_FORMAT, NULL );
cache_mode = MFS_WRITE_THROUGH_CACHE;
_io_ioctl ( fat_handle, IO_IOCTL_SET_FAT_CACHE_MODE, &cache_mode );
_io_ioctl ( fat_handle, IO_IOCTL_SET_WRITE_CACHE_MODE, &cache_mode );
_io_ioctl ( fat_handle, IO_IOCTL_FAT_CACHE_OFF, NULL );

2. Update the file content (stripped code):
handle = fopen ( filename, "w+" );
fseek ( handle, 0, IO_SEEK_SET );
write ( handle, txt_buf, strlen(txt_buf) );
fflush ( handle );
fclose ( handle );
_io_ioctl ( fat_handle, IO_IOCTL_FLUSH_FAT, NULL );

3. readout the raw data:
fseek ( ramdisk_handle, lba_data_ptr->offset, IO_SEEK_SET );
read ( ramdisk_handle, lba_data_ptr->buff_ptr, lba_data_ptr->size );

Outcomes