summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2021-12-24 04:58:51 -0600
committerAlejandro Soto <alejandro@34project.org>2021-12-24 05:07:23 -0600
commit311b2a40213aa48131a189f99dc4258d354c0c78 (patch)
tree3f4fd971a7b94d07f11a8c878e0bc665bdf61f67
parent5afc15edaa593bdf7dd2ae7c542980d9d70b8321 (diff)
Fix old warnings
-rw-r--r--examples/ext2.rs17
-rw-r--r--src/buffers.rs0
-rw-r--r--src/client.rs47
-rw-r--r--src/fuse/fs.rs55
-rw-r--r--src/fuse/io.rs4
-rw-r--r--src/fuse/ops.rs11
-rw-r--r--src/fuse/session.rs52
-rw-r--r--src/proto.rs13
-rw-r--r--src/util.rs4
9 files changed, 42 insertions, 161 deletions
diff --git a/examples/ext2.rs b/examples/ext2.rs
index 996d1fd..c1f4bce 100644
--- a/examples/ext2.rs
+++ b/examples/ext2.rs
@@ -322,7 +322,7 @@ impl Fuse for Ext2 {
"(empty)".into()
}
})
- .unwrap_or("(bad)".into());
+ .unwrap_or_else(|| "(bad)".into());
log::info!("UUID: {}", Uuid::from_bytes(self.superblock.s_uuid));
log::info!("Label: {}", label.escape_debug());
@@ -476,10 +476,6 @@ impl blown_fuse::fs::Inode for Inode {
}
}
-fn early_error<T, E: From<Errno>>(_: ()) -> Result<T, E> {
- Err(Errno::EINVAL.into())
-}
-
fn main() -> Result<(), Box<dyn std::error::Error>> {
let matches = App::new("ext2")
.about("read-only ext2 FUSE driver")
@@ -535,16 +531,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let superblock = superblock.and_then(|superblock| try_from_bytes(superblock).ok());
let superblock: &'static Superblock = match superblock {
Some(superblock) => superblock,
- None => return early_error(log::error!("Bad superblock")),
+ None => {
+ log::error!("Bad superblock");
+ return Err(Errno::EINVAL.into());
+ }
};
if superblock.s_magic != 0xef53 {
- return early_error(log::error!("Bad magic"));
+ log::error!("Bad magic");
+ return Err(Errno::EINVAL.into());
}
let (major, minor) = (superblock.s_rev_level, superblock.s_minor_rev_level);
if (major, minor) != (1, 0) {
- return early_error(log::error!("Unsupported revision: {}.{}", major, minor));
+ log::error!("Unsupported revision: {}.{}", major, minor);
+ return Err(Errno::EINVAL.into());
}
let fs = Ext2 {
diff --git a/src/buffers.rs b/src/buffers.rs
deleted file mode 100644
index e69de29..0000000
--- a/src/buffers.rs
+++ /dev/null
diff --git a/src/client.rs b/src/client.rs
index 9f036c3..e1fcc89 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -3,50 +3,3 @@
//! Usually, a kernel module or other OS component takes the role of the FUSE client. This module
//! is a client-wise counterpart to the rest of `blown-fuse` API. So far, this only serves the
//! purpose of having agnostic tests, but wrappers might be written in the future with it.
-
-/*use crate::{proto, FuseResult};
-
-#[cfg(feature = "server")]
-use crate::session;
-
-struct Client {}
-
-struct RequestContext<'a> {
- client: &'a,
- uid: Uid,
- gid: Gid,
- pid: Pid,
-}
-
-impl Client {
- pub fn context(&self, uid: Uid, gid: Gid, pid: Pid) -> RequestContext<'_> {
- RequestContext {
- client: &self,
- uid,
- gid,
- pid,
- }
- }
-}
-
-impl RequestContext<'_> {
- pub async fn lookup(&self) -> FuseResult<> {
- self.tail()
- }
-}
-
-struct Start {}
-
-impl Start {
- pub async fn start(self) -> FuseResult<Session> {
-
- }
-}
-
-#[cfg(feature = "server")]
-pub fn channel() -> std::io::Result<(session::Start, self::Start)> {
- let client_start = ;
- let server_start = ;
-
- (client_stasrt, server_start)
-}*/
diff --git a/src/fuse/fs.rs b/src/fuse/fs.rs
index 4cf3282..0c39ea7 100644
--- a/src/fuse/fs.rs
+++ b/src/fuse/fs.rs
@@ -1,13 +1,6 @@
-use async_trait::async_trait;
-use nix::errno::Errno;
-
-use std::{
- num::NonZeroUsize,
- ops::{Deref, DerefMut},
- sync::Arc,
-};
-
use crate::{Ino, TimeToLive};
+use async_trait::async_trait;
+use std::{num::NonZeroUsize, ops::Deref, sync::Arc};
use super::{
io::{Attrs, EntryType},
@@ -43,7 +36,7 @@ pub trait Inode: Send + Sync {
fn attrs(self: &FarcTo<Self>) -> (Attrs, TimeToLive);
fn inode_type(self: &FarcTo<Self>) -> EntryType;
- fn direct_io<'o>(self: &FarcTo<Self>) -> bool {
+ fn direct_io(self: &FarcTo<Self>) -> bool {
false
}
@@ -82,46 +75,4 @@ pub trait Inode: Send + Sync {
}
}
-#[async_trait]
-pub trait Tape: Send + Sync {
- type Fuse: Fuse;
-
- async fn seek(self: &mut Head<Self>, offset: u64) -> Result<(), Errno>;
-
- async fn rewind(self: &mut Head<Self>) -> Result<(), Errno> {
- self.seek(0).await
- }
-
- async fn read<'o>(self: &mut Head<Self>, (_, reply, _): Op<'o, Self::Fuse, Read>) -> Done<'o> {
- reply.not_implemented()
- }
-
- async fn write<'o>(
- self: &mut Head<Self>,
- (_, reply, _): Op<'o, Self::Fuse, Write>,
- ) -> Done<'o> {
- reply.not_implemented()
- }
-}
-
pub type FarcTo<I> = <<I as Inode>::Fuse as Fuse>::Farc;
-
-pub struct Head<T: Tape + ?Sized> {
- offset: u64,
- inode: <T::Fuse as Fuse>::Farc,
- tape: T,
-}
-
-impl<T: Tape + ?Sized> Deref for Head<T> {
- type Target = T;
-
- fn deref(&self) -> &Self::Target {
- &self.tape
- }
-}
-
-impl<T: Tape + ?Sized> DerefMut for Head<T> {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.tape
- }
-}
diff --git a/src/fuse/io.rs b/src/fuse/io.rs
index 450d9f7..305f0ef 100644
--- a/src/fuse/io.rs
+++ b/src/fuse/io.rs
@@ -68,7 +68,7 @@ impl<'o, Fs: Fuse, O: Operation<'o, Fs>> Reply<'o, Fs, O> {
F: Future<Output = T>,
{
tokio::pin!(f);
- let mut rx = session::interrupt_rx(&self.session);
+ let mut rx = session::interrupt_rx(self.session);
use Interruptible::*;
loop {
@@ -97,7 +97,7 @@ impl<'o, Fs: Fuse, O: Operation<'o, Fs>> Reply<'o, Fs, O> {
let errno = errno as i32;
O::consume_errno(errno, &mut self.tail);
- Done::from_result(session::fail(&self.session, self.unique, errno))
+ Done::from_result(session::fail(self.session, self.unique, errno))
}
pub fn not_implemented(self) -> Done<'o> {
diff --git a/src/fuse/ops.rs b/src/fuse/ops.rs
index bfbc70a..bbd49fe 100644
--- a/src/fuse/ops.rs
+++ b/src/fuse/ops.rs
@@ -55,7 +55,7 @@ op! {
/// be cached by the client for up to the given TTL.
pub fn found(self, entry: &Fs::Farc, ttl: TimeToLive) -> Done<'o> {
let (attrs, attrs_ttl) = <Fs as Fuse>::Inode::attrs(entry);
- session::unveil(&self.session, entry);
+ session::unveil(self.session, entry);
self.single(&make_entry(
(<Fs as Fuse>::Inode::ino(entry), ttl),
@@ -103,16 +103,11 @@ op! {
},
Reply {
- /// The iinode may now be accessed.
+ /// The inode may now be accessed.
pub fn ok(self) -> Done<'o> {
self.ok_with_handle(0)
}
- /*pub fn tape<R: Tape<Fuse = Fs>>(self, reel: R) -> Done<'o> {
- let (ino, _) = self.tail;
- self.ok_with_handle(session::allocate_handle(&self.session, ino, reel))
- }*/
-
fn ok_with_handle(self, handle: u64) -> Done<'o> {
let (_, flags) = self.tail;
self.single(&proto::OpenOut {
@@ -342,7 +337,7 @@ impl<'o, Fs: Fuse, O: Operation<'o, Fs>> Reply<'o, Fs, O> {
}
fn chain(self, chain: OutputChain<'_>) -> Done<'o> {
- Done::from_result(session::ok(&self.session, self.unique, chain))
+ Done::from_result(session::ok(self.session, self.unique, chain))
}
}
diff --git a/src/fuse/session.rs b/src/fuse/session.rs
index 4a34aae..8975c57 100644
--- a/src/fuse/session.rs
+++ b/src/fuse/session.rs
@@ -35,14 +35,6 @@ pub fn ok<Fs: Fuse>(session: &Session<Fs>, unique: u64, output: OutputChain<'_>)
session.send(unique, 0, output)
}
-pub fn notify<Fs: Fuse>(
- session: &Session<Fs>,
- op: proto::NotifyCode,
- output: OutputChain<'_>,
-) -> FuseResult<()> {
- session.send(0, op as i32, output)
-}
-
pub fn fail<Fs: Fuse>(session: &Session<Fs>, unique: u64, mut errno: i32) -> FuseResult<()> {
if errno <= 0 {
log::warn!(
@@ -164,7 +156,7 @@ impl<Fs: Fuse> Session<Fs> {
Ordering::Greater => {
let tail = [bytes_of(&proto::MAJOR_VERSION)];
- ok(&self, unique, OutputChain::tail(&tail))?;
+ ok(self, unique, OutputChain::tail(&tail))?;
return Ok(Handshake::Restart);
}
@@ -183,14 +175,14 @@ impl<Fs: Fuse> Session<Fs> {
major = proto::MAJOR_VERSION
);
- fail(&self, unique, Errno::EPROTONOSUPPORT as i32)?;
+ fail(self, unique, Errno::EPROTONOSUPPORT as i32)?;
return Err(ProtocolInit);
}
let root = {
let mut init_result = Err(0);
let reply = Reply {
- session: &self,
+ session: self,
unique,
tail: &mut init_result,
};
@@ -232,12 +224,12 @@ impl<Fs: Fuse> Session<Fs> {
};
let tail = [bytes_of(&init_out)];
- ok(&self, unique, OutputChain::tail(&tail))?;
+ ok(self, unique, OutputChain::tail(&tail))?;
Ok(Handshake::Done)
}
- async fn dispatch(self: &Arc<Self>, request: &mut Incoming<Fs>) -> FuseResult<()> {
+ async fn dispatch(self: &Arc<Self>, request: &mut Incoming) -> FuseResult<()> {
let request: proto::Request<'_> = request.buffer.data().try_into()?;
let header = request.header();
let InHeader { unique, ino, .. } = *header;
@@ -281,7 +273,7 @@ impl<Fs: Fuse> Session<Fs> {
Interrupt(body) => {
//TODO: Don't reply with EAGAIN if the interrupt is successful
let _ = self.interrupt_tx.send(body.unique);
- return fail(&self, unique, Errno::EAGAIN as i32);
+ return fail(self, unique, Errno::EAGAIN as i32);
}
Destroy => {
@@ -313,7 +305,7 @@ impl<Fs: Fuse> Session<Fs> {
ino
);
- return fail(&self, unique, Errno::ENOANO as i32);
+ return fail(self, unique, Errno::ENOANO as i32);
}
};
@@ -331,7 +323,7 @@ impl<Fs: Fuse> Session<Fs> {
attr: attrs,
};
- return ok(&self, unique, OutputChain::tail(&[bytes_of(&out)]));
+ return ok(self, unique, OutputChain::tail(&[bytes_of(&out)]));
}
Access(body) => {
@@ -363,7 +355,7 @@ impl<Fs: Fuse> Session<Fs> {
Opendir(body) => inode_op!(opendir, *body),
Readdir(body) => inode_op!(readdir, *body),
- _ => return fail(&self, unique, Errno::ENOSYS as i32),
+ _ => return fail(self, unique, Errno::ENOSYS as i32),
};
done.into_result()
@@ -398,7 +390,7 @@ impl<Fs: Fuse> Session<Fs> {
}
}
- async fn receive(self: &Arc<Self>) -> std::io::Result<Incoming<Fs>> {
+ async fn receive(self: &Arc<Self>) -> std::io::Result<Incoming> {
use InputBufferStorage::*;
let permit = Arc::clone(&self.input_semaphore)
@@ -407,7 +399,6 @@ impl<Fs: Fuse> Session<Fs> {
.unwrap();
let mut incoming = Incoming {
- session: Arc::clone(self),
buffer: InputBuffer {
bytes: 0,
data: Sbo(SboStorage([0; SBO_SIZE])),
@@ -452,17 +443,15 @@ impl<Fs: Fuse> Session<Fs> {
}
fn send(&self, unique: u64, error: i32, output: OutputChain<'_>) -> FuseResult<()> {
- let length = std::mem::size_of::<proto::OutHeader>();
- let length = length
- + output
- .iter()
- .map(<[_]>::iter)
- .flatten()
- .copied()
- .map(<[_]>::len)
- .sum::<usize>();
-
- let length = length.try_into().unwrap();
+ let after_header: usize = output
+ .iter()
+ .map(<[_]>::iter)
+ .flatten()
+ .copied()
+ .map(<[_]>::len)
+ .sum();
+
+ let length = (std::mem::size_of::<proto::OutHeader>() + after_header) as _;
let header = proto::OutHeader {
len: length,
error,
@@ -537,8 +526,7 @@ enum Handshake {
Restart,
}
-struct Incoming<Fs: Fuse> {
- session: Arc<Session<Fs>>,
+struct Incoming {
buffer: InputBuffer,
}
diff --git a/src/proto.rs b/src/proto.rs
index 9816922..53c2123 100644
--- a/src/proto.rs
+++ b/src/proto.rs
@@ -4,7 +4,7 @@ use bitflags::bitflags;
use bytemuck::{self, Pod};
use bytemuck_derive::{Pod, Zeroable};
use num_enum::TryFromPrimitive;
-use std::{convert::TryFrom, ffi::CStr, fmt, mem::replace};
+use std::{convert::TryFrom, ffi::CStr, fmt, mem};
use crate::{util::display_or, FuseError, FuseResult};
@@ -778,17 +778,10 @@ impl<'a> TryFrom<&'a [u8]> for Request<'a> {
return Err(BadLength);
}
- RequestBody::$op { prefix, data: replace(&mut bytes, &[]) }
+ RequestBody::$op { prefix, data: mem::take(&mut bytes) }
}
};
- /*($op:ident, $($field:ident),+) => {
- {
- $($field!($op, $field));+;
- RequestBody::$op { $($field),+ }
- }
- };*/
-
($op:ident, $($fields:ident),+) => {
{
build_body!($op, $($fields),+);
@@ -841,7 +834,7 @@ impl<'a> TryFrom<&'a [u8]> for Request<'a> {
BatchForget => {
prefix!(BatchForget, prefix);
- let forgets = replace(&mut bytes, &[]);
+ let forgets = mem::take(&mut bytes);
let forgets = bytemuck::try_cast_slice(forgets).map_err(|_| Truncated)?;
if prefix.count as usize != forgets.len() {
diff --git a/src/util.rs b/src/util.rs
index 5185efd..2ad8c00 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -61,12 +61,12 @@ impl<'a> OutputChain<'a> {
pub fn preceded(&'a self, segments: &'a [&'a [u8]]) -> Self {
OutputChain {
segments,
- then: Some(&self),
+ then: Some(self),
}
}
pub fn iter(&self) -> OutputChainIter<'_> {
- OutputChainIter(Some(&self))
+ OutputChainIter(Some(self))
}
}