cargo clippy

ch7-signal
Yifan Wu 3 years ago
parent ad85266da1
commit 2f5cff7e21

@ -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,
);

@ -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
}
}
}

@ -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
}
}
}

@ -110,12 +110,13 @@ impl Inode {
pub fn create(&self, name: &str) -> Option<Arc<Inode>> {
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

@ -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 {
}
}
}
}
}

@ -62,13 +62,11 @@ impl FrameAllocator for StackFrameAllocator {
fn alloc(&mut self) -> Option<PhysPageNum> {
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!");
}
}

@ -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
}
}

@ -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 {

@ -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::<u8>()]);
} else {
loop {
let mut exit_code: i32 = 0;

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![allow(clippy::needless_range_loop)]
#[macro_use]
extern crate user_lib;

@ -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
}
}
}

@ -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::<u8>()]);
} else {
let mut _unused: i32 = 0;
wait(&mut _unused);
@ -18,4 +18,4 @@ pub fn main() -> i32 {
}
}
0
}
}

@ -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::<u8>());
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; }

@ -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::<u8>()]);
panic!("unreachable!");
} else {
let mut exit_code: i32 = Default::default();
@ -37,4 +37,4 @@ pub fn main() -> i32 {
}
println!("Usertests passed!");
0
}
}

Loading…
Cancel
Save