diff --git a/easy-fs-fuse/src/main.rs b/easy-fs-fuse/src/main.rs index cf07b618..09e93456 100644 --- a/easy-fs-fuse/src/main.rs +++ b/easy-fs-fuse/src/main.rs @@ -61,7 +61,7 @@ fn easy_fs_pack() -> std::io::Result<()> { }))); // 16MiB, at most 4095 files let efs = EasyFileSystem::create( - block_file.clone(), + block_file, 16 * 2048, 1, ); diff --git a/easy-fs/src/bitmap.rs b/easy-fs/src/bitmap.rs index 4feaa9cf..5474e749 100644 --- a/easy-fs/src/bitmap.rs +++ b/easy-fs/src/bitmap.rs @@ -17,7 +17,7 @@ pub struct Bitmap { /// Return (block_pos, bits64_pos, inner_pos) fn decomposition(mut bit: usize) -> (usize, usize, usize) { let block_pos = bit / BLOCK_BITS; - bit = bit % BLOCK_BITS; + bit %= BLOCK_BITS; (block_pos, bit / 64, bit % 64) } @@ -70,4 +70,4 @@ impl Bitmap { pub fn maximum(&self) -> usize { self.blocks * BLOCK_BITS } -} \ No newline at end of file +} diff --git a/easy-fs/src/layout.rs b/easy-fs/src/layout.rs index c6f7b315..b5295de1 100644 --- a/easy-fs/src/layout.rs +++ b/easy-fs/src/layout.rs @@ -289,35 +289,26 @@ impl DiskInode { .lock() .modify(0, |indirect2: &mut IndirectBlock| { // full indirect1 blocks - for i in 0..a1 { - v.push(indirect2[i]); - get_block_cache( - indirect2[i] as usize, - Arc::clone(block_device), - ) - .lock() - .modify(0, |indirect1: &mut IndirectBlock| { - for j in 0..INODE_INDIRECT1_COUNT { - v.push(indirect1[j]); - //indirect1[j] = 0; - } - }); - //indirect2[i] = 0; + for entry in indirect2.iter_mut().take(a1) { + v.push(*entry); + get_block_cache(*entry as usize, Arc::clone(block_device)) + .lock() + .modify(0, |indirect1: &mut IndirectBlock| { + for entry in indirect1.iter() { + v.push(*entry); + } + }); } // last indirect1 block if b1 > 0 { v.push(indirect2[a1]); - get_block_cache( - indirect2[a1] as usize, - Arc::clone(block_device), - ) - .lock() - .modify(0, |indirect1: &mut IndirectBlock| { - for j in 0..b1 { - v.push(indirect1[j]); - //indirect1[j] = 0; - } - }); + get_block_cache(indirect2[a1] as usize, Arc::clone(block_device)) + .lock() + .modify(0, |indirect1: &mut IndirectBlock| { + for entry in indirect1.iter().take(b1) { + v.push(*entry); + } + }); //indirect2[a1] = 0; } }); @@ -445,4 +436,4 @@ impl DirEntry { pub fn inode_number(&self) -> u32 { self.inode_number } -} \ No newline at end of file +} diff --git a/easy-fs/src/vfs.rs b/easy-fs/src/vfs.rs index 9534c39a..4dfd31b0 100644 --- a/easy-fs/src/vfs.rs +++ b/easy-fs/src/vfs.rs @@ -110,12 +110,13 @@ impl Inode { pub fn create(&self, name: &str) -> Option> { let mut fs = self.fs.lock(); - if self.modify_disk_inode(|root_inode| { + let op = |root_inode: &mut DiskInode| { // assert it is a directory assert!(root_inode.is_dir()); // has the file been created? self.find_inode_id(name, root_inode) - }).is_some() { + }; + if self.modify_disk_inode(op).is_some() { return None; } // create a new file diff --git a/os/src/fs/pipe.rs b/os/src/fs/pipe.rs index ed2dde15..08d51daf 100644 --- a/os/src/fs/pipe.rs +++ b/os/src/fs/pipe.rs @@ -78,12 +78,10 @@ impl PipeRingBuffer { pub fn available_read(&self) -> usize { if self.status == RingBufferStatus::EMPTY { 0 + } else if self.tail > self.head { + self.tail - self.head } else { - if self.tail > self.head { - self.tail - self.head - } else { - self.tail + RING_BUFFER_SIZE - self.head - } + self.tail + RING_BUFFER_SIZE - self.head } } pub fn available_write(&self) -> usize { @@ -165,4 +163,4 @@ impl File for Pipe { } } } -} \ No newline at end of file +} diff --git a/os/src/mm/frame_allocator.rs b/os/src/mm/frame_allocator.rs index 357db707..3afe336b 100644 --- a/os/src/mm/frame_allocator.rs +++ b/os/src/mm/frame_allocator.rs @@ -62,13 +62,11 @@ impl FrameAllocator for StackFrameAllocator { fn alloc(&mut self) -> Option { if let Some(ppn) = self.recycled.pop() { Some(ppn.into()) + } else if self.current == self.end { + None } else { - if self.current == self.end { - None - } else { - self.current += 1; - Some((self.current - 1).into()) - } + self.current += 1; + Some((self.current - 1).into()) } } fn dealloc(&mut self, ppn: PhysPageNum) { @@ -131,4 +129,4 @@ pub fn frame_allocator_test() { } drop(v); println!("frame_allocator_test passed!"); -} \ No newline at end of file +} diff --git a/user/src/bin/cmdline_args.rs b/user/src/bin/cmdline_args.rs index b49ec332..9a227456 100644 --- a/user/src/bin/cmdline_args.rs +++ b/user/src/bin/cmdline_args.rs @@ -9,8 +9,8 @@ extern crate user_lib; #[no_mangle] pub fn main(argc: usize, argv: &[&str]) -> i32 { println!("argc = {}", argc); - for i in 0..argc { - println!("argv[{}] = {}", i, argv[i]); + for (i, arg) in argv.iter().enumerate() { + println!("argv[{}] = {}", i, arg); } 0 -} \ No newline at end of file +} diff --git a/user/src/bin/huge_write.rs b/user/src/bin/huge_write.rs index b00ca17b..4b0daaf8 100644 --- a/user/src/bin/huge_write.rs +++ b/user/src/bin/huge_write.rs @@ -15,8 +15,8 @@ use user_lib::{ #[no_mangle] pub fn main() -> i32 { let mut buffer = [0u8; 1024]; // 1KiB - for i in 0..buffer.len() { - buffer[i] = i as u8; + for (i, ch) in buffer.iter_mut().enumerate() { + *ch = i as u8; } let f = open("testf\0", OpenFlags::CREATE | OpenFlags::WRONLY); if f < 0 { diff --git a/user/src/bin/initproc.rs b/user/src/bin/initproc.rs index a9b8048a..fba348cb 100644 --- a/user/src/bin/initproc.rs +++ b/user/src/bin/initproc.rs @@ -1,7 +1,6 @@ #![no_std] #![no_main] -#[macro_use] extern crate user_lib; use user_lib::{ @@ -14,7 +13,7 @@ use user_lib::{ #[no_mangle] fn main() -> i32 { if fork() == 0 { - exec("user_shell\0", &[0 as *const u8]); + exec("user_shell\0", &[core::ptr::null::()]); } else { loop { let mut exit_code: i32 = 0; diff --git a/user/src/bin/matrix.rs b/user/src/bin/matrix.rs index 8f1357ea..c2461cf2 100644 --- a/user/src/bin/matrix.rs +++ b/user/src/bin/matrix.rs @@ -1,5 +1,6 @@ #![no_std] #![no_main] +#![allow(clippy::needless_range_loop)] #[macro_use] extern crate user_lib; diff --git a/user/src/bin/pipe_large_test.rs b/user/src/bin/pipe_large_test.rs index 121987be..6f4f5000 100644 --- a/user/src/bin/pipe_large_test.rs +++ b/user/src/bin/pipe_large_test.rs @@ -40,8 +40,8 @@ pub fn main() -> i32 { // close write end of up pipe close(up_pipe_fd[1]); // generate a long random string - for i in 0..LENGTH { - random_str[i] = get_time() as u8; + for ch in random_str.iter_mut() { + *ch = get_time() as u8; } // send it assert_eq!(write(down_pipe_fd[1], &random_str) as usize, random_str.len()); @@ -66,4 +66,4 @@ pub fn main() -> i32 { println!("pipe_large_test passed!"); 0 } -} \ No newline at end of file +} diff --git a/user/src/bin/run_pipe_test.rs b/user/src/bin/run_pipe_test.rs index 000b82d5..f0f95b03 100644 --- a/user/src/bin/run_pipe_test.rs +++ b/user/src/bin/run_pipe_test.rs @@ -10,7 +10,7 @@ use user_lib::{fork, exec, wait}; pub fn main() -> i32 { for i in 0..1000 { if fork() == 0 { - exec("pipe_large_test\0", &[0 as *const u8]); + exec("pipe_large_test\0", &[core::ptr::null::()]); } else { let mut _unused: i32 = 0; wait(&mut _unused); @@ -18,4 +18,4 @@ pub fn main() -> i32 { } } 0 -} \ No newline at end of file +} diff --git a/user/src/bin/user_shell.rs b/user/src/bin/user_shell.rs index 09c6ea8b..3514d549 100644 --- a/user/src/bin/user_shell.rs +++ b/user/src/bin/user_shell.rs @@ -1,5 +1,6 @@ #![no_std] #![no_main] +#![allow(clippy::println_empty_string)] extern crate alloc; @@ -72,7 +73,7 @@ impl ProcessArguments { .iter() .map(|arg| arg.as_ptr()) .collect(); - args_addr.push(0 as *const u8); + args_addr.push(core::ptr::null::()); Self { input, @@ -105,10 +106,8 @@ pub fn main() -> i32 { if !process_args.output.is_empty() { valid = false; } } else if i == process_arguments_list.len() - 1 { if !process_args.input.is_empty() { valid = false; } - } else { - if !process_args.output.is_empty() || !process_args.input.is_empty() { - valid = false; - } + } else if !process_args.output.is_empty() || !process_args.input.is_empty() { + valid = false; } } if process_arguments_list.len() == 1 { valid = true; } diff --git a/user/src/bin/usertests.rs b/user/src/bin/usertests.rs index e8be6c45..83da4d59 100644 --- a/user/src/bin/usertests.rs +++ b/user/src/bin/usertests.rs @@ -26,7 +26,7 @@ pub fn main() -> i32 { println!("Usertests: Running {}", test); let pid = fork(); if pid == 0 { - exec(*test, &[0 as *const u8]); + exec(*test, &[core::ptr::null::()]); panic!("unreachable!"); } else { let mut exit_code: i32 = Default::default(); @@ -37,4 +37,4 @@ pub fn main() -> i32 { } println!("Usertests passed!"); 0 -} \ No newline at end of file +}