Skip to content

Commit

Permalink
remove some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Jan 2, 2024
1 parent 876c75e commit 190b897
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 79 deletions.
4 changes: 2 additions & 2 deletions src/fd/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl<T> Socket<T> {
}

fn read(&self, buf: &mut [u8]) -> Result<isize, IoError> {
if buf.len() == 0 {
if buf.is_empty() {
return Ok(0);
}

Expand All @@ -275,7 +275,7 @@ impl<T> Socket<T> {
}

fn write(&self, buf: &[u8]) -> Result<isize, IoError> {
if buf.len() == 0 {
if buf.is_empty() {
return Ok(0);
}

Expand Down
9 changes: 5 additions & 4 deletions src/fs/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const U64_SIZE: u32 = ::core::mem::size_of::<u64>() as u32;
const S_IFLNK: u32 = 40960;
const S_IFMT: u32 = 61440;

#[allow(dead_code)]
const FUSE_GETATTR_FH: u32 = 1 << 0;

#[repr(C)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1151,7 +1152,7 @@ impl FuseFileHandleInner {
fn read(&mut self, buf: &mut [u8]) -> Result<isize, IoError> {
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;
}
Expand All @@ -1164,7 +1165,7 @@ impl FuseFileHandleInner {
let len: usize = if rsp.header.len as usize
- ::core::mem::size_of::<fuse_out_header>()
- ::core::mem::size_of::<fuse_read_out>()
>= len.try_into().unwrap()
>= len
{
len.try_into().unwrap()
} else {
Expand Down Expand Up @@ -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)
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/fs/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -336,7 +336,7 @@ impl RomHandle {

pub fn len(&self) -> usize {
let guard = self.data.read();
guard.len() as usize
guard.len()
}
}

Expand Down Expand Up @@ -367,8 +367,8 @@ impl RamHandle {

pub fn len(&self) -> usize {
let guard = self.data.read();
let ref vec: &Vec<u8> = guard.deref();
vec.len() as usize
let vec: &Vec<u8> = guard.deref();
vec.len()
}
}

Expand All @@ -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)]
Expand All @@ -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)) },
}
}
}
Expand Down
72 changes: 8 additions & 64 deletions src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod mem;
mod uhyve;

use alloc::boxed::Box;
use alloc::string::String;
use alloc::sync::Arc;
use alloc::vec::Vec;

Expand Down Expand Up @@ -96,7 +95,7 @@ impl Filesystem {
/// Tries to open file at given path.
pub fn open(&self, path: &str, opt: OpenOption) -> Result<Arc<dyn ObjectInterface>, 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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -156,7 +155,7 @@ impl Filesystem {
pub fn stat(&self, path: &str) -> Result<FileAttr, IoError> {
debug!("Getting stats {}", path);

let mut components: Vec<&str> = path.split("/").collect();
let mut components: Vec<&str> = path.split('/').collect();
components.reverse();
components.pop();

Expand All @@ -167,7 +166,7 @@ impl Filesystem {
pub fn lstat(&self, path: &str) -> Result<FileAttr, IoError> {
debug!("Getting lstats {}", path);

let mut components: Vec<&str> = path.split("/").collect();
let mut components: Vec<&str> = path.split('/').collect();
components.reverse();
components.pop();

Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/fs/uhyve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 190b897

Please sign in to comment.