diff --git a/src/fd/socket/tcp.rs b/src/fd/socket/tcp.rs index c75a9c3f67..307ea91b1c 100644 --- a/src/fd/socket/tcp.rs +++ b/src/fd/socket/tcp.rs @@ -253,7 +253,7 @@ impl Socket { } fn read(&self, buf: &mut [u8]) -> Result { - if buf.len() == 0 { + if buf.is_empty() { return Ok(0); } @@ -275,7 +275,7 @@ impl Socket { } fn write(&self, buf: &[u8]) -> Result { - if buf.len() == 0 { + if buf.is_empty() { return Ok(0); } diff --git a/src/fs/fuse.rs b/src/fs/fuse.rs index 07559718a6..2ddaac0235 100644 --- a/src/fs/fuse.rs +++ b/src/fs/fuse.rs @@ -31,6 +31,7 @@ const U64_SIZE: u32 = ::core::mem::size_of::() as u32; const S_IFLNK: u32 = 40960; const S_IFMT: u32 = 61440; +#[allow(dead_code)] const FUSE_GETATTR_FH: u32 = 1 << 0; #[repr(C)] @@ -202,7 +203,7 @@ struct fuse_attr { } impl fuse_attr { - fn to_stat(self) -> FileAttr { + fn to_stat(&self) -> FileAttr { FileAttr { st_ino: self.ino, st_nlink: self.nlink as u64, @@ -1151,7 +1152,7 @@ impl FuseFileHandleInner { fn read(&mut self, buf: &mut [u8]) -> Result { debug!("FUSE read!"); let mut len = buf.len(); - if len as usize > MAX_READ_LEN { + if len > MAX_READ_LEN { debug!("Reading longer than max_read_len: {}", len); len = MAX_READ_LEN; } @@ -1164,7 +1165,7 @@ impl FuseFileHandleInner { let len: usize = if rsp.header.len as usize - ::core::mem::size_of::() - ::core::mem::size_of::() - >= len.try_into().unwrap() + >= len { len.try_into().unwrap() } else { @@ -1498,7 +1499,7 @@ impl VfsNode for FuseDirectory { Ok(attr.to_stat()) } else { let path = readlink(rsp.nodeid)?; - let mut components: Vec<&str> = path.split("/").collect(); + let mut components: Vec<&str> = path.split('/').collect(); self.traverse_stat(&mut components) } } diff --git a/src/fs/mem.rs b/src/fs/mem.rs index e23312e0a9..0886e78466 100644 --- a/src/fs/mem.rs +++ b/src/fs/mem.rs @@ -143,7 +143,7 @@ impl MemDirectory { pub fn create_file(&self, name: &str, ptr: *const u8, length: usize) -> Result<(), IoError> { let name = name.trim(); - if name.find("/").is_none() { + if name.find('/').is_none() { let file = unsafe { MemFile::from_raw_parts(ptr, length) }; self.inner .0 @@ -336,7 +336,7 @@ impl RomHandle { pub fn len(&self) -> usize { let guard = self.data.read(); - guard.len() as usize + guard.len() } } @@ -367,8 +367,8 @@ impl RamHandle { pub fn len(&self) -> usize { let guard = self.data.read(); - let ref vec: &Vec = guard.deref(); - vec.len() as usize + let vec: &Vec = guard.deref(); + vec.len() } } @@ -384,8 +384,8 @@ impl Clone for RamHandle { /// Enumeration of possible methods to seek within an I/O object. #[derive(Debug, Clone)] enum DataHandle { - RAM(RamHandle), - ROM(RomHandle), + Ram(RamHandle), + Rom(RomHandle), } #[derive(Debug)] @@ -397,13 +397,13 @@ pub(crate) struct MemFile { impl MemFile { pub fn new() -> Self { Self { - data: DataHandle::RAM(RamHandle::new()), + data: DataHandle::Ram(RamHandle::new()), } } pub unsafe fn from_raw_parts(ptr: *const u8, length: usize) -> Self { Self { - data: unsafe { DataHandle::ROM(RomHandle::new(ptr, length)) }, + data: unsafe { DataHandle::Rom(RomHandle::new(ptr, length)) }, } } } diff --git a/src/fs/mod.rs b/src/fs/mod.rs index cd5c04cb57..61ffbb8120 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -4,7 +4,6 @@ mod mem; mod uhyve; use alloc::boxed::Box; -use alloc::string::String; use alloc::sync::Arc; use alloc::vec::Vec; @@ -96,7 +95,7 @@ impl Filesystem { /// Tries to open file at given path. pub fn open(&self, path: &str, opt: OpenOption) -> Result, IoError> { info!("Open file {}", path); - let mut components: Vec<&str> = path.split("/").collect(); + let mut components: Vec<&str> = path.split('/').collect(); components.reverse(); components.pop(); @@ -107,7 +106,7 @@ impl Filesystem { /// Unlinks a file given by path pub fn unlink(&self, path: &str) -> Result<(), IoError> { debug!("Unlinking file {}", path); - let mut components: Vec<&str> = path.split("/").collect(); + let mut components: Vec<&str> = path.split('/').collect(); components.reverse(); components.pop(); @@ -118,7 +117,7 @@ impl Filesystem { /// Remove directory given by path pub fn rmdir(&self, path: &str) -> Result<(), IoError> { debug!("Removing directory {}", path); - let mut components: Vec<&str> = path.split("/").collect(); + let mut components: Vec<&str> = path.split('/').collect(); components.reverse(); components.pop(); @@ -129,7 +128,7 @@ impl Filesystem { /// Create directory given by path pub fn mkdir(&self, path: &str, mode: u32) -> Result<(), IoError> { debug!("Create directory {}", path); - let mut components: Vec<&str> = path.split("/").collect(); + let mut components: Vec<&str> = path.split('/').collect(); components.reverse(); components.pop(); @@ -143,7 +142,7 @@ impl Filesystem { let mut components: Vec<&str> = Vec::new(); self.root.traverse_opendir(&mut components) } else { - let mut components: Vec<&str> = path.split("/").collect(); + let mut components: Vec<&str> = path.split('/').collect(); components.reverse(); components.pop(); @@ -156,7 +155,7 @@ impl Filesystem { pub fn stat(&self, path: &str) -> Result { debug!("Getting stats {}", path); - let mut components: Vec<&str> = path.split("/").collect(); + let mut components: Vec<&str> = path.split('/').collect(); components.reverse(); components.pop(); @@ -167,7 +166,7 @@ impl Filesystem { pub fn lstat(&self, path: &str) -> Result { debug!("Getting lstats {}", path); - let mut components: Vec<&str> = path.split("/").collect(); + let mut components: Vec<&str> = path.split('/').collect(); components.reverse(); components.pop(); @@ -182,7 +181,7 @@ impl Filesystem { ) -> Result<(), IoError> { debug!("Mounting {}", path); - let mut components: Vec<&str> = path.split("/").collect(); + let mut components: Vec<&str> = path.split('/').collect(); components.reverse(); components.pop(); @@ -255,61 +254,6 @@ pub(crate) fn init() { #[cfg(all(feature = "fuse", feature = "pci"))] fuse::init(); uhyve::init(); - - /*let fd = crate::sys_opendir("/\0".as_ptr()); - info!("fd {}", fd); - loop { - if let crate::fd::DirectoryEntry::Valid(dirent) = crate::sys_readdir(fd) { - if dirent == core::ptr::null() { - break; - } - - let s = unsafe { - String::from_raw_parts( - &(*dirent).d_name as *const _ as *mut u8, - (*dirent).d_namelen as usize, - (*dirent).d_namelen as usize, - ) - }; - info!("dirent.d_name {:?}", s); - core::mem::forget(s); - } - } - - let fd = crate::sys_opendir("/root\0".as_ptr()); - info!("fd {}", fd); - loop { - if let crate::fd::DirectoryEntry::Valid(dirent) = crate::sys_readdir(fd) { - if dirent == core::ptr::null() { - break; - } - - let s = unsafe { - String::from_raw_parts( - &(*dirent).d_name as *const _ as *mut u8, - (*dirent).d_namelen as usize, - (*dirent).d_namelen as usize, - ) - }; - info!("dirent.d_name {:?}", s); - core::mem::forget(s); - } - } - - let mut attr: FileAttr = Default::default(); - let ret = crate::sys_lstat("/root/hello.txt\0".as_ptr(), &mut attr as *mut FileAttr); - info!("ret {} {:?}", ret, attr); - - let fd = crate::sys_open("/root/hello.txt\0".as_ptr(), 0o0000, 0); - info!("fd {}", fd); - let mut values = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - let ret = crate::sys_read(fd, values.as_mut_ptr(), values.len()); - info!( - "result {} {}", - unsafe { String::from_utf8_unchecked(values) }, - ret - ); - crate::sys_close(fd);*/ } pub unsafe fn create_file(name: &str, ptr: *const u8, length: usize) { diff --git a/src/fs/uhyve.rs b/src/fs/uhyve.rs index 2f6e522dc9..e7dc9af143 100644 --- a/src/fs/uhyve.rs +++ b/src/fs/uhyve.rs @@ -306,7 +306,7 @@ impl VfsNode for UhyveDirectory { pub(crate) fn init() { info!("Try to initialize uhyve filesystem"); if is_uhyve() { - let mount_point = format!("/host"); + let mount_point = "/host".to_string(); info!("Mounting virtio-fs at {}", mount_point); fs::FILESYSTEM .get()