sntree / fullfat

Automatically exported from code.google.com/p/fullfat
Other
0 stars 0 forks source link

Better function on ff_ioman.c FF_BlockRead / Write on removeable media #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have been testing this with the a removeable USB thumb drive. 
It is the possible that the drive is removed during operation.

In that case (removed disk) the read function reports 
FF_ERR_DRIVER_FATAL_ERROR, but the read (and write) function do not look for 
this. This code will fix this problem
Also a loop (int t) is included  to avoid deadlocks. This is not a Fullfat 
issue, but was an issue on my test system. Maybe that part is usefull as well.

-----------------------

FF_T_SINT32 FF_BlockRead(FF_IOMAN *pIoman, FF_T_UINT32 ulSectorLBA, FF_T_UINT32 
ulNumSectors, void *pBuffer, FF_T_BOOL aSemLocked) 
{
    FF_T_SINT32 slRetVal = 0;
    int t=200;

    if(pIoman->pPartition->TotalSectors) {
        if((ulSectorLBA + ulNumSectors) > (pIoman->pPartition->TotalSectors + pIoman->pPartition->BeginLBA)) {
            return (FF_ERR_IOMAN_OUT_OF_BOUNDS_READ | FF_BLOCKREAD);        
        }
    }

    if(pIoman->pBlkDevice->fnpReadBlocks) 
    do {    // Make sure we don't execute a NULL.
#ifdef  FF_BLKDEV_USES_SEM
        if (!aSemLocked || pIoman->pSemaphore != pIoman->pBlkDevSemaphore)
            FF_PendSemaphore(pIoman->pBlkDevSemaphore);
#endif
        slRetVal = pIoman->pBlkDevice->fnpReadBlocks(pBuffer, ulSectorLBA, ulNumSectors, pIoman->pBlkDevice->pParam);
#ifdef  FF_BLKDEV_USES_SEM
        if (!aSemLocked || pIoman->pSemaphore != pIoman->pBlkDevSemaphore)
            FF_ReleaseSemaphore(pIoman->pBlkDevSemaphore);
#endif
        if(!FF_isERR(slRetVal)  && FF_GETERROR(slRetVal) != FF_ERR_DRIVER_BUSY) {
            break;
        }
        FF_Sleep(FF_DRIVER_BUSY_SLEEP);
    } while ((t--) && (slRetVal != FF_ERR_DRIVER_FATAL_ERROR));
    return slRetVal;
}
------------------------------

Original issue reported on code.google.com by klaasvor...@gmail.com on 23 Apr 2015 at 8:41