SD卡第0扇区读出来的内容与实际不符,具体情况如下文。

2019-07-21 03:17发布

SD卡第0扇区内容:

用fatfs去读SD卡第0扇区内容时,找不到FAT标识,上图显示偏移位置0x00000036开始就是FAT字样。

check_fs源码:
[mw_shl_code=c,true]/*-----------------------------------------------------------------------*/ /* Load boot record and check if it is an FAT boot record */ /*-----------------------------------------------------------------------*/ static BYTE check_fs ( /* 0:The FAT BR, 1:Valid BR but not an FAT, 2:Not a BR, 3isk error */ FATFS *fs, /* File system object */ DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not */ ) { if (disk_read(fs->drv, fs->win, sect, 1) != RES_OK) /* Load boot record */ return 3; if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature (always placed at offset 510 even if the sector size is >512) */ return 2; if ((LD_DWORD(&fs->win[BS_FilSysType]) & 0xFFFFFF) == 0x544146) /* Check "FAT" string */ return 0; if ((LD_DWORD(&fs->win[BS_FilSysType32]) & 0xFFFFFF) == 0x544146) return 0; return 1; }[/mw_shl_code]
ff.c部分程式:
[mw_shl_code=c,true] /* Search FAT partition on the drive. Supports only generic partitionings, FDISK and SFD. */ fmt = check_fs(fs, bsect = 0); /* Check sector 0 if it is a VBR */ if (fmt == 1) { /* Not an FAT-VBR, the disk may be partitioned */ /* Check the partition listed in top of the partition table */ tbl = &fs->win[MBR_Table + LD2PT(vol) * SZ_PTE];/* Partition table */ if (tbl[4]) { /* Is the partition existing? */ bsect = LD_DWORD(&tbl[8]); /* Partition offset in LBA */ fmt = check_fs(fs, bsect); /* Check the partition */ } }[/mw_shl_code] 单步执行这段程式
[mw_shl_code=c,true] fmt = check_fs(fs, bsect = 0); /* Check sector 0 if it is a VBR */ [/mw_shl_code]
查找第0扇区内容,fmt=1,进入if语句
[mw_shl_code=c,true] tbl = &fs->win[MBR_Table + LD2PT(vol) * SZ_PTE];/* Partition table */ [/mw_shl_code]
指针指向偏移地址446位置
[mw_shl_code=c,true] bsect = LD_DWORD(&tbl[8]); /* Partition offset in LBA */ [/mw_shl_code]
得到446+8即0x1C6地址的数值,从我的第0扇区内容看,这个值是64

[mw_shl_code=c,true] fmt = check_fs(fs, bsect); /* Check the partition */ [/mw_shl_code]
读取第64扇区内容,这段执行之后fmt=0,即找到FAT。
我查看我我的SD第64扇区内容,结果里面为空,如下图:

这是怎么回事呢?

我单步到这句,得到的结果是:bsect=63,与实际不符。 [mw_shl_code=c,true] bsect = LD_DWORD(&tbl[8]); /* Partition offset in LBA */ [/mw_shl_code]
我的63扇区里面显示也是空的,是不是我哪里理解错了?

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。