diff --git a/src/bin/ch3_taskinfo.rs b/src/bin/ch3_taskinfo.rs index 7f55f15..b536599 100644 --- a/src/bin/ch3_taskinfo.rs +++ b/src/bin/ch3_taskinfo.rs @@ -11,12 +11,12 @@ use user_lib::{ #[no_mangle] pub fn main() -> usize { let t1 = get_time() as usize; - let info = TaskInfo::new(); + let mut info = TaskInfo::new(); get_time(); sleep(500); let t2 = get_time() as usize; // 注意本次 task info 调用也计入 - assert_eq!(0, task_info(&info)); + assert_eq!(0, task_info(&mut info)); let t3 = get_time() as usize; assert!(3 <= info.syscall_times[SYSCALL_GETTIMEOFDAY]); assert_eq!(1, info.syscall_times[SYSCALL_TASK_INFO]); @@ -30,7 +30,7 @@ pub fn main() -> usize { // 想想为什么 write 调用是两次 println!("string from task info test\n"); let t4 = get_time() as usize; - assert_eq!(0, task_info(&info)); + assert_eq!(0, task_info(&mut info)); let t5 = get_time() as usize; assert!(5 <= info.syscall_times[SYSCALL_GETTIMEOFDAY]); assert_eq!(2, info.syscall_times[SYSCALL_TASK_INFO]); diff --git a/src/bin/ch6_file1.rs b/src/bin/ch6_file1.rs index 6565121..26c3ed8 100644 --- a/src/bin/ch6_file1.rs +++ b/src/bin/ch6_file1.rs @@ -13,8 +13,8 @@ pub fn main() -> i32 { let fd = open(fname, OpenFlags::CREATE | OpenFlags::WRONLY); assert!(fd > 0); let fd = fd as usize; - let stat: Stat = Stat::new(); - let ret = fstat(fd, &stat); + let mut stat: Stat = Stat::new(); + let ret = fstat(fd, &mut stat); assert_eq!(ret, 0); assert_eq!(stat.mode, StatMode::FILE); assert_eq!(stat.nlink, 1); diff --git a/src/bin/ch6_file2.rs b/src/bin/ch6_file2.rs index c646314..a49c4d1 100644 --- a/src/bin/ch6_file2.rs +++ b/src/bin/ch6_file2.rs @@ -14,29 +14,29 @@ pub fn main() -> i32 { let (lname0, lname1, lname2) = ("linkname0\0", "linkname1\0", "linkname2\0"); let fd = open(fname, OpenFlags::CREATE | OpenFlags::WRONLY) as usize; link(fname, lname0); - let stat = Stat::new(); - fstat(fd, &stat); + let mut stat = Stat::new(); + fstat(fd, &mut stat); assert_eq!(stat.nlink, 2); link(fname, lname1); link(fname, lname2); - fstat(fd, &stat); + fstat(fd, &mut stat); assert_eq!(stat.nlink, 4); write(fd, test_str.as_bytes()); close(fd); unlink(fname); let fd = open(lname0, OpenFlags::RDONLY) as usize; - let stat2 = Stat::new(); + let mut stat2 = Stat::new(); let mut buf = [0u8; 100]; let read_len = read(fd, &mut buf) as usize; assert_eq!(test_str, core::str::from_utf8(&buf[..read_len]).unwrap(),); - fstat(fd, &stat2); + fstat(fd, &mut stat2); assert_eq!(stat2.dev, stat.dev); assert_eq!(stat2.ino, stat.ino); assert_eq!(stat2.nlink, 3); unlink(lname1); unlink(lname2); - fstat(fd, &stat2); + fstat(fd, &mut stat2); assert_eq!(stat2.nlink, 1); close(fd); unlink(lname0); diff --git a/src/lib.rs b/src/lib.rs index 233349e..4068f6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -203,7 +203,7 @@ pub fn unlink(path: &str) -> isize { sys_unlinkat(AT_FDCWD as usize, path, 0) } -pub fn fstat(fd: usize, st: &Stat) -> isize { +pub fn fstat(fd: usize, st: &mut Stat) -> isize { sys_fstat(fd, st) } @@ -307,7 +307,7 @@ pub fn pipe(pipe_fd: &mut [usize]) -> isize { sys_pipe(pipe_fd) } -pub fn task_info(info: &TaskInfo) -> isize { +pub fn task_info(info: &mut TaskInfo) -> isize { sys_task_info(info) } diff --git a/src/syscall.rs b/src/syscall.rs index c186281..776f7b7 100644 --- a/src/syscall.rs +++ b/src/syscall.rs @@ -128,7 +128,7 @@ pub fn sys_unlinkat(dirfd: usize, path: &str, flags: usize) -> isize { syscall(SYSCALL_UNLINKAT, [dirfd, path.as_ptr() as usize, flags]) } -pub fn sys_fstat(fd: usize, st: &Stat) -> isize { +pub fn sys_fstat(fd: usize, st: &mut Stat) -> isize { syscall(SYSCALL_FSTAT, [fd, st as *const _ as usize, 0]) } @@ -210,7 +210,7 @@ pub fn sys_pipe(pipe: &mut [usize]) -> isize { syscall(SYSCALL_PIPE, [pipe.as_mut_ptr() as usize, 0, 0]) } -pub fn sys_task_info(info: &TaskInfo) -> isize { +pub fn sys_task_info(info: &mut TaskInfo) -> isize { syscall(SYSCALL_TASK_INFO, [info as *const _ as usize, 0, 0]) }