fatfs通过蔟号获取首扇区号
//通过蔟号返回蔟的首扇区号
//假设数据区蔟个数为n
//fat表中条目 = n + 2
//2表示:fat表中0号蔟和1号蔟位置被系统占用
//数据区蔟编号从2开始,则:数据区蔟号为2~(n+1)号蔟
//数据区蔟的偏移量 = (2-2)~(c+1-2)=0~(n-1)
static LBA_t clst2sect ( /* !=0:Sector number, 0:Failed (invalid cluster#) */
FATFS* fs,//文件系统对象。/* Filesystem object */
DWORD clst//数据区蔟号/* Cluster# to be converted */
)
{
clst -= 2;//数据区蔟的偏移量。/* Cluster number is origin from 2 */
if (clst >= fs->n_fatent - 2) //用户蔟偏移量必须小于用户蔟个数
return 0;//无效数据区蔟编号/* Is it invalid cluster number? */
//database:数据区扇区起始号
//csize:每蔟扇区数
//clst蔟的扇区号 = 数据区扇区起始号 + (clst - 2)*每蔟扇区数
return fs->database + (LBA_t)fs->csize * clst; /* Start sector number of the cluster */
}
3万+



被折叠的 条评论
为什么被折叠?



