summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2022-01-08 07:46:54 -0600
committerAlejandro Soto <alejandro@34project.org>2022-01-08 07:46:54 -0600
commit3f07297b0f4372e234ffe2b8bccc46312e9b68f8 (patch)
treeef4ceabf82e81c679b7be85d1b527e6a63ee0037 /src
parentfffebe5facf7b88c89c7aaa9385aa845f161e6f1 (diff)
Move Ino, Ttl, Timestamp to crate::io
Diffstat (limited to '')
-rw-r--r--src/io.rs94
-rw-r--r--src/lib.rs109
-rw-r--r--src/ops/dir.rs6
-rw-r--r--src/ops/entry.rs7
-rw-r--r--src/ops/inode.rs11
-rw-r--r--src/ops/mod.rs17
-rw-r--r--src/ops/open.rs4
-rw-r--r--src/ops/traits.rs12
-rw-r--r--src/proto.rs3
-rw-r--r--src/session.rs12
10 files changed, 136 insertions, 139 deletions
diff --git a/src/io.rs b/src/io.rs
index 5bcd6e7..dee8635 100644
--- a/src/io.rs
+++ b/src/io.rs
@@ -6,10 +6,11 @@ use std::{
ffi::OsStr,
future::Future,
ops::{ControlFlow, FromResidual, Try},
+ time::{SystemTime, UNIX_EPOCH},
};
use super::{Done, Operation, Reply, Request};
-use crate::{proto, Errno, FuseResult, Ino, Timestamp, Ttl};
+use crate::{proto, Errno, FuseResult};
#[doc(no_inline)]
pub use nix::{
@@ -21,6 +22,21 @@ pub use nix::{
pub use proto::FsyncFlags;
+#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
+pub struct Ino(pub u64);
+
+#[derive(Copy, Clone, Eq, PartialEq)]
+pub struct Ttl {
+ seconds: u64,
+ nanoseconds: u32,
+}
+
+#[derive(Copy, Clone, Default, Eq, PartialEq)]
+pub struct Timestamp {
+ seconds: i64,
+ nanoseconds: u32,
+}
+
pub enum Interruptible<'o, O: Operation<'o>, T> {
Completed(Reply<'o, O>, T),
Interrupted(Done<'o>),
@@ -58,6 +74,82 @@ pub struct Entry<'a, K> {
#[derive(Copy, Clone)]
pub struct FsInfo(proto::StatfsOut);
+impl Ino {
+ pub const NULL: Self = Ino(0);
+
+ pub const ROOT: Self = Ino(proto::ROOT_ID);
+
+ pub fn as_raw(self) -> u64 {
+ self.0
+ }
+}
+
+impl std::fmt::Display for Ino {
+ fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(formatter, "{}", self.0)
+ }
+}
+
+impl Ttl {
+ pub const NULL: Self = Ttl {
+ seconds: 0,
+ nanoseconds: 0,
+ };
+
+ pub const MAX: Self = Ttl {
+ seconds: u64::MAX,
+ nanoseconds: u32::MAX,
+ };
+
+ pub fn new(seconds: u64, nanoseconds: u32) -> Ttl {
+ assert!(nanoseconds < 1_000_000_000);
+
+ Ttl {
+ seconds,
+ nanoseconds,
+ }
+ }
+
+ pub fn seconds(self) -> u64 {
+ self.seconds
+ }
+
+ pub fn nanoseconds(self) -> u32 {
+ self.nanoseconds
+ }
+}
+
+impl Timestamp {
+ pub fn new(seconds: i64, nanoseconds: u32) -> Self {
+ Timestamp {
+ seconds,
+ nanoseconds,
+ }
+ }
+}
+
+impl From<SystemTime> for Timestamp {
+ fn from(time: SystemTime) -> Self {
+ let (seconds, nanoseconds) = match time.duration_since(UNIX_EPOCH) {
+ Ok(duration) => {
+ let secs = duration.as_secs().try_into().unwrap();
+ (secs, duration.subsec_nanos())
+ }
+
+ Err(before_epoch) => {
+ let duration = before_epoch.duration();
+ let secs = -i64::try_from(duration.as_secs()).unwrap();
+ (secs, duration.subsec_nanos())
+ }
+ };
+
+ Timestamp {
+ seconds,
+ nanoseconds,
+ }
+ }
+}
+
impl<'o, E> From<Failed<'o, E>> for Done<'o> {
fn from(failed: Failed<'o, E>) -> Done<'o> {
failed.0
diff --git a/src/lib.rs b/src/lib.rs
index def34d7..2a0312e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -8,10 +8,7 @@
#[cfg(not(target_os = "linux"))]
compile_error!("Unsupported OS");
-use std::{
- marker::PhantomData,
- time::{SystemTime, UNIX_EPOCH},
-};
+use std::marker::PhantomData;
pub use self::error::{FuseError, FuseResult};
@@ -46,28 +43,9 @@ pub struct Reply<'o, O: Operation<'o>> {
state: O::ReplyState,
}
-/// Inode number.
-///
-/// This is a public newtype. Users are expected to inspect the underlying `u64` and construct
-/// arbitrary `Ino` objects.
-#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
-pub struct Ino(pub u64);
-
#[must_use]
pub struct Done<'o>(PhantomData<&'o mut &'o ()>);
-#[derive(Copy, Clone, Eq, PartialEq)]
-pub struct Ttl {
- seconds: u64,
- nanoseconds: u32,
-}
-
-#[derive(Copy, Clone, Default, Eq, PartialEq)]
-pub struct Timestamp {
- seconds: i64,
- nanoseconds: u32,
-}
-
impl Done<'_> {
fn new() -> Self {
Done(PhantomData)
@@ -78,91 +56,6 @@ impl Done<'_> {
}
}
-impl Ino {
- /// The invalid inode number, mostly useful for internal aspects of the FUSE protocol.
- pub const NULL: Self = Ino(0);
-
- /// The inode number of the root inode as observed by a FUSE client. Other libraries refer to
- /// this as `FUSE_ROOT_ID`.
- ///
- /// Note that a mounted session will remember the inode number given by `Inode::ino()` for the
- /// root inode at initialization and transparently swap between it and `Ino::ROOT`. During
- /// dispatch, requests targeted at `Ino::ROOT` will have this value replaced by the stored root
- /// number, while replies involving the root inode will always report `Ino::ROOT` to the FUSE
- /// client. Therefore, filesystems do not have to be aware of `Ino::ROOT` in most cases.
- pub const ROOT: Self = Ino(proto::ROOT_ID);
-
- /// Extracts the raw inode number.
- pub fn as_raw(self) -> u64 {
- self.0
- }
-}
-
-impl std::fmt::Display for Ino {
- fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(formatter, "{}", self.0)
- }
-}
-
-impl Ttl {
- pub const NULL: Self = Ttl {
- seconds: 0,
- nanoseconds: 0,
- };
-
- pub const MAX: Self = Ttl {
- seconds: u64::MAX,
- nanoseconds: u32::MAX,
- };
-
- pub fn new(seconds: u64, nanoseconds: u32) -> Ttl {
- assert!(nanoseconds < 1_000_000_000);
- Ttl {
- seconds,
- nanoseconds,
- }
- }
-
- pub fn seconds(&self) -> u64 {
- self.seconds
- }
-
- pub fn nanoseconds(&self) -> u32 {
- self.nanoseconds
- }
-}
-
-impl Timestamp {
- pub fn new(seconds: i64, nanoseconds: u32) -> Self {
- Timestamp {
- seconds,
- nanoseconds,
- }
- }
-}
-
-impl From<SystemTime> for Timestamp {
- fn from(time: SystemTime) -> Self {
- let (seconds, nanoseconds) = match time.duration_since(UNIX_EPOCH) {
- Ok(duration) => {
- let secs = duration.as_secs().try_into().unwrap();
- (secs, duration.subsec_nanos())
- }
-
- Err(before_epoch) => {
- let duration = before_epoch.duration();
- let secs = -i64::try_from(duration.as_secs()).unwrap();
- (secs, duration.subsec_nanos())
- }
- };
-
- Timestamp {
- seconds,
- nanoseconds,
- }
- }
-}
-
mod sealed {
pub trait Sealed {}
}
diff --git a/src/ops/dir.rs b/src/ops/dir.rs
index 210c13a..4b075eb 100644
--- a/src/ops/dir.rs
+++ b/src/ops/dir.rs
@@ -6,9 +6,10 @@ use std::{
};
use crate::{
- io::{Entry, EntryType, Interruptible, Known, Stat},
+ io::{Entry, EntryType, Ino, Interruptible, Known, Stat, Ttl},
+ proto,
sealed::Sealed,
- Done, Operation, Reply, Request,
+ Done, Errno, Operation, Reply, Request,
};
use super::{
@@ -20,7 +21,6 @@ use super::{
FromRequest,
};
-use crate::{proto, Errno, Ino, Ttl};
use bytemuck::{bytes_of, Zeroable};
use bytes::BufMut;
use nix::sys::stat::SFlag;
diff --git a/src/ops/entry.rs b/src/ops/entry.rs
index af48914..ac90a4d 100644
--- a/src/ops/entry.rs
+++ b/src/ops/entry.rs
@@ -3,7 +3,12 @@ use super::{
traits::{ReplyKnown, ReplyOk, RequestMode, RequestName},
};
-use crate::{io::Mode, proto, sealed::Sealed, Ino, Operation, Request};
+use crate::{
+ io::{Ino, Mode},
+ proto,
+ sealed::Sealed,
+ Operation, Request,
+};
use std::ffi::{CStr, OsStr};
pub enum Mknod {}
diff --git a/src/ops/inode.rs b/src/ops/inode.rs
index 15e3854..c1aa98c 100644
--- a/src/ops/inode.rs
+++ b/src/ops/inode.rs
@@ -1,5 +1,10 @@
use super::traits::{ReplyOk, RequestHandle};
-use crate::{io::Stat, proto, sealed::Sealed, Done, Ino, Operation, Reply, Request};
+use crate::{
+ io::{Ino, Stat},
+ proto,
+ sealed::Sealed,
+ Done, Operation, Reply, Request,
+};
pub enum Forget {}
pub enum Getattr {}
@@ -95,8 +100,8 @@ impl<'o> ReplyStat<'o> for Getattr {
let attrs = attrs.finish(inode);
reply.single(&proto::AttrOut {
- attr_valid: ttl.seconds,
- attr_valid_nsec: ttl.nanoseconds,
+ attr_valid: ttl.seconds(),
+ attr_valid_nsec: ttl.nanoseconds(),
dummy: Default::default(),
attr: attrs,
})
diff --git a/src/ops/mod.rs b/src/ops/mod.rs
index d4ebd72..89c39c1 100644
--- a/src/ops/mod.rs
+++ b/src/ops/mod.rs
@@ -3,7 +3,14 @@ use std::{
os::unix::ffi::OsStrExt,
};
-use crate::{proto, sealed::Sealed, util::OutputChain, Done, Ino, Operation, Reply, Request, Ttl};
+use crate::{
+ io::{Ino, Ttl},
+ proto,
+ sealed::Sealed,
+ util::OutputChain,
+ Done, Operation, Reply, Request,
+};
+
use bytemuck::{bytes_of, Pod};
pub mod traits;
@@ -73,10 +80,10 @@ fn make_entry(
proto::EntryOut {
nodeid: ino,
generation: 0, //TODO
- entry_valid: entry_ttl.seconds,
- attr_valid: attr_ttl.seconds,
- entry_valid_nsec: entry_ttl.nanoseconds,
- attr_valid_nsec: attr_ttl.nanoseconds,
+ entry_valid: entry_ttl.seconds(),
+ attr_valid: attr_ttl.seconds(),
+ entry_valid_nsec: entry_ttl.nanoseconds(),
+ attr_valid_nsec: attr_ttl.nanoseconds(),
attr: attrs,
}
}
diff --git a/src/ops/open.rs b/src/ops/open.rs
index 2d1599d..0d58da7 100644
--- a/src/ops/open.rs
+++ b/src/ops/open.rs
@@ -1,9 +1,9 @@
use crate::{
- io::{AccessFlags, Known, Mode, OpenFlags, Stat},
+ io::{AccessFlags, Known, Mode, OpenFlags, Stat, Ttl},
proto::{self, OpenOutFlags},
sealed::Sealed,
util::OutputChain,
- Done, Errno, Operation, Reply, Request, Ttl,
+ Done, Errno, Operation, Reply, Request,
};
use super::{
diff --git a/src/ops/traits.rs b/src/ops/traits.rs
index e445687..20f7378 100644
--- a/src/ops/traits.rs
+++ b/src/ops/traits.rs
@@ -1,8 +1,12 @@
use crate::{
- io::{Entry, FsInfo, Interruptible, Known, Mode, Stat},
- Done, Ino, Operation, Reply, Request, Ttl,
+ io::{Entry, FsInfo, Ino, Interruptible, Known, Mode, Stat, Ttl},
+ Done, Operation, Reply, Request,
};
+use super::make_entry;
+use bytes::BufMut;
+use std::{ffi::OsStr, os::unix::ffi::OsStrExt};
+
pub use super::{
dir::{ReplyEntries, ReplyFound},
entry::{RequestDevice, RequestLink, RequestTarget},
@@ -13,10 +17,6 @@ pub use super::{
xattr::ReplyXattrRead,
};
-use super::make_entry;
-use bytes::BufMut;
-use std::{ffi::OsStr, os::unix::ffi::OsStrExt};
-
pub trait RequestName<'o>: Operation<'o> {
fn name<'a>(request: &'a Request<'o, Self>) -> &'a OsStr;
}
diff --git a/src/proto.rs b/src/proto.rs
index 5587d89..6df93ca 100644
--- a/src/proto.rs
+++ b/src/proto.rs
@@ -1,13 +1,12 @@
// Based on libfuse/include/fuse_kernel.h
+use crate::{util::display_or, FuseError, FuseResult};
use bitflags::bitflags;
use bytemuck::{self, try_cast_slice, try_from_bytes, Pod};
use bytemuck_derive::{Pod, Zeroable};
use num_enum::TryFromPrimitive;
use std::{convert::TryFrom, ffi::CStr, fmt};
-use crate::{util::display_or, FuseError, FuseResult};
-
pub const ROOT_ID: u64 = 1;
pub const MAJOR_VERSION: u32 = 7;
pub const TARGET_MINOR_VERSION: u32 = 32;
diff --git a/src/session.rs b/src/session.rs
index 6f7fd6c..117aa5f 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -19,21 +19,17 @@ use tokio::{
sync::{broadcast, OwnedSemaphorePermit, Semaphore},
};
-use bytemuck::bytes_of;
-use smallvec::SmallVec;
-
use crate::{
error::MountError,
mount::unmount_sync,
+ ops::{self, FromRequest},
proto::{self, InHeader, Structured},
util::{page_size, DumbFd, OutputChain},
- Errno, FuseError, FuseResult,
+ Done, Errno, FuseError, FuseResult, Op, Operation, Reply, Request,
};
-use super::{
- ops::{self, FromRequest},
- Done, Op, Operation, Reply, Request,
-};
+use bytemuck::bytes_of;
+use smallvec::SmallVec;
pub struct Start {
session_fd: DumbFd,