vfs/directory/
entry_container.rs1use crate::directory::dirents_sink;
9use crate::directory::traversal_position::TraversalPosition;
10use crate::execution_scope::ExecutionScope;
11use crate::node::Node;
12use crate::object_request::ObjectRequestRef;
13#[cfg(any(fuchsia_api_level_at_least = "PLATFORM", not(fuchsia_api_level_at_least = "NEXT")))]
14use crate::object_request::ToObjectRequest as _;
15use crate::path::Path;
16use flex_client::fidl::ServerEnd;
17use flex_fuchsia_io as fio;
18use futures::future::BoxFuture;
19use std::any::Any;
20use std::future::{Future, ready};
21use std::sync::Arc;
22use zx_status::Status;
23
24mod private {
25 use flex_fuchsia_io as fio;
26
27 #[derive(Debug)]
29 pub struct DirectoryWatcher {
30 channel: flex_client::AsyncChannel,
31 }
32
33 impl DirectoryWatcher {
34 pub fn channel(&self) -> &flex_client::AsyncChannel {
36 let Self { channel } = self;
37 channel
38 }
39 }
40
41 impl From<flex_client::fidl::ServerEnd<fio::DirectoryWatcherMarker>> for DirectoryWatcher {
42 fn from(server_end: flex_client::fidl::ServerEnd<fio::DirectoryWatcherMarker>) -> Self {
43 use crate::object_request::IntoAsyncChannel;
44 let channel = server_end.into_channel().into_async_channel();
45 Self { channel }
46 }
47 }
48}
49
50pub use private::DirectoryWatcher;
51
52pub trait Directory: Node {
55 fn open(
71 self: Arc<Self>,
72 scope: ExecutionScope,
73 path: Path,
74 flags: fio::Flags,
75 object_request: ObjectRequestRef<'_>,
76 ) -> Result<(), Status>;
77
78 fn open_async(
81 self: Arc<Self>,
82 scope: ExecutionScope,
83 path: Path,
84 flags: fio::Flags,
85 object_request: ObjectRequestRef<'_>,
86 ) -> impl Future<Output = Result<(), Status>> + Send
87 where
88 Self: Sized,
89 {
90 ready(self.open(scope, path, flags, object_request))
91 }
92
93 fn read_dirents(
96 &self,
97 pos: &TraversalPosition,
98 sink: Box<dyn dirents_sink::Sink>,
99 ) -> impl Future<Output = Result<(TraversalPosition, Box<dyn dirents_sink::Sealed>), Status>> + Send
100 where
101 Self: Sized;
102
103 fn register_watcher(
106 self: Arc<Self>,
107 scope: ExecutionScope,
108 mask: fio::WatchMask,
109 watcher: DirectoryWatcher,
110 ) -> Result<(), Status>;
111
112 fn unregister_watcher(self: Arc<Self>, key: usize);
115
116 #[cfg(any(fuchsia_api_level_at_least = "PLATFORM", not(fuchsia_api_level_at_least = "NEXT")))]
117 fn deprecated_open(
120 self: Arc<Self>,
121 _scope: ExecutionScope,
122 flags: fio::OpenFlags,
123 _path: Path,
124 server_end: ServerEnd<fio::NodeMarker>,
125 ) {
126 flags.to_object_request(server_end.into_channel()).shutdown(Status::NOT_SUPPORTED);
127 }
128}
129
130pub trait MutableDirectory: Directory + Send + Sync {
134 fn link<'a>(
137 self: Arc<Self>,
138 _name: String,
139 _source_dir: Arc<dyn Any + Send + Sync>,
140 _source_name: &'a str,
141 ) -> BoxFuture<'a, Result<(), Status>> {
142 Box::pin(ready(Err(Status::NOT_SUPPORTED)))
143 }
144
145 fn update_attributes(
149 &self,
150 attributes: fio::MutableNodeAttributes,
151 ) -> impl Future<Output = Result<(), Status>> + Send
152 where
153 Self: Sized;
154
155 fn unlink(
157 self: Arc<Self>,
158 name: &str,
159 must_be_directory: bool,
160 ) -> impl Future<Output = Result<(), Status>> + Send
161 where
162 Self: Sized;
163
164 fn sync(&self) -> impl Future<Output = Result<(), Status>> + Send
166 where
167 Self: Sized;
168
169 fn rename(
171 self: Arc<Self>,
172 _src_dir: Arc<dyn MutableDirectory>,
173 _src_name: Path,
174 _dst_name: Path,
175 ) -> BoxFuture<'static, Result<(), Status>> {
176 Box::pin(ready(Err(Status::NOT_SUPPORTED)))
177 }
178
179 fn create_symlink(
181 &self,
182 _name: String,
183 _target: Vec<u8>,
184 _connection: Option<ServerEnd<fio::SymlinkMarker>>,
185 ) -> impl Future<Output = Result<(), Status>> + Send
186 where
187 Self: Sized,
188 {
189 ready(Err(Status::NOT_SUPPORTED))
190 }
191}