SD card read errors are not reported to the host and send bad data
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- c
- 领域
- embedded-iot
调研方向
Start with tud_msc_read10_cb() and tud_msc_write10_cb() in supervisor/shared/usb/usb_msc_flash.c, checking the result of disk_read() and disk_write() from extmod/vfs_fat_diskio.c. Then read sdcardio_sdcard_readblocks() in shared-module/sdcardio/SDCard.c, where the CMD12 result overwrites the earlier error. Done means failed reads and writes return an error to TinyUSB, the multi-block path returns the first error, and the misleading comment is corrected. Choosing between TUD_MSC_RET_ERROR and TUD_MSC_RET_BUSY needs a maintainer decision.
由索引模型根据 Issue 内容生成。
描述
Claude wrote this:
In https://github.com/adafruit/circuitpython/issues/11692#issuecomment-6526961492, @jedgarpark found that when sdcardio could not get the SPI bus lock, a failed read was not reported, and sent bad data. On their card, a later write built from those stale sectors emptied a file and wiped a directory.
The comment blamed FatFs, but CircuitPython's own FatFs mount does see the error: disk_read() in extmod/vfs_fat_diskio.c turns any nonzero result into RES_ERROR. The stale data more likely went out over USB, because their build presented the SD card to the computer (CIRCUITPY_SDCARD_USB). Checking main at cf41418682 shows two places where a read error is dropped, and one wrong comment.
Problems
tud_msc_read10_cb()insupervisor/shared/usb/usb_msc_flash.cignores the result ofdisk_read()and always returns the full byte count. When the read fails, the computer receives whatever was already in the buffer as if it were the card's data. If the computer then writes back a sector built from that data, the filesystem is damaged.tud_msc_write10_cb()likewise ignores the result ofdisk_write(), so a failed write looks successful to the computer.- In
sdcardio_sdcard_readblocks()inshared-module/sdcardio/SDCard.c, a multi-block read keeps any error from CMD18 orreadinto()inr. It then overwritesrwith the result of the CMD12 stop command, so a failed multi-block read can return 0. - The comment
// No caller actually uses this value.at the end ofsdcardio_sdcard_readblocks()is wrong.disk_read()uses the value as described above, andSDCard.readblocks()raisesOSErroron a negative value.
Possible fix
- Return
TUD_MSC_RET_ERRORfromtud_msc_read10_cb()andtud_msc_write10_cb()whendisk_read()ordisk_write()does not returnRES_OK. TinyUSB then fails the SCSI command instead of sending the buffer. ReturningTUD_MSC_RET_BUSYinstead would make TinyUSB retry the callback, which might suit a bus-lock timeout better. - In the multi-block path, save the first error before sending CMD12 and return it.
- Remove or correct the comment.
- 主要语言
- C
- 星标
- 4.6k
- 派生
- 1.4k
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 187
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
adafruit/circuitpython 的其他 Issue
-
documentation enhancement
难度 2/5 1-3 小时 新手友好度 67/100
adafruit/circuitpython#11689 ·
维护者通常 1 天内回复
-
Hard fault with combination of ESP32SPI and wifi monitor可能已有人在做 @dhalbert 于 4 天前认领。 未关闭bug network
adafruit/circuitpython#11710 · 6 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Feather RP2350: MAX3421E instead of PIO USB host, or a second build?可能已有人在做 @mikeysklar 于 6 天前认领。 未关闭rp2 usb
adafruit/circuitpython#11697 · 5 条评论 · 已指派 2 人 ·
维护者通常 1 天内回复
-
rp2040 zephyr
难度 5/5 一周以上 新手友好度 35/100
adafruit/circuitpython#11690 ·
维护者通常 1 天内回复
-
Metro ESP32-P4 wifi issue/packet loss可能已有人在做 @dhalbert 于 2 天前认领。 未关闭bug esp32-p4 network
难度 4/5 1-2 天 新手友好度 45/100
adafruit/circuitpython#11682 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 adafruit/circuitpython 的全部 Issue
相似的 Issue
-
area/docs
难度 1/5 1 小时以内 新手友好度 83/100
Clodmony/starship-coop#72 ·
维护者通常 1 天内回复
-
ospf6d: heap-use-after-free in seqnumber_mismatch()/bad_lsreq() when a neighbor is deleted with events pending可能已有人在做 @lichenlang89 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 61/100
维护者通常 2 天内回复
-
5700模组网络优先级问题未关闭
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
severity: low
难度 2/5 1-3 小时 新手友好度 76/100
luainkernel/lunatik#2372 ·
维护者通常 1 天内回复