Fix negative hashing
[yaffs/.git] / yaffs_fileem.c
index 700695b52dadc8227c22f637ad0b513f3c26b132..3ee50eb739ab6a39f32bff4259b985a0ec331c14 100644 (file)
@@ -26,7 +26,7 @@
 #include <fcntl.h>
 #include <string.h>
 
-#define FILE_SIZE_IN_MEG 4
+#define FILE_SIZE_IN_MEG 2
 
 // #define YAFFS_ERROR_TESTING 
 
@@ -137,17 +137,18 @@ static void  CheckInit(yaffs_Device *dev)
        static int initialised = 0;
 
        int length;
+       int nWritten;
 
        
        if(!initialised)
        {
                memset(ffChunk,0xFF,528);
                
-#ifdef YAFFS_DUMP
-               h = open("yaffs-em-file" , O_RDONLY);
-#else
+//#ifdef YAFFS_DUMP
+//             h = open("yaffs-em-file" , O_RDONLY);
+//#else
                h = open("yaffs-em-file" , O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
-#endif
+//#endif
                if(h < 0)
                {
                        perror("Fatal error opening yaffs emulation file");
@@ -156,27 +157,26 @@ static void  CheckInit(yaffs_Device *dev)
                initialised = 1;
                
                length = lseek(h,0,SEEK_END);
-               if(length !=  FILE_SIZE_IN_BYTES)
+               nWritten = 528;
+               while(length <  FILE_SIZE_IN_BYTES && nWritten == 528)
                {
-                       // Create file contents
-                       int i;
-                       
-                       printf("Creating emulation file...\n");
-                       for(i = 0; i < FILE_SIZE_IN_BLOCKS; i++)
-                       {
-                               yaffs_FEEraseBlockInNAND(dev,i);
-                               
-                               if(IsAMarkedBadBlock(i))
-                               {
-                                       yaffs_Spare spare;
-                                       memset(&spare,0xff,sizeof(spare));
-                                       spare.blockStatus = 1;
-                                       
-                                       yaffs_FEWriteChunkToNAND(dev, i * 32,NULL,&spare);
-                               }
-                       }
+                       write(h,ffChunk,528);
+                       length = lseek(h,0,SEEK_END);           
+               }
+               if(nWritten != 528)
+               {
+                       perror("Fatal error expanding yaffs emulation file");
+                       exit(1);
+
                }
-               eraseDisplayEnabled = 1;
+               
+               close(h);
+               
+#ifdef YAFFS_DUMP
+               h = open("yaffs-em-file" , O_RDONLY);
+#else
+               h = open("yaffs-em-file" , O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
+#endif
        }
 }