From louis@mizi.com Mon Apr 07 08:00:57 2008
Received: from mail.mizi.com ([61.107.31.33])
	by stoneboat.aleph1.co.uk with esmtps
	(TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.63)
	(envelope-from <louis@mizi.com>) id 1JilLS-0003i8-09
	for yaffs@lists.aleph1.co.uk; Mon, 07 Apr 2008 08:00:57 +0100
Received: from [61.107.31.74] (peach.mizi.com [61.107.31.74])
	by mail.mizi.com (8.12.11/8.12.11) with ESMTP id m3770enp007703
	for <yaffs@lists.aleph1.co.uk>; Mon, 7 Apr 2008 16:00:40 +0900
Message-ID: <47F9C698.5060608@mizi.com>
Date: Mon, 07 Apr 2008 16:00:40 +0900
From: Louis JANG <louis@mizi.com>
Organization: MIZI Research, Inc.
User-Agent: Thunderbird 1.5.0.14pre (X11/20071023)
MIME-Version: 1.0
To: yaffs@lists.aleph1.co.uk
Content-Type: multipart/mixed; boundary="------------080407000609040005030904"
X-SA-Exim-Connect-IP: 61.107.31.33
X-SA-Exim-Mail-From: louis@mizi.com
X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on
	stoneboat.aleph1.co.uk
X-Spam-Level: 
X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham
	version=3.2.3
X-SA-Exim-Version: 4.2.1 (built Tue, 09 Jan 2007 17:23:22 +0000)
X-SA-Exim-Scanned: Yes (on stoneboat.aleph1.co.uk)
Subject: [Yaffs] mmap, power-off, and data is lost
X-BeenThere: yaffs@lists.aleph1.co.uk
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: Discussion of YAFFS NAND flash filesystem <yaffs.lists.aleph1.co.uk>
List-Unsubscribe: <http://lists.aleph1.co.uk/cgi-bin/mailman/listinfo/yaffs>, 
	<mailto:yaffs-request@lists.aleph1.co.uk?subject=unsubscribe>
List-Archive: <http://lists.aleph1.co.uk/lurker/list/yaffs.html>
List-Post: <mailto:yaffs@lists.aleph1.co.uk>
List-Help: <mailto:yaffs-request@lists.aleph1.co.uk?subject=help>
List-Subscribe: <http://lists.aleph1.co.uk/cgi-bin/mailman/listinfo/yaffs>,
	<mailto:yaffs-request@lists.aleph1.co.uk?subject=subscribe>
X-List-Received-Date: Mon, 07 Apr 2008 07:00:58 -0000

This is a multi-part message in MIME format.
--------------080407000609040005030904
Content-Type: text/plain; charset=EUC-KR
Content-Transfer-Encoding: 7bit

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.

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

--------------080407000609040005030904
Content-Type: text/x-csrc;
 name="mmap_test.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="mmap_test.c"


#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

int
main()
{
    const char *dbname = "/root/mmap_test";
    int fd = open(dbname, O_RDWR|O_TRUNC|O_CREAT, 0777);
    if (fd < 0) {
	perror("open");
	return -1;
    }

    int len = 1024;
    if (ftruncate(fd, len) < 0) {
	perror("ftruncate");
	return -1;
    }

    void *mmap_ptr = mmap(0, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
    if (mmap_ptr == MAP_FAILED) {
	perror("mmap");
	close(fd);
	return -1;
    }

    memset(mmap_ptr, '1', len);
    munmap(mmap_ptr, len);
    close(fd);
    return 0;
}

--------------080407000609040005030904--

