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
8 changes: 4 additions & 4 deletions examples/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use std::time::{Duration, UNIX_EPOCH};

const TTL: Duration = Duration::from_secs(1); // 1 second

const FIOC_GET_SIZE: u64 = nix::request_code_read!('E', 0, std::mem::size_of::<usize>());
const FIOC_SET_SIZE: u64 = nix::request_code_write!('E', 1, std::mem::size_of::<usize>());

struct FiocFS {
content: Vec<u8>,
root_attr: FileAttr,
Expand Down Expand Up @@ -98,7 +101,7 @@ impl Filesystem for FiocFS {
reply: ReplyData,
) {
if ino == 2 {
reply.data(&self.content[offset as usize..])
reply.data(&self.content[offset as usize..]);
} else {
reply.error(ENOENT);
}
Expand Down Expand Up @@ -148,9 +151,6 @@ impl Filesystem for FiocFS {
return;
}

const FIOC_GET_SIZE: u64 = nix::request_code_read!('E', 0, std::mem::size_of::<usize>());
const FIOC_SET_SIZE: u64 = nix::request_code_write!('E', 1, std::mem::size_of::<usize>());

match cmd.into() {
FIOC_GET_SIZE => {
let size_bytes = self.content.len().to_ne_bytes();
Expand Down
2 changes: 1 addition & 1 deletion examples/notify_inval_inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Filesystem for ClockFS<'_> {
reply.error(EINVAL);
return;
};
let Ok(end) = (offset + size as i64).min(dlen).try_into() else {
let Ok(end) = (offset + i64::from(size)).min(dlen).try_into() else {
reply.error(EINVAL);
return;
};
Expand Down
2 changes: 1 addition & 1 deletion examples/passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl PassthroughFs {
Self {
root_attr,
passthrough_file_attr,
backing_cache: Default::default(),
backing_cache: BackingCache::default(),
}
}
}
Expand Down
22 changes: 10 additions & 12 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 @@ -498,7 +497,7 @@ impl Filesystem for SimpleFS {
hardlinks: 2,
uid: 0,
gid: 0,
xattrs: Default::default(),
xattrs: BTreeMap::default(),
};
self.write_inode(&root);
let mut entries = BTreeMap::new();
Expand Down Expand Up @@ -832,7 +831,7 @@ impl Filesystem for SimpleFS {
hardlinks: 1,
uid: req.uid(),
gid: creation_gid(&parent_attrs, req.gid()),
xattrs: Default::default(),
xattrs: BTreeMap::default(),
};
self.write_inode(&attrs);
File::create(self.content_path(inode)).unwrap();
Expand Down Expand Up @@ -910,7 +909,7 @@ impl Filesystem for SimpleFS {
hardlinks: 2, // Directories start with link count of 2, since they have a self link
uid: req.uid(),
gid: creation_gid(&parent_attrs, req.gid()),
xattrs: Default::default(),
xattrs: BTreeMap::default(),
};
self.write_inode(&attrs);

Expand Down Expand Up @@ -1089,7 +1088,7 @@ impl Filesystem for SimpleFS {
hardlinks: 1,
uid: req.uid(),
gid: creation_gid(&parent_attrs, req.gid()),
xattrs: Default::default(),
xattrs: BTreeMap::default(),
};

if let Err(error_code) = self.insert_link(req, parent, link_name, inode, FileKind::Symlink)
Expand Down Expand Up @@ -1797,7 +1796,7 @@ impl Filesystem for SimpleFS {
hardlinks: 1,
uid: req.uid(),
gid: creation_gid(&parent_attrs, req.gid()),
xattrs: Default::default(),
xattrs: BTreeMap::default(),
};
self.write_inode(&attrs);
File::create(self.content_path(inode)).unwrap();
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
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl KernelConfig {
fn congestion_threshold(&self) -> u16 {
match self.congestion_threshold {
// Default to a threshold of 3/4 of the max background threads
None => (self.max_background as u32 * 3 / 4) as u16,
None => (u32::from(self.max_background) * 3 / 4) as u16,
Some(value) => min(value, self.max_background),
}
}
Expand Down Expand Up @@ -991,7 +991,8 @@ pub fn spawn_mount<'a, FS: Filesystem + Send + 'static + 'a, P: AsRef<Path>>(
.map(|x| Some(MountOption::from_str(x.to_str()?)))
.collect();
let options = options.ok_or(ErrorKind::InvalidData)?;
Session::new(filesystem, mountpoint.as_ref(), options.as_ref()).and_then(|se| se.spawn())
Session::new(filesystem, mountpoint.as_ref(), options.as_ref())
.and_then(session::Session::spawn)
}

/// Mount the given filesystem to the given mountpoint. This function spawns
Expand All @@ -1007,5 +1008,5 @@ pub fn spawn_mount2<'a, FS: Filesystem + Send + 'static + 'a, P: AsRef<Path>>(
options: &[MountOption],
) -> io::Result<BackgroundSession> {
check_option_conflicts(options)?;
Session::new(filesystem, mountpoint.as_ref(), options).and_then(|se| se.spawn())
Session::new(filesystem, mountpoint.as_ref(), options).and_then(session::Session::spawn)
}
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
2 changes: 1 addition & 1 deletion src/ll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl Errno {
pub const NO_XATTR: Errno = Self::ENOATTR;

pub fn from_i32(err: i32) -> Errno {
err.try_into().ok().map(Errno).unwrap_or(Errno::EIO)
err.try_into().ok().map_or(Errno::EIO, Errno)
}
}
impl From<std::io::Error> for Errno {
Expand Down
7 changes: 4 additions & 3 deletions src/ll/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,13 @@ 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());
for x in data {
v.extend_from_slice(x)
v.extend_from_slice(x);
}
Self::Data(v)
}
Expand Down Expand Up @@ -291,7 +292,7 @@ pub(crate) fn mode_from_kind_and_perm(kind: FileType, perm: u16) -> u32 {
FileType::Symlink => libc::S_IFLNK,
FileType::Socket => libc::S_IFSOCK,
}) as u32
| perm as u32
| u32::from(perm)
}
/// Returns a `fuse_attr` from `FileAttr`
pub(crate) fn fuse_attr_from_attr(attr: &crate::FileAttr) -> abi::fuse_attr {
Expand Down
4 changes: 2 additions & 2 deletions src/ll/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,9 +954,9 @@ mod op {
pub fn capabilities(&self) -> u64 {
#[cfg(feature = "abi-7-36")]
if self.arg.flags & (FUSE_INIT_EXT as u32) != 0 {
return (self.arg.flags as u64) | ((self.arg.flags2 as u64) << 32);
return u64::from(self.arg.flags) | (u64::from(self.arg.flags2) << 32);
}
self.arg.flags as u64
u64::from(self.arg.flags)
}
pub fn max_readahead(&self) -> u32 {
self.arg.max_readahead
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
32 changes: 15 additions & 17 deletions src/mnt/mount_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,26 @@ 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(())
}
}

fn conflicts_with(option: &MountOption) -> Vec<MountOption> {
match option {
MountOption::FSName(_) => vec![],
MountOption::Subtype(_) => vec![],
MountOption::CUSTOM(_) => vec![],
MountOption::FSName(_)
| MountOption::Subtype(_)
| MountOption::CUSTOM(_)
| MountOption::DirSync
| MountOption::AutoUnmount
| MountOption::DefaultPermissions => vec![],
MountOption::AllowOther => vec![MountOption::AllowRoot],
MountOption::AllowRoot => vec![MountOption::AllowOther],
MountOption::AutoUnmount => vec![],
MountOption::DefaultPermissions => vec![],
MountOption::Dev => vec![MountOption::NoDev],
MountOption::NoDev => vec![MountOption::Dev],
MountOption::Suid => vec![MountOption::NoSuid],
Expand All @@ -120,7 +121,6 @@ fn conflicts_with(option: &MountOption) -> Vec<MountOption> {
MountOption::NoExec => vec![MountOption::Exec],
MountOption::Atime => vec![MountOption::NoAtime],
MountOption::NoAtime => vec![MountOption::Atime],
MountOption::DirSync => vec![],
MountOption::Sync => vec![MountOption::Async],
MountOption::Async => vec![MountOption::Sync],
}
Expand All @@ -133,10 +133,10 @@ pub fn option_to_string(option: &MountOption) -> String {
MountOption::Subtype(subtype) => format!("subtype={subtype}"),
MountOption::CUSTOM(value) => value.to_string(),
MountOption::AutoUnmount => "auto_unmount".to_string(),
MountOption::AllowOther => "allow_other".to_string(),
MountOption::AllowRoot |
// AllowRoot is implemented by allowing everyone access and then restricting to
// root + owner within fuser
MountOption::AllowRoot => "allow_other".to_string(),
MountOption::AllowOther => "allow_other".to_string(),
MountOption::DefaultPermissions => "default_permissions".to_string(),
MountOption::Dev => "dev".to_string(),
MountOption::NoDev => "nodev".to_string(),
Expand Down Expand Up @@ -174,7 +174,7 @@ pub(crate) fn parse_options_from_args(args: &[&OsStr]) -> io::Result<Vec<MountOp
Some(x) => return Err(err(format!("Error parsing args: expected -o, got {x}"))),
};
for x in opt.split(',') {
out.push(MountOption::from_str(x))
out.push(MountOption::from_str(x));
}
}
Ok(out)
Expand All @@ -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
Loading