根据静态注解修正了部分的 global 修正(遍历截止fat32 fileio.vp)

This commit is contained in:
TermiNexus committed 2026-07-31 13:36:26 +08:00
1 parent 9d786dd5b1
commit be92f671d0
6 files changed
+23 -7

No files matched your search

+1 -1
View File
@@ -196,7 +196,7 @@ def _setup_trampoline(entry_addr: t.CUInt64T, stack_addr: t.CUInt64T, cr3_val: t
c.Set(c.Deref(t.CUInt16T(AP_TRAMPOLINE_ADDR + 0x0F10, t.CPtr)), gdt_limit)
c.Set(c.Deref(t.CUInt64T(AP_TRAMPOLINE_ADDR + 0x0F12, t.CPtr)), gdt_base)
idt_addr: t.CUInt64T = t.CUInt64T(c.Addr(idt.idp))
idt_addr: t.CUInt64T = t.CUInt64T(c.Addr(idt.idt))
idt_base: t.CUInt64T = c.Deref(t.CUInt64T(idt_addr + 2, t.CPtr))
idt_limit: t.CUInt16T = c.Deref(t.CUInt16T(idt_addr, t.CPtr))
c.Set(c.Deref(t.CUInt16T(AP_TRAMPOLINE_ADDR + 0x0F20, t.CPtr)), idt_limit)
+1 -1
View File
@@ -5,7 +5,7 @@ import t, c
# FPU上下文结构体
@c.Attribute(t.attr.aligned(16))
class fpu_context:
data: t.CUInt8T[512] # FXSAVE区域大小
data: t.CArray[t.CUInt8T, 512] # FXSAVE区域大小
@t.Object
@@ -149,7 +149,7 @@ def example_main() -> t.CInt:
print("--- 8. 文件状态和属性 ---")
info: types.fileinfo
res = fs.stat("/test_dir_1/file1.txt", info)
res = fs.stat("/test_dir_1/file1.txt", c.Addr(info))
print_fresult_void(res, "获取文件信息")
if res == types.FRESULT.FR_OK:
print(f" 文件名: {info.fname}")
@@ -183,12 +183,12 @@ def example_main() -> t.CInt:
print("--- 10. 列出目录 ---")
dp: types.dirobj
res = fs.opendir("/", dp)
res = fs.opendir("/", c.Addr(dp))
if res == types.FRESULT.FR_OK:
print("根目录内容:")
dir_info: types.fileinfo
while True:
res = fs.readdir(dp, dir_info)
res = fs.readdir(c.Addr(dp), c.Addr(dir_info))
if res != types.FRESULT.FR_OK:
break
attr_str: t.CConst = ""
@@ -205,7 +205,7 @@ def example_main() -> t.CInt:
if dir_info.attr & types.AM_ARC:
attr_str = attr_str + "A"
print(f" [{attr_str}] {dir_info.fname} ({dir_info.file_size} 字节)")
fs.closedir(dp)
fs.closedir(c.Addr(dp))
print()
# 11. 删除文件和目录
@@ -11,11 +11,13 @@ drive_initialized: t.CArray[t.CInt, MAX_DRIVES]
drive_lock: spinlock._spinlock = spinlock._spinlock()
def status(pdrv: t.CUInt8T) -> types.DRESULT:
global drive_initialized
if pdrv >= MAX_DRIVES: return types.DRESULT.RES_PARERR
if not drive_initialized[pdrv]: return types.DRESULT.RES_NOTRDY
return types.DRESULT.RES_OK
def init(pdrv: t.CUInt8T) -> types.DRESULT:
global drive_lock, drive_initialized
if pdrv >= MAX_DRIVES: return types.DRESULT.RES_PARERR
drive_lock.lock()
err: t.CInt = ide.init()
@@ -27,6 +29,7 @@ def init(pdrv: t.CUInt8T) -> types.DRESULT:
return types.DRESULT.RES_OK
def read(pdrv: t.CUInt8T, buff: t.CUInt8T | t.CPtr, sector: t.CUInt32T, count: t.CUInt32T) -> types.DRESULT:
global drive_initialized, drive_lock
if pdrv >= MAX_DRIVES: return types.DRESULT.RES_PARERR
if not drive_initialized[pdrv]: return types.DRESULT.RES_NOTRDY
drive_lock.lock()
@@ -40,6 +43,7 @@ def read(pdrv: t.CUInt8T, buff: t.CUInt8T | t.CPtr, sector: t.CUInt32T, count: t
return types.DRESULT.RES_OK
def write(pdrv: t.CUInt8T, buff: t.CConst | t.CUInt8T | t.CPtr, sector: t.CUInt32T, count: t.CUInt32T) -> types.DRESULT:
global drive_initialized, drive_lock
if pdrv >= MAX_DRIVES: return types.DRESULT.RES_PARERR
if not drive_initialized[pdrv]: return types.DRESULT.RES_NOTRDY
drive_lock.lock()
@@ -52,6 +56,7 @@ def write(pdrv: t.CUInt8T, buff: t.CConst | t.CUInt8T | t.CPtr, sector: t.CUInt3
return types.DRESULT.RES_OK
def ioctl(pdrv: t.CUInt8T, cmd: t.CUInt8T, buff: t.CVoid | t.CPtr) -> types.DRESULT:
global drive_initialized
if pdrv >= MAX_DRIVES: return types.DRESULT.RES_PARERR
if not drive_initialized[pdrv]: return types.DRESULT.RES_NOTRDY
match cmd:
@@ -34,6 +34,8 @@ part_is_fat32: t.CArray[t.CInt, MAX_VOLUMES * MAX_PARTITIONS]
num_drives: t.CInt = 0
def _init():
global num_drives, drive_letter_map, volume_mounted, drive_pdrv, drive_num_parts
global part_types, part_start_lbas, part_totals, part_is_fat32
if num_drives > 0: return
i: t.CInt
for i in range(MAX_VOLUMES):
@@ -52,6 +54,8 @@ def _part_idx(drive: t.CInt, part: t.CInt) -> t.CInt:
return drive * MAX_PARTITIONS + part
def parse_mbr(pdrv: t.CUInt8T, drive_idx: t.CInt) -> types.FRESULT:
global num_drives, drive_letter_map, volume_mounted, drive_pdrv, drive_num_parts
global part_types, part_start_lbas, part_totals, part_is_fat32
buf: t.CArray[t.CUInt8T, 512]
res: types.DRESULT = diskio.read(pdrv, c.Addr(buf[0]), 0, 1)
if res != types.DRESULT.RES_OK: return types.FRESULT.FR_DISK_ERR
@@ -79,6 +83,8 @@ def parse_mbr(pdrv: t.CUInt8T, drive_idx: t.CInt) -> types.FRESULT:
return types.FRESULT.FR_OK
def scan_drives() -> types.FRESULT:
global num_drives, drive_letter_map, volume_mounted, drive_pdrv, drive_num_parts
global part_types, part_start_lbas, part_totals, part_is_fat32
_init()
global num_drives
num_drives = 0
@@ -1647,10 +1647,11 @@ class dirobj:
handle_table: t.CArray[fileobj, MAX_HANDLES]
lock_table: t.CArray[filelock, MAX_LOCKS]
lock_table: t.CArray[filelock, MAX_LOCKS]
handles_initialized: t.CStatic | t.CInt = 0
def handles_init():
global handles_initialized, handle_table, lock_table
if handles_initialized: return
for i in range(MAX_HANDLES):
handle_table[i].is_open = 0
@@ -1660,6 +1661,7 @@ def handles_init():
handles_initialized = 1
def handle_alloc() -> fileobj | t.CPtr:
global handle_table
handles_init()
for i in range(MAX_HANDLES):
if not handle_table[i].is_open:
@@ -1667,6 +1669,7 @@ def handle_alloc() -> fileobj | t.CPtr:
return None
def lock_check(dir_sector: t.CUInt64T, dir_offset: t.CUInt32T, mode: t.CUInt8T) -> FRESULT:
global lock_table
handles_init()
for i in range(MAX_LOCKS):
lk: filelock | t.CPtr = c.Addr(lock_table[i])
@@ -1676,6 +1679,7 @@ def lock_check(dir_sector: t.CUInt64T, dir_offset: t.CUInt32T, mode: t.CUInt8T)
return FRESULT.FR_OK
def lock_acquire(dir_sector: t.CUInt64T, dir_offset: t.CUInt32T, exclusive: t.CInt) -> FRESULT:
global lock_table
handles_init()
for i in range(MAX_LOCKS):
lk: filelock | t.CPtr = c.Addr(lock_table[i])
@@ -1689,6 +1693,7 @@ def lock_acquire(dir_sector: t.CUInt64T, dir_offset: t.CUInt32T, exclusive: t.CI
return FRESULT.FR_TOO_MANY_OPEN_FILES
def lock_release(dir_sector: t.CUInt64T, dir_offset: t.CUInt32T):
global lock_table
handles_init()
for i in range(MAX_LOCKS):
lk: filelock | t.CPtr = c.Addr(lock_table[i])