Skip to content

Commit

Permalink
remove compiler and clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Sep 17, 2023
1 parent 6af27fa commit 89c6fa5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/fd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ use crate::env;
use crate::errno::*;
use crate::fd::file::{GenericFile, UhyveFile};
use crate::fd::stdio::*;
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
use crate::syscalls::fs::{self, Dirent, FileAttr, FilePerms, SeekWhence};
#[cfg(all(feature = "tcp", not(feature = "newlib")))]
#[cfg(all(any(feature = "tcp", feature = "udp"), not(feature = "newlib")))]
use crate::syscalls::net::*;

mod file;
Expand Down Expand Up @@ -345,6 +344,7 @@ pub(crate) fn open(name: *const u8, flags: i32, mode: i32) -> Result<FileDescrip
}
}

#[allow(unused_variables)]
pub(crate) fn opendir(name: *const u8) -> Result<FileDescriptor, i32> {
if env::is_uhyve() {
Err(-EINVAL)
Expand Down
42 changes: 22 additions & 20 deletions src/fs/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl PosixFileSystem for Fuse {
}

fn mkdir(&self, name: &str, mode: u32) -> Result<i32, FileError> {
let (mut cmd, mut rsp) = create_mkdir(name, mode);
let (cmd, mut rsp) = create_mkdir(name, mode);

get_filesystem_driver()
.ok_or(FileError::ENOSYS)?
Expand Down Expand Up @@ -231,7 +231,7 @@ impl Fuse {
}

pub fn readlink(&self, nid: u64) -> Result<String, FileError> {
let mut len = MAX_READ_LEN as u32;
let len = MAX_READ_LEN as u32;
let (cmd, mut rsp) = create_readlink(nid, len);
get_filesystem_driver()
.unwrap()
Expand Down Expand Up @@ -318,7 +318,7 @@ impl PosixFile for FuseDir {
return Err(FileError::EBADF);
};

let (mut cmd, mut rsp) = create_read(nid, fh, len, self.offset as u64);
let (mut cmd, mut rsp) = create_read(nid, fh, len, self.offset);
cmd.header.opcode = Opcode::FUSE_READDIR as u32;
if let Some(fs_driver) = get_filesystem_driver() {
fs_driver.lock().send_command(cmd.as_ref(), rsp.as_mut());
Expand Down Expand Up @@ -682,7 +682,7 @@ fn create_getattr(
(*raw).cmd = fuse_getattr_in {
getattr_flags: flags,
dummy: 0,
fh: fh,
fh,
};

Box::from_raw(raw)
Expand Down Expand Up @@ -1316,22 +1316,24 @@ pub struct fuse_attr {

impl fuse_attr {
unsafe fn fill_stat(self, stat: *mut FileAttr) {
(*stat).st_dev = 0;
(*stat).st_ino = self.ino;
(*stat).st_nlink = self.nlink as u64;
(*stat).st_mode = self.mode;
(*stat).st_uid = self.uid;
(*stat).st_gid = self.gid;
(*stat).st_rdev = self.rdev as u64;
(*stat).st_size = self.size.try_into().unwrap();
(*stat).st_blksize = self.blksize as i64;
(*stat).st_blocks = self.blocks.try_into().unwrap();
(*stat).st_atime = self.atime.try_into().unwrap();
(*stat).st_atime_nsec = self.atimensec as i64;
(*stat).st_mtime = self.mtime.try_into().unwrap();
(*stat).st_mtime_nsec = self.atimensec as i64;
(*stat).st_ctime = self.ctime.try_into().unwrap();
(*stat).st_ctime_nsec = self.ctimensec as i64;
unsafe {
(*stat).st_dev = 0;
(*stat).st_ino = self.ino;
(*stat).st_nlink = self.nlink as u64;
(*stat).st_mode = self.mode;
(*stat).st_uid = self.uid;
(*stat).st_gid = self.gid;
(*stat).st_rdev = self.rdev as u64;
(*stat).st_size = self.size.try_into().unwrap();
(*stat).st_blksize = self.blksize as i64;
(*stat).st_blocks = self.blocks.try_into().unwrap();
(*stat).st_atime = self.atime.try_into().unwrap();
(*stat).st_atime_nsec = self.atimensec as i64;
(*stat).st_mtime = self.mtime.try_into().unwrap();
(*stat).st_mtime_nsec = self.atimensec as i64;
(*stat).st_ctime = self.ctime.try_into().unwrap();
(*stat).st_ctime_nsec = self.ctimensec as i64;
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/syscalls/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ use hermit_sync::TicketMutex;
/// - FileDescriptor newtype
use crate::env::is_uhyve;
use crate::errno;
#[cfg(feature = "fs")]
pub use crate::fs::fuse::fuse_dirent as Dirent;
#[cfg(not(feature = "fs"))]
pub struct Dirent;

// TODO: lazy static could be replaced with explicit init on OS boot.
pub static FILESYSTEM: TicketMutex<Filesystem> = TicketMutex::new(Filesystem::new());
Expand Down Expand Up @@ -144,6 +147,7 @@ impl Filesystem {
}

/// Similar to open
#[allow(dead_code)]
pub fn opendir(&mut self, path: &str) -> Result<u64, FileError> {
debug!("Opening dir {}", path);
let (fs, internal_path) = self.parse_path(path)?;
Expand Down Expand Up @@ -171,6 +175,7 @@ impl Filesystem {
}

/// Remove directory given by path
#[allow(dead_code)]
pub fn rmdir(&mut self, path: &str) -> Result<(), FileError> {
debug!("Removing directory {}", path);
let (fs, internal_path) = self.parse_path(path)?;
Expand All @@ -179,6 +184,7 @@ impl Filesystem {
}

/// Create directory given by path
#[allow(dead_code)]
pub fn mkdir(&mut self, path: &str, mode: u32) -> Result<(), FileError> {
debug!("Removing directory {}", path);
let (fs, internal_path) = self.parse_path(path)?;
Expand All @@ -187,6 +193,7 @@ impl Filesystem {
}

/// stat
#[allow(dead_code)]
pub fn stat(&mut self, path: &str, stat: *mut FileAttr) -> Result<(), FileError> {
debug!("Getting stats {}", path);
let (fs, internal_path) = self.parse_path(path)?;
Expand All @@ -195,6 +202,7 @@ impl Filesystem {
}

/// lstat
#[allow(dead_code)]
pub fn lstat(&mut self, path: &str, stat: *mut FileAttr) -> Result<(), FileError> {
debug!("Getting lstats {}", path);
let (fs, internal_path) = self.parse_path(path)?;
Expand Down
3 changes: 2 additions & 1 deletion src/syscalls/interfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use core::ffi::CStr;

pub use self::generic::*;
pub use self::uhyve::*;
use crate::errno::ENOENT;
#[cfg(not(target_arch = "x86_64"))]
use crate::errno::ENOSYS;
use crate::syscalls::fs::{self, FileAttr};
use crate::{arch, env};

Expand Down
12 changes: 12 additions & 0 deletions src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,31 @@ pub extern "C" fn sys_unlink(name: *const u8) -> i32 {
kernel_function!(__sys_unlink(name))
}

#[cfg(target_arch = "x86_64")]
extern "C" fn __sys_mkdir(name: *const u8, mode: u32) -> i32 {
SYS.mkdir(name, mode)
}

#[cfg(not(target_arch = "x86_64"))]
extern "C" fn __sys_mkdir(_name: *const u8, _mode: u32) -> i32 {
-crate::errno::ENOSYS
}

#[no_mangle]
pub extern "C" fn sys_mkdir(name: *const u8, mode: u32) -> i32 {
kernel_function!(__sys_mkdir(name, mode))
}

#[cfg(target_arch = "x86_64")]
extern "C" fn __sys_rmdir(name: *const u8) -> i32 {
SYS.rmdir(name)
}

#[cfg(not(target_arch = "x86_64"))]
extern "C" fn __sys_rmdir(_name: *const u8) -> i32 {
-crate::errno::ENOSYS
}

#[no_mangle]
pub extern "C" fn sys_rmdir(name: *const u8) -> i32 {
kernel_function!(__sys_rmdir(name))
Expand Down

0 comments on commit 89c6fa5

Please sign in to comment.