debug(fat32): read 打印文件状态(size/first_cluster/pos)与实际读取字节数,定位 ehdr 读取失败根因

This commit is contained in:
TermiNexus committed 2026-08-27 00:08:52 +08:00
1 parent a8f7c0b0b3
commit 51c7475031
1 file changed
+11 -1
+11 -1
View File
@@ -4,7 +4,8 @@ import spinlock
import string
import fat32_diskio as diskio
import fat32_time as ftime
import viperlib
import drivers.serial.uart.serial as serial
def _read32(buf: t.CUInt8T | t.CPtr, off: t.CUInt32T) -> t.CUInt32T:
return t.CUInt32T(buf[off]) | (t.CUInt32T(buf[off + 1]) << 8) | (t.CUInt32T(buf[off + 2]) << 16) | (t.CUInt32T(buf[off + 3]) << 24)
@@ -1452,6 +1453,11 @@ class fileobj:
if not self.is_open: return FRESULT.FR_INVALID_OBJECT
if not (self.flags & FA_READ): return FRESULT.FR_DENIED
c.Set(t.CUInt32T(br, t.CPtr), 0)
# [RD-DIAG] 定位 read_len<64(ehdr 读取失败)根因:打印文件状态
_rdb: t.CArray[t.CChar, 160]
viperlib.snprintf(c.Addr(_rdb), 160, "[fat32] read: size=%lu fc=%lu cc=%lu pos=%lu btr=%lu\n",
self.file_size, self.first_cluster, self.current_cluster, self.file_pos, btr)
serial.puts(c.Addr(_rdb))
vol: volinfo | t.CPtr = self.vol
remaining: t.CUInt32T = btr
buf_ptr: t.CUInt8T | t.CPtr = t.CUInt8T(buff, t.CPtr)
@@ -1487,6 +1493,10 @@ class fileobj:
next_c: t.CUInt32T = vol.cluster_get_next(self.current_cluster)
if next_c == 0: break
self.current_cluster = next_c
# [RD-DIAG] 打印实际读取字节数
_rdb2: t.CArray[t.CChar, 96]
viperlib.snprintf(c.Addr(_rdb2), 96, "[fat32] read done: br=%lu\n", total_read)
serial.puts(c.Addr(_rdb2))
c.Set(t.CUInt32T(br, t.CPtr), total_read)
return FRESULT.FR_OK