www.pudn.com > fat32.c51.rar > FATREADFILE.C
#ifndef _FAT32_DEFINE
#include "FAT32.c"
#endif
WORD FAT32ReadFile(BYTE fp);
WORD FAT32ReadFile(BYTE fp)
{
register WORD tmp;
if (FCB[fp].ByteCnt==FCB[fp].Size) return(0);
else
{
FCB[fp].ByteCnt+=IDE.BytesPerSec;
if (FCB[fp].ByteCnt<=FCB[fp].Size) tmp=IDE.BytesPerSec;
else
{
FCB[fp].ByteCnt-=IDE.BytesPerSec;
tmp=FCB[fp].Size-FCB[fp].ByteCnt;
FCB[fp].ByteCnt=FCB[fp].Size;
}
if (FCB[fp].ClusSecCnt==FAT32.SecPerClus) //读下一簇
{
FCB[fp].LastCluster=FAT32NextCluster(FCB[fp].LastCluster);
if (FCB[fp].LastCluster==0x0fffffff) return(0);
IDEReadSector(ClusterToSector(FCB[fp].LastCluster));
FCB[fp].ClusSecCnt=1;
}
else if (FCB[fp].ClusSecCnt==0) //读第一簇
{
IDEReadSector(ClusterToSector(FCB[fp].LastCluster));
FCB[fp].ClusSecCnt++;
}
else //读当前簇下一扇区
{
IDEReadSector(ClusterToSector(FCB[fp].LastCluster)+FCB[fp].ClusSecCnt);
FCB[fp].ClusSecCnt++;
}
}
return(tmp);
}