[Yaffs] Wrong data after unmount/mount

Beat Morf beat.morf at duagon.com
Tue Aug 30 11:48:19 BST 2005


Charles Manning wrote:

>Hi Beat
>
>I will need to ask you a few questions to help me understand better.
>
>On Monday 29 August 2005 21:19, Beat Morf wrote:
>  
>
>>Hi
>>
>>I have a small question concerning the YAFFS direct implementation and
>>appending data on a file.
>>
>>I have a file called "file01". Now I use the procedure "yaffs_write(h,
>>buffer, 600) to append data to the file until no more space is left (my
>>flash supports 512Bytes/Chunk and I reduced the total YAFFS size to
>>1916928 Bytes):
>>    
>>
>
>So is that 117 blocks of 32 pages of 512 bytes?
>How many reserve blocks?
>How many short op caches?
>  
>
My configuration is as follows:

    flash.nBytesPerChunk = 512;
    flash.nChunksPerBlock = 32;
    flash.nReservedBlocks = 5;
    flash.startBlock = 5;
    flash.endBlock = 127;
    flash.useNANDECC = 0;
    flash.nShortOpCaches = 0;
    flash.genericDevice = (void *) 0;

>>- Size of the file "file01": 1041408
>>- Available size but not useable: 875008
>>    
>>
>
>How did you determine there was no more space?
>
>Did you do something like:
>  while (yaffs_write(h,buffer,600) > 0)
> {
> }
>  
>
I allways used the procedure called "yaffs_freespace(..)" for determine 
free space.

I use following C-code:

/* Test the YAFFS interface */
diag_printf("format\n");
yaffs_llformat("/data");  /* Erase each block from startBlock to endBlock */
diag_printf("mount\n");
yaffs_mount("/data");
diag_printf("free space: %d\n", yaffs_freespace("/data"));
diag_printf("create file with max. size\n");
h = yaffs_open("/data/file01", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | 
S_IWRITE);
while (0 < (size = yaffs_write(h, buffer, 1024))){}
showdirentries("/data", 1, 1, 0);
diag_printf("free space: %d\n", yaffs_freespace("/data"));
diag_printf("umount\n");
yaffs_unmount( "/data" );

/* OUTPUT */
format
mount
free space: 
1916928                                                            
create file with max. size
|-  f    8      size: 1916416     /data/file01
|- d    1      size:         512     /data/lost+found
free space: 0
umount


If I modify the line to "while (0 < (size = yaffs_write(h, buffer, 
600)))", the output is as follows:
/* OUTPUT */
format
mount
free space: 1916928
create file with max. size
|-  f    8     size:  1041600     
/data/file01                                                                 

|- d    1     size:          512     
/data/lost+found                                    
free space: 874496
umount

>How did you determine "available size but not usable"?
>  
>
As you can see in the last output-example, the "yaffs_freespace" 
procedure returns that still 874496Bytes are free, but the procedure 
write(...) couldn't write any byte more into the file! Means, that the 
874496bytes are lost within the pages that couldn't be complete be used.

>>If I change the size of the buffer to "yaffs_write(h, buffer, 1024), I
>>get following result:
>>- Size of the file "file01": 1904128
>>- Available size but not useable: 12288
>>
>>What happens if I add packets with size of 600Bytes? Do YAFFS use 2
>>chunks and in the second chunk 424 Bytes are lost (512 - (600-512) = 424)
>>?!
>>    
>>
>
>The difference between these is that the one will use the cache and the other 
>will not. The short op cache only works on data that is not page aligned, in 
>the following way
>
>Let us examine what happens to a sequence of 600-byte writes, starting at 
>location zero:
>
>write 600:
> Chunk 1 (bytes 0..511) written to NAND bypassing cache.
> Chunk 2 (bytes512..599) written to cache entry 1.
>write 600
> Chunk 2 (bytes 600..1023) appended to cache entry 1.
> Chunk 3 (bytes 1024..1199) written to cache entry 2
>write 600
> Chunk 3 (bytes 1200..1535) appended to cache entry 2.
> Chunk 4 (bytes 1536..1799) written to cache entry 3.
>...
>
>When the cache gets full or the file is flushed/closed it will force stuff to 
>be written from the cache to NAND.
>
>Since the writes of 1024 are all page aligned, they are not placed in the 
>cache.
>
>No data should be lost and no space should be wasted in this operation.
>  
>
I tested my application with "flash.nShortOpCaches = 10;" and writing 
600Bytes packages. You are right, the flash is now complete used and 
"yaffs_freespace" returns 0.


(1) I saw that setting the "nShortOpCaches" to 10 will allocate 10 times 
the "yaffs_ChunkCache" struct (536Bytes).
- Why is a value of 10 to 20 recommended (means memory usage of 5KB up 
to 10KB!)
- How can I force writing the cache to the flash?

(2) It looks like "yaffs_freespace()" didn't note the lost bytes within 
a page as lost (used)?!


Beat



More information about the yaffs mailing list