diff options
| author | Alejandro Soto <alejandro@34project.org> | 2022-01-05 02:52:04 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2022-01-05 02:52:04 -0600 |
| commit | 75cced9d4c101ec2f9f04ed95621ff3a3f750eae (patch) | |
| tree | a8ff3fa46a75b18ee3c1133aa6fc0857132d6115 /src/ops/open.rs | |
| parent | ff17b04143dde5157808be5bcf1cbf8a942db4c4 (diff) | |
Refactor impls of Reply as individual traits
Diffstat (limited to 'src/ops/open.rs')
| -rw-r--r-- | src/ops/open.rs | 92 |
1 files changed, 42 insertions, 50 deletions
diff --git a/src/ops/open.rs b/src/ops/open.rs index 9123421..ab9eea7 100644 --- a/src/ops/open.rs +++ b/src/ops/open.rs @@ -4,7 +4,7 @@ use crate::{ proto, Done, Errno, Operation, Reply, Request, }; -use super::FromRequest; +use super::{traits::ReplyOk, FromRequest}; pub enum Open {} pub enum Release {} @@ -12,6 +12,28 @@ pub enum Opendir {} pub enum Releasedir {} pub enum Access {} +pub trait ReplyOpen<'o>: ReplyOk<'o, ReplyTail = proto::OpenOutFlags> { + fn ok_with_handle(reply: Reply<'o, Self>, handle: u64) -> Done<'o> { + let open_flags = reply.tail.bits(); + + reply.single(&proto::OpenOut { + fh: handle, + open_flags, + padding: Default::default(), + }) + } + + fn force_direct_io(reply: &mut Reply<'o, Self>) { + reply.tail |= proto::OpenOutFlags::DIRECT_IO; + } +} + +pub trait ReplyPermissionDenied<'o>: Operation<'o> { + fn permission_denied(reply: Reply<'o, Self>) -> Done<'o> { + reply.fail(Errno::EACCES) + } +} + impl Sealed for Open {} impl Sealed for Release {} impl Sealed for Opendir {} @@ -30,7 +52,7 @@ impl<'o> Operation<'o> for Release { impl<'o> Operation<'o> for Opendir { type RequestBody = &'o proto::OpendirIn; - type ReplyTail = (); + type ReplyTail = proto::OpenOutFlags; } impl<'o> Operation<'o> for Releasedir { @@ -49,63 +71,39 @@ impl<'o> Request<'o, Open> { } } -impl<'o> Reply<'o, Open> { - pub fn force_direct_io(&mut self) { - self.tail |= proto::OpenOutFlags::DIRECT_IO; - } - - pub fn ok(self) -> Done<'o> { - self.ok_with_handle(0) - } - - pub fn ok_with_handle(self, handle: u64) -> Done<'o> { - let open_flags = self.tail.bits(); - - self.single(&proto::OpenOut { - fh: handle, - open_flags, - padding: Default::default(), - }) +impl<'o> ReplyOk<'o> for Open { + fn ok(reply: Reply<'o, Self>) -> Done<'o> { + reply.ok_with_handle(0) } } +impl<'o> ReplyOpen<'o> for Open {} +impl<'o> ReplyPermissionDenied<'o> for Open {} + impl<'o> Request<'o, Release> { pub fn handle(&self) -> u64 { self.body.fh } } -impl<'o> Reply<'o, Release> { - pub fn ok(self) -> Done<'o> { - self.empty() - } -} +impl<'o> ReplyOk<'o> for Release {} -impl<'o> Reply<'o, Opendir> { - pub fn ok(self) -> Done<'o> { - self.ok_with_handle(0) - } - - pub fn ok_with_handle(self, handle: u64) -> Done<'o> { - self.single(&proto::OpenOut { - fh: handle, - open_flags: 0, - padding: Default::default(), - }) +impl<'o> ReplyOk<'o> for Opendir { + fn ok(reply: Reply<'o, Self>) -> Done<'o> { + reply.ok_with_handle(0) } } +impl<'o> ReplyPermissionDenied<'o> for Opendir {} +impl<'o> ReplyOpen<'o> for Opendir {} + impl<'o> Request<'o, Releasedir> { pub fn handle(&self) -> u64 { self.body.release_in.fh } } -impl<'o> Reply<'o, Releasedir> { - pub fn ok(self) -> Done<'o> { - self.empty() - } -} +impl<'o> ReplyOk<'o> for Releasedir {} impl<'o> Request<'o, Access> { pub fn mask(&self) -> AccessFlags { @@ -113,18 +111,12 @@ impl<'o> Request<'o, Access> { } } -impl<'o> Reply<'o, Access> { - pub fn ok(self) -> Done<'o> { - self.empty() - } +impl<'o> ReplyOk<'o> for Access {} - pub fn permission_denied(self) -> Done<'o> { - self.fail(Errno::EACCES) - } -} +impl<'o> ReplyPermissionDenied<'o> for Access {} -impl<'o> FromRequest<'o, Open> for proto::OpenOutFlags { - fn from_request(_request: &Request<'o, Open>) -> Self { +impl<'o, O: ReplyOpen<'o>> FromRequest<'o, O> for proto::OpenOutFlags { + fn from_request(_request: &Request<'o, O>) -> Self { proto::OpenOutFlags::empty() } } |
