你好,振南,我把大规模读写做成功了,感觉很爽,谢谢你的帮助,其实我把你的 FAT32_Read_File
UINT32 FAT32_Read_File(struct FileInfoStruct *pfi,UINT32 offset,UINT32 len,UINT8 *pbuf)
改成
UINT32 FAT32_Write_File(struct FileInfoStruct *pfi,UINT32 offset,UINT32 len,UINT8 *pbuf)
了,这样就可以实现任意位置处的文件刷新了,多谢!!
UINT32 FAT32_Write_File(struct FileInfoStruct *pfi,UINT32 offset,UINT32 len,UINT8 *pbuf)
{
UINT32 i,j,k,temp;
UINT32 counter=0;
if(offset<pfi->FileSize)
{
if(offset+len>pfi->FileSize) len=pfi->FileSize-offset;
FAT32_Seek_File(pfi,offset);
FAT32_ReadSector(pfi->FileCurSector,FAT32_Buffer);
for(i=pfi->FileCurPos;i<Init_Arg.BytesPerSector;i++)
{
if(counter<len)
{
FAT32_Buffer[i]=pbuf[counter];
counter++;
pfi->FileCurPos++;
pfi->FileCurOffset++;
}
else
{FAT32_WriteSector(pfi->FileCurSector,FAT32_Buffer);
goto end;}
}
FAT32_WriteSector(pfi->FileCurSector,FAT32_Buffer);
if(pfi->FileCurSector-(SOC(pfi->FileCurCluster))!=(Init_Arg.SectorsPerClust-1))
{
for(j=pfi->FileCurSector+1;j<(SOC(pfi->FileCurCluster))+Init_Arg.SectorsPerClust;j++)
{FAT32_ReadSector(j,FAT32_Buffer);
pfi->FileCurSector=j;
for(i=0;i<Init_Arg.BytesPerSector;i++)
{
if(counter<len)
{
FAT32_Buffer[i]=pbuf[counter];
counter++;
pfi->FileCurPos++;
pfi->FileCurOffset++;
}
else
{FAT32_WriteSector(j,FAT32_Buffer);
goto end;}
}
FAT32_WriteSector(j,FAT32_Buffer);
}
}
temp=(len-counter)/(Init_Arg.BytesPerSector*Init_Arg.SectorsPerClust);
for(k=0;k<temp;k++)
{
pfi->FileCurCluster=FAT32_GetNextCluster(pfi->FileCurCluster);
for(j=(SOC(pfi->FileCurCluster));j<(SOC(pfi->FileCurCluster))+Init_Arg.SectorsPerClust;j++)
{
FAT32_ReadSector(j,FAT32_Buffer);
pfi->FileCurSector=j;
for(i=0;i<Init_Arg.BytesPerSector;i++)
{
if(counter<len)
{
FAT32_Buffer[i]=pbuf[counter];
counter++;
pfi->FileCurOffset++;
pfi->FileCurPos++;
pfi->FileCurPos%=Init_Arg.BytesPerSector;
}
else
{FAT32_WriteSector(j,FAT32_Buffer);
goto end;}
}
FAT32_WriteSector(j,FAT32_Buffer);
}
}
pfi->FileCurCluster=FAT32_GetNextCluster(pfi->FileCurCluster);
temp=(SOC(pfi->FileCurCluster))+((len-counter)/Init_Arg.BytesPerSector);
pfi->FileCurSector=(SOC(pfi->FileCurCluster));
for(j=(SOC(pfi->FileCurCluster));j<temp;j++)
{
FAT32_ReadSector(j,FAT32_Buffer);
pfi->FileCurSector=j;
for(i=0;i<Init_Arg.BytesPerSector;i++)
{
if(counter<len)
{
pbuf[counter]=FAT32_Buffer[i];
counter++;
pfi->FileCurPos++;
pfi->FileCurPos%=Init_Arg.BytesPerSector;
pfi->FileCurOffset++;
}
else
{FAT32_WriteSector(j,FAT32_Buffer);
goto end;}
}
FAT32_WriteSector(j,FAT32_Buffer);
}
pfi->FileCurSector=j;
FAT32_ReadSector(pfi->FileCurSector,FAT32_Buffer);
temp=len-counter;
for(i=0;i<temp;i++)
{
if(counter<len)
{
pbuf[counter]=FAT32_Buffer[i];
counter++;
pfi->FileCurPos++;
pfi->FileCurPos%=Init_Arg.BytesPerSector;
pfi->FileCurOffset++;
}
else
{FAT32_WriteSector(pfi->FileCurSector,FAT32_Buffer);
goto end;}
}
FAT32_WriteSector(pfi->FileCurSector,FAT32_Buffer);
}
end:
return len;
} |