Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ impl SimpleFS {
}

fn creation_mode(&self, mode: u32) -> u16 {
if !self.suid_support {
(mode & !(libc::S_ISUID | libc::S_ISGID) as u32) as u16
} else {
if self.suid_support {
mode as u16
} else {
(mode & !(libc::S_ISUID | libc::S_ISGID) as u32) as u16
}
}

Expand Down Expand Up @@ -432,9 +432,8 @@ impl SimpleFS {
let entries = self.get_directory_content(parent)?;
if let Some((inode, _)) = entries.get(name.as_bytes()) {
return self.get_inode(*inode);
} else {
return Err(libc::ENOENT);
}
return Err(libc::ENOENT);
}

fn insert_link(
Expand Down Expand Up @@ -1964,9 +1963,8 @@ fn as_file_kind(mut mode: u32) -> FileKind {
return FileKind::Symlink;
} else if mode == libc::S_IFDIR as u32 {
return FileKind::Directory;
} else {
unimplemented!("{mode}");
}
unimplemented!("{mode}");
}

fn get_groups(pid: u32) -> Vec<u32> {
Expand Down
11 changes: 5 additions & 6 deletions src/ll/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ impl<'a> ArgumentIterator<'a> {

#[cfg(test)]
pub mod tests {
use std::ops::Deref;

use super::super::test::AlignedData;
use super::*;
Expand All @@ -105,15 +104,15 @@ pub mod tests {

#[test]
fn all_data() {
let mut it = ArgumentIterator::new(TEST_DATA.deref());
let mut it = ArgumentIterator::new(&*TEST_DATA);
it.fetch_str().unwrap();
let arg = it.fetch_all();
assert_eq!(arg, [0x62, 0x61, 0x72, 0x00, 0x62, 0x61]);
}

#[test]
fn generic_argument() {
let mut it = ArgumentIterator::new(TEST_DATA.deref());
let mut it = ArgumentIterator::new(&*TEST_DATA);
let arg: &TestArgument = it.fetch().unwrap();
assert_eq!(arg.p1, 0x66);
assert_eq!(arg.p2, 0x6f);
Expand All @@ -127,7 +126,7 @@ pub mod tests {

#[test]
fn string_argument() {
let mut it = ArgumentIterator::new(TEST_DATA.deref());
let mut it = ArgumentIterator::new(&*TEST_DATA);
let arg = it.fetch_str().unwrap();
assert_eq!(arg, "foo");
let arg = it.fetch_str().unwrap();
Expand All @@ -137,7 +136,7 @@ pub mod tests {

#[test]
fn mixed_arguments() {
let mut it = ArgumentIterator::new(TEST_DATA.deref());
let mut it = ArgumentIterator::new(&*TEST_DATA);
let arg: &TestArgument = it.fetch().unwrap();
assert_eq!(arg.p1, 0x66);
assert_eq!(arg.p2, 0x6f);
Expand All @@ -150,7 +149,7 @@ pub mod tests {

#[test]
fn out_of_data() {
let mut it = ArgumentIterator::new(TEST_DATA.deref());
let mut it = ArgumentIterator::new(&*TEST_DATA);
it.fetch::<u64>().unwrap();
let arg: Option<&TestArgument> = it.fetch();
assert!(arg.is_none());
Expand Down
3 changes: 2 additions & 1 deletion src/ll/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ impl<'a> Response<'a> {
// these fields are only needed for unrestricted ioctls
flags: 0,
in_iovs: 1,
out_iovs: if !data.is_empty() { 1 } else { 0 },
// boolean to integer
out_iovs: u32::from(!data.is_empty()),
};
// TODO: Don't copy this data
let mut v: ResponseBuf = ResponseBuf::from_slice(r.as_bytes());
Expand Down
9 changes: 4 additions & 5 deletions src/mnt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ fn is_mounted(fuse_device: &File) -> bool {
let err = io::Error::last_os_error();
if err.kind() == io::ErrorKind::Interrupted {
continue;
} else {
// This should never happen. The fd is guaranteed good as `File` owns it.
// According to man poll ENOMEM is the only error code unhandled, so we panic
// consistent with rust's usual ENOMEM behaviour.
panic!("Poll failed with error {err}")
}
// This should never happen. The fd is guaranteed good as `File` owns it.
// According to man poll ENOMEM is the only error code unhandled, so we panic
// consistent with rust's usual ENOMEM behaviour.
panic!("Poll failed with error {err}")
}
_ => unreachable!(),
};
Expand Down
14 changes: 6 additions & 8 deletions src/mnt/mount_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ pub fn check_option_conflicts(options: &[MountOption]) -> Result<(), io::Error>
options_set.extend(options.iter().cloned());
let conflicting: HashSet<MountOption> = options.iter().flat_map(conflicts_with).collect();
let intersection: Vec<MountOption> = conflicting.intersection(&options_set).cloned().collect();
if !intersection.is_empty() {
if intersection.is_empty() {
Ok(())
} else {
Err(io::Error::new(
ErrorKind::InvalidInput,
format!("Conflicting mount options found: {intersection:?}"),
))
} else {
Ok(())
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ mod test {
#[test]
fn option_round_trip() {
use super::MountOption::*;
for x in [
for x in &[
FSName("Blah".to_owned()),
Subtype("Bloo".to_owned()),
CUSTOM("bongos".to_owned()),
Expand All @@ -214,10 +214,8 @@ mod test {
DirSync,
Sync,
Async,
]
.iter()
{
assert_eq!(*x, MountOption::from_str(option_to_string(x).as_ref()))
] {
assert_eq!(*x, MountOption::from_str(option_to_string(x).as_ref()));
}
}

Expand Down
21 changes: 10 additions & 11 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,17 @@ impl<'a> Request<'a> {
ll::Operation::IoCtl(x) => {
if x.unrestricted() {
return Err(Errno::ENOSYS);
} else {
se.filesystem.ioctl(
self,
self.request.nodeid().into(),
x.file_handle().into(),
x.flags(),
x.command(),
x.in_data(),
x.out_size(),
self.reply(),
);
}
se.filesystem.ioctl(
self,
self.request.nodeid().into(),
x.file_handle().into(),
x.flags(),
x.command(),
x.in_data(),
x.out_size(),
self.reply(),
);
}
ll::Operation::Poll(x) => {
let ph = PollHandle::new(se.ch.sender(), x.kernel_handle());
Expand Down
7 changes: 2 additions & 5 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use libc::{EAGAIN, EINTR, ENODEV, ENOENT};
use log::{info, warn};
use nix::unistd::geteuid;
use std::fmt;
use std::io;
use std::os::fd::{AsFd, BorrowedFd, OwnedFd};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::thread::{self, JoinHandle};
use std::{io, ops::DerefMut};

use crate::Filesystem;
use crate::MountOption;
Expand Down Expand Up @@ -146,10 +146,7 @@ impl<FS: Filesystem> Session<FS> {
// Buffer for receiving requests from the kernel. Only one is allocated and
// it is reused immediately after dispatching to conserve memory and allocations.
let mut buffer = vec![0; BUFFER_SIZE];
let buf = aligned_sub_buf(
buffer.deref_mut(),
std::mem::align_of::<abi::fuse_in_header>(),
);
let buf = aligned_sub_buf(&mut buffer, std::mem::align_of::<abi::fuse_in_header>());
loop {
// Read the next request from the given channel to kernel driver
// The kernel driver makes sure that we get exactly one request per read
Expand Down