- CheckInit();
-
-
- if(dev->param.inbandTags){
-
- yaffs_PackedTags2TagsPart * pt2tp;
- pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk];
- yaffs_PackTags2TagsPart(pt2tp,tags);
-
- pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE;
- h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))];
-
- lseek(h,pos,SEEK_SET);
- written = write(h,data,dev->param.totalBytesPerChunk);
-
-
- if(yaffs_testPartialWrite){
- close(h);
- exit(1);
- }
-
- if(written != dev->param.totalBytesPerChunk) return YAFFS_FAIL;
-
-
- }
-
- else {
- /* First do a write of a partial page */
- int n_partials;
- int bpos;
-
- if(data)
- {
- pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE;
- h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))];
-
-
- memcpy(localBuffer,data, dev->nDataBytesPerChunk);
-
- n_partials = rand()%20;
-
- for(i = 0; i < n_partials; i++){
- bpos = rand() % dev->nDataBytesPerChunk;
-
- localBuffer[bpos] |= (1 << (rand() & 7));
- }
-
- if(REPORT_ERROR && memcmp(localBuffer,data,dev->nDataBytesPerChunk))
- printf("nand simulator: data does not match\n");
-
- lseek(h,pos,SEEK_SET);
- written = write(h,localBuffer,dev->nDataBytesPerChunk);
-
- if(yaffs_testPartialWrite){
- close(h);
- exit(1);
- }
-
-
- if(written != dev->nDataBytesPerChunk) return YAFFS_FAIL;
- }
- // yflash2_MaybePowerFail(chunkInNAND,1);
-
- if(tags)
- {
- pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE + PAGE_DATA_SIZE ;
- h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))];
-
- lseek(h,pos,SEEK_SET);
-
- if( 0 && dev->param.isYaffs2)
- {
-
- written = write(h,tags,sizeof(yaffs_ExtendedTags));
- if(written != sizeof(yaffs_ExtendedTags)) return YAFFS_FAIL;
- }
- else
- {
- yaffs_PackedTags2 pt;
- yaffs_PackTags2(&pt,tags, !dev->param.noTagsECC);
- __u8 * ptab = (__u8 *)&pt;
-
- nRead = read(h,localBuffer,sizeof(pt));
- for(i = error = 0; REPORT_ERROR && i < sizeof(pt) && !error; i++){
- if(localBuffer[i] != 0xFF){
- printf("nand simulation: chunk %d oob byte %d was %0x2\n",
- chunkInNAND,i,localBuffer[i]);
- error = 1;
- }
- }
-
- for(i = 0; i < sizeof(pt); i++)
- localBuffer[i] &= ptab[i];
-
- n_partials = rand()% sizeof(pt);
-
- for(i = 0; i < n_partials; i++){
- bpos = rand() % sizeof(pt);
-
- localBuffer[bpos] |= (1 << (rand() & 7));
- }
-
- if(REPORT_ERROR && memcmp(localBuffer,&pt,sizeof(pt)))
- printf("nand sim: tags corruption\n");
-
- lseek(h,pos,SEEK_SET);
-
- written = write(h,localBuffer,sizeof(pt));
- if(written != sizeof(pt)) return YAFFS_FAIL;
- }
- }
-
- //yflash2_MaybePowerFail(chunkInNAND,2);
-
- /* Next do the whole write */
- if(data)
- {
- pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE;
- h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))];
-
-
- memset(localBuffer,0xFF, PAGE_SIZE);
- for(i = 0; i < dev->nDataBytesPerChunk; i++){
- localBuffer[i] &= data[i];
- }
-
- if(REPORT_ERROR && memcmp(localBuffer,data,dev->nDataBytesPerChunk))
- printf("nand simulator: data does not match\n");
-
- lseek(h,pos,SEEK_SET);
- written = write(h,localBuffer,dev->nDataBytesPerChunk);
-
- if(yaffs_testPartialWrite){
- close(h);
- exit(1);
- }
-
-
- if(written != dev->nDataBytesPerChunk) return YAFFS_FAIL;
- }
-
- if(tags)
- {
- pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE + PAGE_DATA_SIZE ;
- h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))];
-
- lseek(h,pos,SEEK_SET);
-
- if( 0 && dev->param.isYaffs2)
- {
-
- written = write(h,tags,sizeof(yaffs_ExtendedTags));
- if(written != sizeof(yaffs_ExtendedTags)) return YAFFS_FAIL;
- }
- else
- {
- yaffs_PackedTags2 pt;
- yaffs_PackTags2(&pt,tags,!dev->param.noTagsECC);
- __u8 * ptab = (__u8 *)&pt;
-
- nRead = read(h,localBuffer,sizeof(pt));
- for(i = error = 0; REPORT_ERROR && i < sizeof(pt) && !error; i++){
- if(localBuffer[i] != 0xFF){
- printf("nand simulation: chunk %d oob byte %d was %0x2\n",
- chunkInNAND,i,localBuffer[i]);
- error = 1;
- }
- }
-
- for(i = 0; i < sizeof(pt); i++)
- localBuffer[i] &= ptab[i];
-
- if(REPORT_ERROR && memcmp(localBuffer,&pt,sizeof(pt)))
- printf("nand sim: tags corruption\n");
-
- lseek(h,pos,SEEK_SET);
-
- written = write(h,localBuffer,sizeof(pt));
- if(written != sizeof(pt)) return YAFFS_FAIL;
- }
- }
-
- yflash2_MaybePowerFail(chunkInNAND,3);
-
- }
- return YAFFS_OK;
-
-}
-
-int yaffs_CheckAllFF(const __u8 *ptr, int n)