SD card read errors are not reported to the host and send bad data
I maintainer di solito rispondono entro 1 giorno
@mikeysklar ci sta già lavorando.
Dal 3/11/2026.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c
- Ambito
- embedded-iot
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C
- Stelle
- 4.6k
- Fork
- 1.4k
- Merge medio
- 1g 8h
- PR unite (30g)
- 183
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di adafruit/circuitpython
-
documentation enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
adafruit/circuitpython#11689 ·
I maintainer di solito rispondono entro 1 giorno
-
Hard fault with combination of ESP32SPI and wifi monitorForse già presa @dhalbert l’ha presa 2 giorni fa. Apertabug network
adafruit/circuitpython#11710 · 6 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Feather RP2350: MAX3421E instead of PIO USB host, or a second build?Forse già presa @mikeysklar l’ha presa 5 giorni fa. Apertarp2 usb
adafruit/circuitpython#11697 · 5 commenti · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
-
rp2040 zephyr
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
adafruit/circuitpython#11690 ·
I maintainer di solito rispondono entro 1 giorno
-
Metro ESP32-P4 wifi issue/packet lossForse già presa @dhalbert l’ha presa 1 giorno fa. Apertabug esp32-p4 network
Difficoltà 4/5 1-2 giorni Idoneità per principianti 45/100
adafruit/circuitpython#11682 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di adafruit/circuitpython
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
containers/bubblewrap#826 ·
I maintainer di solito rispondono entro 1 giorno
-
[compiler-rt] Rtsan-aarch64-NoInstTest: error: no such file or directory: 'NOTFOUND' (libatomic)Apertabuild-problem compiler-rt:rtsan platform:linux
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
llvm/llvm-project#239039 ·
I maintainer di solito rispondono entro 1 giorno
-
component:obi contribfest go test
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 83/100
open-telemetry/opentelemetry-ebpf-instrumentation#4143 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
checkpoint-restore/criu#3304 ·
I maintainer di solito rispondono entro 1 giorno
-
Separate Installation Commands into Individual Code BlocksForse già presa @andrySD l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
colbymchenry/codegraph#3241 ·
I maintainer di solito rispondono entro 1 giorno