void BufRead(int blkno, void* pData) { Buf* find = BufFind(blkno); Buf* pNewBuf; // HIT if (find != NULL) { LruInsert(find); //pData = find->pMem; memmove(pData, find->pMem, strlen(find->pMem) + 1); } // MISS else { // Create New Buffer pNewBuf = BufGetNewBuffer(); pNewBuf->blkno = blkno; pNewBuf->state = BUF_STATE_CLEAN; DevReadBlock(blkno, pNewBuf->pMem); BufInsertToTail(pNewBuf, pNewBuf->blkno, BUF_LIST_CLEAN); LruInsert(pNewBuf); memmove(pData, pNewBuf->pMem, strlen(pNewBuf->pMem) + 1); } }
void BufRead(int blkno, void* pData) { Buf* pBuf; pBuf = BufFind(blkno); if( pBuf != NULL ) { removeLru(blkno); insertLru(pBuf); copyBlock((char*)pBuf->pMem, (char*)pData); return; } pBuf = popFree(); pBuf->blkno = blkno; //pBuf->pMem = (void*)malloc(BLOCK_SIZE); DevReadBlock(blkno, (char*)pBuf->pMem); insertHash(pBuf); insertClean(pBuf); removeLru(blkno); insertLru(pBuf); copyBlock((char*)pBuf->pMem, (char*)pData); }