Re: [Yaffs] File corruption

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Charles Manning
Date:  
To: yaffs
Subject: Re: [Yaffs] File corruption
On Wednesday 03 January 2007 12:15, Eddie Dawydiuk wrote:
> Hello,
>
> I came across an interesting problem where a write immediately followed by
> a fchmod results in file corruption. We are using Yaffs2, on a board with
> 2KB Nand flash. I reported a very similiar problem about two years ago
> when using Yaffs1, the fix was to change nShortOpCache = 0.
>
> http://lists.aleph1.co.uk/pipermail/yaffs/2005q1/000941.html


The problem is caused by the fchmod causing an object header write which then
caused yaffs to forget that there was stull in the cache for that file.

Killing the cache would "fix" the problem, as would any operation that causes
the cache to be written out before the fchmod.

I thought this was fixed by
http://www.aleph1.co.uk/cgi-bin/viewcvs.cgi/yaffs2/yaffs_guts.c?r1=1.35&r2=1.36

which is supposed to be only updating the file dirty state if there is nothing
in the cache.

Can you please check whether you have this change?

>
> Below is a small program to reproduce the problem. I found after running
> the program, a file named "file" is written to disk. After unmounting
> and remounting the yaffs2 filesystem the file "file" has been corrupted.
> You can use the md5sum utility to verify this as well as hexedit. In the
> example provided the first 0x757FF bytes are correct, all data
> after this byte is now 0. Also I found by syncing the file or sleeping
> prior to calling fchmod avoids the problem...
>
> #include <fcntl.h>
> #include <assert.h>
> #include <sys/stat.h>
> #include <unistd.h>
>
> #define BLOCK_SIZE 16384
> #define FILE_SIZE 483279
>
>
> int main(void)
> {
>          unsigned char data[BLOCK_SIZE];
>          int file_size = FILE_SIZE, bytes, i, j = 0;
>          int fd = open("file", O_WRONLY|O_CREAT|O_TRUNC, 0600);
>          assert(fd != -1);

>
>          do
>          {
>                  for(i=0;i<BLOCK_SIZE;i++)
>                          data[i] = j;
>                  j++;

>
>                  if(file_size < BLOCK_SIZE)
>                          bytes = write(fd, data, file_size);
>                  else
>                          bytes = write(fd, data, BLOCK_SIZE);

>
>                  file_size = file_size - bytes;

>
>          }while(file_size);

>
> //sleep(30);
> //fsync(fd);
>          fchmod(fd, 0644);
>          close(fd);

>
>          return 0;
> }

>
> //Eddie
>
> _______________________________________________
> yaffs mailing list
>
> http://lists.aleph1.co.uk/cgi-bin/mailman/listinfo/yaffs