Re: [Yaffs] mmap, power-off, and data is lost

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Charles Manning
Date:  
To: yaffs
Subject: Re: [Yaffs] mmap, power-off, and data is lost
On Monday 07 April 2008 19:00:40 Louis JANG wrote:
> Hi all,
>
> I'm using yaffs in several mobile platform, and using mmap interface to
> read/write contents of file in yaffs. it works well in normal situation,
> but it losts data when I turn off its power without unmount.


With mmapping, the data lives in the page cache until it is flushed to the fs.

YAFFS will not see the data until the mmapping is flushed through. This will
only happen when the pages are sync'ed back to the fs by msync() or when
the page mapping is invalidated (page pushed out or munmap)

As James says, msync should do what you need.

>
> Please look at the attached sample code, and the following is its result.
>
> # ./a.out
> # ls -l
> -rwxr-xr-x 1 0 0 1024 Apr 7 14:37 mmap_test
> ...
> # sync
>
> ... power off without unmount, and power-on
>
> # ls -l
> -rwxr-xr-x 1 0 0 0 Apr 7 14:37 mmap_test
>
> I also waited for about 10 seconds before power off, but data was lost
> also.
>
> The above problem is not happened if I read mmap_test file before
> power-off(I used cat). and it's not happened if I unmount before. I also
> have tested the above problem with write api instead of mmap, it was not
> happened in this case.
>
> Regards,
> Louis JANG