static int CheckInit(void) { static int initialised = 0; int i,j; int fail = 0; int nBlocks; int nAllocated = 0; if(initialised) { return YAFFS_OK; } ned.nBlocks = nBlocks = nandemul2k_CalcNBlocks(); ned.block = YMALLOC(sizeof(nandemul_Block*) * nBlocks ); if(!ned.block) return YAFFS_FAIL; for(i=fail=0; i <nBlocks; i++) { nandemul_Block *blk; if(!(blk = ned.block[i] = YMALLOC(sizeof(nandemul_Block)))) { fail = 1; } else { for(j = 0; j < PAGES_PER_BLOCK; j++) { if((blk->page[j] = YMALLOC(sizeof(nandemul_Page))) == 0) { fail = 1; } } nandemul_ReallyEraseBlock(i); ned.block[i]->damaged = 0; nAllocated++; } } if(fail) { //Todo thump pages for(i = 0; i < nAllocated; i++) { YFREE(ned.block[i]); } YFREE(ned.block); T(YAFFS_TRACE_ALWAYS,("Allocation failed, could only allocate %dMB of %dMB requested.\n", nAllocated/64,sizeInMB)); return 0; } ned.nBlocks = nBlocks; initialised = 1; return 1; }
int nandemul2k_GetNumberOfBlocks(void) {return nandemul2k_CalcNBlocks();}
static int CheckInit(void) { static int initialised = 0; int i,j; int fail = 0; int nBlocks; int nAllocated = 0; if(initialised) { return 0; } ned.nBlocks = nBlocks = nandemul2k_CalcNBlocks(); ned.block = ALLOCATE(sizeof(nandemul_Block*) * nBlocks ); if(!ned.block) return ENOMEM; for(i=fail=0; i <nBlocks; i++) { nandemul_Block *blk; if(!(blk = ned.block[i] = ALLOCATE(sizeof(nandemul_Block)))) { fail = 1; } else { for(j = 0; j < PAGES_PER_BLOCK; j++) { if((blk->page[j] = ALLOCATE(sizeof(nandemul_Page))) == 0) { fail = 1; } } nandemul2k_DoErase(i); ned.block[i]->damaged = 0; nAllocated++; } } if(fail) { //Todo thump pages for(i = 0; i < nAllocated; i++) { FREE(ned.block[i]); } FREE(ned.block); return ENOMEM; } ned.nBlocks = nBlocks; initialised = 1; return 1; }