From 5b5e5d9e2b24997bf4a6699ed02941fb3190d9d4 Mon Sep 17 00:00:00 2001 From: Stephen Marz Date: Fri, 15 May 2020 10:37:40 -0400 Subject: [PATCH] Fix warnings --- risc_v/src/fs.rs | 20 +++++++++----------- risc_v/src/gpu.rs | 5 ++--- risc_v/src/test.rs | 9 ++++----- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/risc_v/src/fs.rs b/risc_v/src/fs.rs index bad58e9..829029a 100755 --- a/risc_v/src/fs.rs +++ b/risc_v/src/fs.rs @@ -69,7 +69,6 @@ pub struct DirEntry { /// The MinixFileSystem implements the FileSystem trait for the VFS. pub struct MinixFileSystem { - bdev: usize, inode_cache: BTreeMap } @@ -163,14 +162,13 @@ impl MinixFileSystem { // Run this ONLY in a process! pub fn init(bdev: usize) -> Self { let mut btm = BTreeMap::new(); - let mut cwd = String::from("/"); + let cwd = String::from("/"); // Let's look at the root (inode #1) Self::cache_at(&mut btm, &cwd, 1, bdev); Self { - bdev, inode_cache: btm } } @@ -194,7 +192,7 @@ impl MinixFileSystem { let mut blocks_seen = 0u32; let offset_block = offset / BLOCK_SIZE; let mut offset_byte = offset % BLOCK_SIZE; - const num_indirect_pointers: usize = BLOCK_SIZE as usize / 4; + const NUM_INDIRECT_POINTERS: usize = BLOCK_SIZE as usize / 4; // First, the _size parameter (now in bytes_left) is the size of the buffer, not // necessarily the size of the file. If our buffer is bigger than the file, we're OK. // If our buffer is smaller than the file, then we can only read up to the buffer size. @@ -283,7 +281,7 @@ impl MinixFileSystem { if inode.zones[7] != 0 { syc_read(bdev, indirect_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * inode.zones[7]); let izones = indirect_buffer.get() as *const u32; - for i in 0..num_indirect_pointers { + for i in 0..NUM_INDIRECT_POINTERS{ // Where do I put unsafe? Dereferencing the pointers and memcpy are the unsafe functions. unsafe { if izones.add(i).read() != 0 { @@ -323,10 +321,10 @@ impl MinixFileSystem { if inode.zones[8] != 0 { syc_read(bdev, indirect_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * inode.zones[8]); unsafe { - for i in 0..num_indirect_pointers { + for i in 0..NUM_INDIRECT_POINTERS { if izones.add(i).read() != 0 { syc_read(bdev, iindirect_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * izones.add(i).read()); - for j in 0..num_indirect_pointers { + for j in 0..NUM_INDIRECT_POINTERS { if iizones.add(j).read() != 0 { // Notice that this inner code is the same for all end-zone pointers. I'm thinking about // moving this out of here into a function of its own, but that might make it harder @@ -369,10 +367,10 @@ impl MinixFileSystem { if inode.zones[9] != 0 { syc_read(bdev, indirect_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * inode.zones[9]); unsafe { - for i in 0..num_indirect_pointers { + for i in 0..NUM_INDIRECT_POINTERS { if izones.add(i).read() != 0 { syc_read(bdev, iindirect_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * izones.add(i).read()); - for j in 0..num_indirect_pointers { + for j in 0..NUM_INDIRECT_POINTERS { if iizones.add(j).read() != 0 { syc_read( bdev, @@ -380,7 +378,7 @@ impl MinixFileSystem { BLOCK_SIZE, BLOCK_SIZE * iizones.add(j,).read(), ); - for k in 0..num_indirect_pointers { + for k in 0..NUM_INDIRECT_POINTERS { if iiizones.add(k).read() != 0 { // Hey look! This again. if offset_block <= blocks_seen { @@ -425,7 +423,7 @@ impl MinixFileSystem { bytes_read } - pub fn write(&mut self, desc: &String, _buffer: *const u8, _offset: u32, _size: u32) -> u32 { + pub fn write(&mut self, _desc: &Inode, _buffer: *const u8, _offset: u32, _size: u32) -> u32 { 0 } diff --git a/risc_v/src/gpu.rs b/risc_v/src/gpu.rs index 2008211..442c518 100755 --- a/risc_v/src/gpu.rs +++ b/risc_v/src/gpu.rs @@ -4,10 +4,9 @@ // 12 May 2020 #![allow(dead_code)] -use crate::{kmem::{kfree, kmalloc}, - page::{zalloc, PAGE_SIZE}, +use crate::{page::{zalloc, PAGE_SIZE}, virtio, - virtio::{Descriptor, MmioOffsets, Queue, StatusField, VIRTIO_RING_SIZE}}; + virtio::{MmioOffsets, Queue, StatusField, VIRTIO_RING_SIZE}}; use core::{mem::size_of, ptr::null_mut}; pub struct GpuDevice { diff --git a/risc_v/src/test.rs b/risc_v/src/test.rs index 644aeba..64f78ce 100644 --- a/risc_v/src/test.rs +++ b/risc_v/src/test.rs @@ -16,16 +16,15 @@ use crate::{cpu::{build_satp, PROCESS_LIST, PROCESS_LIST_MUTEX, STACK_ADDR, - STACK_PAGES}, - syscall::{syscall_get_pid, syscall_fs_read, syscall_exit}}; + STACK_PAGES}}; use alloc::string::String; /// Test block will load raw binaries into memory to execute them. This function /// will load ELF files and try to execute them. pub fn test_elf() { // This won't be necessary after we connect this to the VFS, but for now, we need it. - const bdev: usize = 8; - let mfs = MinixFileSystem::init(bdev); + const BDEV: usize = 8; + let mfs = MinixFileSystem::init(BDEV); let desc = mfs.open(&String::from("/helloworld.elf")).ok(); if desc.is_none() { println!("Error reading /helloworld.elf"); @@ -39,7 +38,7 @@ pub fn test_elf() { // Read the file from the disk. I got the inode by mounting // the harddrive as a loop on Linux and stat'ing the inode. - let bytes_read = MinixFileSystem::read(bdev, &ino, buffer.get_mut(), ino.size, 0); + let bytes_read = MinixFileSystem::read(BDEV, &ino, buffer.get_mut(), ino.size, 0); // After compiling our program, I manually looked and saw it was 18,360 // bytes. So, to make sure we got the right one, I do a manual check // here.