8000 尝试适配该模块的时候发现第一个文件可以正常打开,但是第二个会读取到全零 · Issue #3 · elliott10/lwext4_rust · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
尝试适配该模块的时候发现第一个文件可以正常打开,但是第二个会读取到全零 #3
Open
@yuanccccccc

Description

@yuanccccccc

我们在尝试给自己的内核适配这个模块,下载了最新的模块到本地,但是尝试了适配之后出现了一些bug,运行日志如下:

/**** APPS ****
[DEBUG] /root/.cargo/git/checkouts/virtio-drivers-0a2b66ab1fb1c3fb/61ece50/src/transport/mod.rs:78 Device features: BlkFeature(SEG_MAX | GEOMETRY | BLK_SIZE | SCSI | FLUSH | TOPOLOGY | CONFIG_WCE | DISCARD | WRITE_ZEROES | NOTIFY_ON_EMPTY | RING_INDIRECT_DESC | RING_EVENT_IDX)
[INFO] /root/.cargo/git/checkouts/virtio-drivers-0a2b66ab1fb1c3fb/61ece50/src/device/blk.rs:59 config: 0xffffffc010001100
[INFO] /root/.cargo/git/checkouts/virtio-drivers-0a2b66ab1fb1c3fb/61ece50/src/device/blk.rs:64 found a block device of size 262144KB
[DEBUG] os/src/drivers/block/virtio_blk.rs:115 alloc paddr: FrameTracker:PA=0x87e02000
[DEBUG] os/src/drivers/block/virtio_blk.rs:115 alloc paddr: FrameTracker:PA=0x87e03000
[TRACE] os/src/mm/frame_allocator.rs:36 drop frame tracker: 0x87e02000
[TRACE] os/src/mm/frame_allocator.rs:36 drop frame tracker: 0x87e03000
[INFO] /code/lwext4_rust/src/blockdev.rs:92 New an Ext4 Block Device
[DEBUG] /code/lwext4_rust/src/blockdev.rs:112 OPEN Ext4 block device p_user=0xffffffc0802d5800
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 2, count: 2
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "[info]  sblock features_incompatible:\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "filetype\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "recover\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "extents\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "64bit\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "flex_bg\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "[info]  sblock features_compatible:\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "has_journal\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "ext_attr\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "resize_inode\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "dir_index\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "[info]  sblock features_read_only:\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "sparse_super\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "large_file\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "huge_file\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "dir_nlink\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "extra_isize\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "metadata_csum\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "[warn]  last umount error: superblock fs_error flag\n"
[DEBUG] /code/lwext4_rust/src/blockdev.rs:178 WRITE Ext4 block id: 2, count: 2
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 8, count: 8
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 296, count: 8
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 262408, count: 2
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "Start of journal at trans id: %u\n"
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 262416, count: 8
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "End of journal.\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "Start of journal at trans id: %u\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "End of journal.\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "Start of journal at trans id: %u\n"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "%s"
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "l: %d   "
[INFO] lwext4_rust/src/ulibc.rs:30 [lwext4] "End of journal.\n"
[DEBUG] /code/lwext4_rust/src/blockdev.rs:178 WRITE Ext4 block id: 2, count: 2
[DEBUG] /code/lwext4_rust/src/blockdev.rs:178 WRITE Ext4 block id: 262408, count: 2
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 262408, count: 2
[DEBUG] /code/lwext4_rust/src/blockdev.rs:178 WRITE Ext4 block id: 2, count: 2
[DEBUG] /code/lwext4_rust/src/blockdev.rs:178 WRITE Ext4 block id: 262408, count: 2
[INFO] /code/lwext4_rust/src/blockdev.rs:253 lwext4 mount Okay
[INFO] /code/lwext4_rust/src/blockdev.rs:305 ls /
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 33064, count: 8
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [dir] .
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [dir] ..
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [dir] lost+found
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] user_shell
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] cat
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] initproc
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] brk
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] chdir
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] clone
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] close
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] dup
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] dup2
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] execve
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] exit
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] fork
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] fstat
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] getcwd
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] getdents
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] getpid
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] getppid
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] gettimeofday
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] mkdir_
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] mmap
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [dir] mnt
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] mount
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] munmap
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] open
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] openat
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] pipe
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] read
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] run-all.sh
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] sleep
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] test_echo
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] text.txt
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] times
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] umount
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] uname
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] unlink
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] wait
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] waitpid
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] write
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] yield
[INFO] /code/lwext4_rust/src/blockdev.rs:323 
[INFO] /code/lwext4_rust/src/blockdev.rs:342 ********************
[INFO] /code/lwext4_rust/src/blockdev.rs:343 ext4_mount_point_stats
[INFO] /code/lwext4_rust/src/blockdev.rs:344 inodes_count = 10000
[INFO] /code/lwext4_rust/src/blockdev.rs:345 free_inodes_count = ffcd
[INFO] /code/lwext4_rust/src/blockdev.rs:346 blocks_count = 10000
[INFO] /code/lwext4_rust/src/blockdev.rs:347 free_blocks_count = dd41
[INFO] /code/lwext4_rust/src/blockdev.rs:348 block_size = 1000
[INFO] /code/lwext4_rust/src/blockdev.rs:349 block_group_count = 2
[INFO] /code/lwext4_rust/src/blockdev.rs:350 blocks_per_group= 8000
[INFO] /code/lwext4_rust/src/blockdev.rs:351 inodes_per_group = 8000
[INFO] /code/lwext4_rust/src/blockdev.rs:354 volume_name = ""
[INFO] /code/lwext4_rust/src/blockdev.rs:355 ********************

[INFO] /code/lwext4_rust/src/blockdev.rs:362 ********************
[INFO] /code/lwext4_rust/src/blockdev.rs:363 ext4 blockdev stats
[INFO] /code/lwext4_rust/src/blockdev.rs:365 bdev->bread_ctr = 7
[INFO] /code/lwext4_rust/src/blockdev.rs:366 bdev->bwrite_ctr = 5
[INFO] /code/lwext4_rust/src/blockdev.rs:368 bcache->ref_blocks = 3
[INFO] /code/lwext4_rust/src/blockdev.rs:369 bcache->max_ref_blocks = 3
[INFO] /code/lwext4_rust/src/blockdev.rs:373 bcache->lru_ctr = 92
[INFO] /code/lwext4_rust/src/blockdev.rs:375 ********************

[INFO] /code/lwext4_rust/src/blockdev.rs:305 ls /
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [dir] .
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [dir] ..
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [dir] lost+found
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] user_shell
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] cat
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] initproc
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] brk
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] chdir
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] clone
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] close
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] dup
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] dup2
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] execve
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] exit
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] fork
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] fstat
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] getcwd
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] getdents
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] getpid
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] getppid
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] gettimeofday
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] mkdir_
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] mmap
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [dir] mnt
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] mount
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] munmap
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] open
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] openat
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] pipe
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] read
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] run-all.sh
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] sleep
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] test_echo
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] text.txt
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] times
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] umount
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] uname
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] unlink
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] wait
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] waitpid
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] write
[INFO] /code/lwext4_rust/src/blockdev.rs:314   [fil] yield
[INFO] /code/lwext4_rust/src/blockdev.rs:323 
**************/
[TRACE] os/src/task/mod.rs:127 os::task::add_initproc
[DEBUG] lwext4_rust/src/file.rs:150 EXT4_DE_DIR /initproc No Exist. ext4_inode_exist rc = 2
[DEBUG] lwext4_rust/src/file.rs:147 EXT4_DE_REG_FILE /initproc Exist
[TRACE] lwext4_rust/src/file.rs:53 [file_open] called with path: /initproc, flags: 0x0
[DEBUG] lwext4_rust/src/file.rs:123 flags_to_cstring: rb
[TRACE] lwext4_rust/src/file.rs:70 [file_open] about to call ext4_fopen
[TRACE] lwext4_rust/src/file.rs:76 [file_open] ext4_fopen returned: 0
[DEBUG] lwext4_rust/src/file.rs:81 file_open /initproc, mp=0xffffffc0822d5658
[TRACE] lwext4_rust/src/file.rs:82 [file_open] success for path: /initproc
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 295928, count: 328
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 296256, count: 7
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 296263, count: 1
[DEBUG] lwext4_rust/src/file.rs:224 file_read "/initproc", len=171680
[DEBUG] lwext4_rust/src/file.rs:88 file_close "/initproc"
[TRACE] os/src/task/task.rs:126 os::task::TaskControlBlock::new
[TRACE] os/src/mm/memory_set.rs:162 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:188 os::mm::memory_set::MapArea::copy_data
[TRACE] os/src/mm/memory_set.rs:162 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:188 os::mm::memory_set::MapArea::copy_data
[TRACE] os/src/mm/memory_set.rs:162 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:188 os::mm::memory_set::MapArea::copy_data
[TRACE] os/src/mm/memory_set.rs:162 os::mm::memory_set::MapArea::map
[TRACE] os/src/task/processor.rs:41 os::task::processor::run_tasks
[TRACE] os/src/task/task.rs:100 os::task::task_entry
[TRACE] os/src/task/task.rs:217 os::task::TaskControlBlock::fork
[TRACE] os/src/mm/memory_set.rs:91 os::mm::MemorySet::from_existed_user
[TRACE] os/src/mm/memory_set.rs:162 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:162 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:162 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:162 os::mm::memory_set::MapArea::map
[TRACE] os/src/task/task.rs:100 os::task::task_entry
[INFO] os/src/syscall/process.rs:59 sys_exec: 0x13000  args: 0x13018
[DEBUG] lwext4_rust/src/file.rs:150 EXT4_DE_DIR /user_shell No Exist. ext4_inode_exist rc = 2
[DEBUG] lwext4_rust/src/file.rs:147 EXT4_DE_REG_FILE /user_shell Exist
[TRACE] lwext4_rust/src/file.rs:53 [file_open] called with path: /user_shell, flags: 0x0
[DEBUG] lwext4_rust/src/file.rs:123 flags_to_cstring: rb
[TRACE] lwext4_rust/src/file.rs:70 [file_open] about to call ext4_fopen
[TRACE] lwext4_rust/src/file.rs:76 [file_open] ext4_fopen returned: 0
[DEBUG] lwext4_rust/src/file.rs:81 file_open /user_shell, mp=0xffffffc0822d5658
[TRACE] lwext4_rust/src/file.rs:82 [file_open] success for path: /user_shell
[DEBUG] /code/lwext4_rust/src/blockdev.rs:144 READ Ext4 block id: 295176, count: 400
[ERROR] lwext4_rust/src/file.rs:220 ext4_fread: rc = 5
[DEBUG] lwext4_rust/src/file.rs:88 file_close "/user_shell"
[ERROR] os/src/lang_items.rs:8 [kernel] Panicked at os/src/syscall/process.rs:75 called `Result::unwrap()` on an `Err` value: EIO

我们的代码执行逻辑是:内核初始化完成之后,加载initporc文件到内存,initproc文件中会执行exec(usershell),usershell会执行一个命令行功能,但是在运行的时候,initproc加载可以正常执行,但是usershell出现了问题。之后我尝试在初始化之后直接加载usershell文件而跳过initporc,发现usershell可以正常执行其他功能,但是同样在执行exec的时候出现各种报错。我们的仓库地址:

https://gitlab.eduxiji.net/T202510055995406/nonix/-/tree/5ff6e2e38136bd08d6f8ac9f68b161d1bfd2b844

我们参考了去年的os大赛获奖内核的适配模块,地址:

https://gitlab.eduxiji.net/rusttrusthuster/oskernel2024-trustos/-/tree/master/lwext4_rust

trustos的架构是riscv64,但是我们需要使用抽象层来实现riscv和loongarch双架构,所以有许多不同,trust中使用了fat和ext4的vfs,我们在编程的时候直接跳过了vfs而是直接适配ext4模块。

在出现报错的之后,我们尝试了各种修改,也出现了各种bug,例如,出现assertion failed,但是没有找到调用位置,日志显示的位置是assert函数定义的位置。

首先是尝试了使用trustos中的lw模块进行使用(我们猜测他们对这个模块做出了一些修改,当然也可能是版本不同),调试的时候我们发现他们在c代码的bcache之外,还在file.rs中又封装了一层cache,而我们使用他们仓库中的lw_ext4的时候,出现了各种报错:
以下代码位置:https://gitlab.eduxiji.net/T202510055995406/nonix/-/tree/a09afcceff2833760a9484c262078ced00b0a488

  • 在初始化完成之后加载user_shell,然后在命令行中执行exit程序,然后出现卡死,我们分析是bcache某个块被多次释放或者其他原因,但是由于代码量太大我们没能成功debug。
**************/
[TRACE] os/src/task/mod.rs:127 os::task::add_initproc
[DEBUG] os/src/fs/ext4_lw/inode.rs:177 find: found regular file at path /user_shell
[DEBUG] os/src/fs/inode.rs:288 [open] found inode in root_inode: /user_shell
[DEBUG] os/src/fs/inode.rs:306 [open] returning opened OSInode for /user_shell
[DEBUG] os/src/fs/ext4_lw/inode.rs:143 [read_all] path: /user_shell, size: 208080
[DEBUG] lwext4_rust/src/file.rs:247 initialize cache! /user_shell
[DEBUG] lwext4_rust/src/file.rs:284 read 208080 bytes from file /user_shell: [127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 243, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 144, 42, 3, 0, 0, 0, 0, 0, 5, 0, 0, 0, 64, 0, 56, 0, 5, 0, 64, 0, 9, 0, 7, 0]
[TRACE] lwext4_rust/src/file.rs:340 find cache
[DEBUG] lwext4_rust/src/file.rs:345 cache data: [127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 243, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 144, 42, 3, 0, 0, 0, 0, 0, 5, 0, 0, 0, 64, 0, 56, 0, 5, 0, 64, 0, 9, 0, 7, 0]
[DEBUG] lwext4_rust/src/file.rs:349 read_size=208080,offset=0,end=208080,end-offset=208080
[DEBUG] lwext4_rust/src/file.rs:364 file_read /user_shell,len = 32cd0,offset is 0
[TRACE] os/src/task/task.rs:126 os::task::TaskControlBlock::new
7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
02 00 f3 00 01 00 00 00 00 00 01 00 00 00 00 00 
40 00 00 00 00 00 00 00 90 2a 03 00 00 00 00 00 
05 00 00 00 40 00 38 00 05 00 40 00 09 00 07 00 

[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:197 os::mm::memory_set::MapArea::copy_data
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:197 os::mm::memory_set::MapArea::copy_data
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:197 os::mm::memory_set::MapArea::copy_data
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/task/processor.rs:41 os::task::processor::run_tasks
[TRACE] os/src/task/task.rs:100 os::task::task_entry
[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
Rust user shell
[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
>> [TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
e[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
x[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
i[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
t[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer
[TRACE] os/src/mm/page_table.rs:65 os::mm::page_table::translated_byte_buffer

[TRACE] os/src/task/task.rs:217 os::task::TaskControlBlock::fork
[TRACE] os/src/mm/memory_set.rs:100 os::mm::MemorySet::from_existed_user
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/task/task.rs:100 os::task::task_entry
[INFO] os/src/syscall/process.rs:59 sys_exec: 0x1e008  args: 0x1e020
[INFO] lwext4_rust/src/ulibc.rs:17 assertion failed:
file: /home/zmy/work/os/oskernel2024-trustos/lwext4_rust/c/lwext4/src/ext4_bcache.c
line: 277

QEMU: Terminated
  • 在初始化完成之后加载initproc,然后会执行exec(user_shell),出现了别的问题:
**************/
[TRACE] os/src/task/mod.rs:127 os::task::add_initproc
[DEBUG] os/src/fs/ext4_lw/inode.rs:177 find: found regular file at path /initproc
[DEBUG] os/src/fs/inode.rs:288 [open] found inode in root_inode: /initproc
[DEBUG] os/src/fs/inode.rs:306 [open] returning opened OSInode for /initproc
[DEBUG] os/src/fs/ext4_lw/inode.rs:143 [read_all] path: /initproc, size: 171680
[DEBUG] lwext4_rust/src/file.rs:247 initialize cache! /initproc
[DEBUG] lwext4_rust/src/file.rs:284 read 171680 bytes from file /initproc: [127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 243, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 96, 156, 2, 0, 0, 0, 0, 0, 5, 0, 0, 0, 64, 0, 56, 0, 5, 0, 64, 0, 9, 0, 7, 0]
[TRACE] lwext4_rust/src/file.rs:340 find cache
[DEBUG] lwext4_rust/src/file.rs:345 cache data: [127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 243, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 96, 156, 2, 0, 0, 0, 0, 0, 5, 0, 0, 0, 64, 0, 56, 0, 5, 0, 64, 0, 9, 0, 7, 0]
[DEBUG] lwext4_rust/src/file.rs:349 read_size=171680,offset=0,end=171680,end-offset=171680
[DEBUG] lwext4_rust/src/file.rs:364 file_read /initproc,len = 29ea0,offset is 0
[TRACE] os/src/task/task.rs:126 os::task::TaskControlBlock::new
7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
02 00 f3 00 01 00 00 00 00 00 01 00 00 00 00 00 
40 00 00 00 00 00 00 00 60 9c 02 00 00 00 00 00 
05 00 00 00 40 00 38 00 05 00 40 00 09 00 07 00 

[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:197 os::mm::memory_set::MapArea::copy_data
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:197 os::mm::memory_set::MapArea::copy_data
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:197 os::mm::memory_set::MapArea::copy_data
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/task/processor.rs:41 os::task::processor::run_tasks
[TRACE] os/src/task/task.rs:100 os::task::task_entry
[TRACE] os/src/task/task.rs:217 os::task::TaskControlBlock::fork
[TRACE] os/src/mm/memory_set.rs:100 os::mm::MemorySet::from_existed_user
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/mm/memory_set.rs:171 os::mm::memory_set::MapArea::map
[TRACE] os/src/task/task.rs:100 os::task::task_entry
[INFO] os/src/syscall/process.rs:59 sys_exec: 0x13000  args: 0x13018
[DEBUG] os/src/fs/ext4_lw/inode.rs:177 find: found regular file at path /user_shell
[DEBUG] os/src/fs/inode.rs:288 [open] found inode in root_inode: /user_shell
[DEBUG] os/src/fs/inode.rs:306 [open] returning opened OSInode for /user_shell
[INFO] os/src/syscall/process.rs:75 open file end
[DEBUG] os/src/fs/ext4_lw/inode.rs:143 [read_all] path: /user_shell, size: 208080
[DEBUG] lwext4_rust/src/file.rs:247 initialize cache! /user_shell
[DEBUG] lwext4_rust/src/file.rs:284 read 0 bytes from file /user_shell: []
[TRACE] lwext4_rust/src/file.rs:340 find cache
[DEBUG] lwext4_rust/src/file.rs:345 cache data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[DEBUG] lwext4_rust/src/file.rs:349 read_size=208080,offset=0,end=208080,end-offset=208080
[DEBUG] lwext4_rust/src/file.rs:364 file_read /user_shell,len = 32cd0,offset is 0
[TRACE] os/src/task/task.rs:170 os::task::TaskControlBlock::exec
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

[ERROR] os/src/lang_items.rs:8 [kernel] Panicked at os/src/mm/memory_set.rs:48 called `Result::unwrap()` on an `Err` value: "Did not find ELF magic number"

出现这个报错之后,我尝试沿着调用流逐级打印读取到的信息,发现在trust仓库中的file.rs中的cache(不确定是版本还是他们自己写的)读取的时候就出现了全零的问题,而追根溯源之后,发现在他们第一次读取并放入cache的时候,也就是这个函数check_cached中,调用了ext4_fread

unsafe {
                ext4_fread(
                    &mut self.file_desc,
                    cache_writer.data.as_mut_ptr() as _,
                    size,
                    &mut rw_count,
                )
            };

之后打印出所读取的数据,发现rwcount是0,也就是什么都没有读取到。

到此处我们的debug就暂时卡住了,我只能去分析一下我们的适配代码和trust的适配代码的逻辑差异,但是目前进展缓慢。

PS:
另一个问题在于,我们需要loongarch,但是您仓库中的各种编译指令似乎都没有提到,有一位学长曾经告诉我,文件系统不接触硬件,但是可能引发各种问题导致读写不对齐运行缓慢。不过我也发现了您的模块在其他一些多架构的内核中也有用到,不知道是否会产生什么问题以及如何解决。
我尝试了修改trust仓库中的lwext4的c代码,但是不太明白应该如何编译c代码,我随意输入字符后仍然能够正常编译内核,显然我们在c中的print语句都没有什么用了,我尝试使用您readme中的命令:

make musl-generic -C c/lwext4 ARCH=riscv64

重新尝试了一下,命令执行成功了,我继续调试去~

一些可能相关的函数或文件:

user\src\bin\initproc.rs
user\src\bin\user_shell.rs
os\src\task\mod.rs\add_initproc: 导入初始化进程
os\src\drivers 块设备适配
os\src\fs 文件系统适配

期待您的解答,如果您方便,也非常希望您能给我通个会议来指点一下我们的一些修改,感谢

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0