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, ToObjectRequest as _};
13use crate::path::Path;
14use fidl::endpoints::ServerEnd;
15use fidl_fuchsia_io as fio;
16use futures::future::BoxFuture;
17use std::any::Any;
18use std::future::{Future, ready};
19use std::sync::Arc;
20use zx_status::Status;
21
22mod private {
23 use fidl_fuchsia_io as fio;
24
25 #[derive(Debug)]
27 pub struct DirectoryWatcher {
28 channel: fuchsia_async::Channel,
29 }
30
31 impl DirectoryWatcher {
32 pub fn channel(&self) -> &fuchsia_async::Channel {
34 let Self { channel } = self;
35 channel
36 }
37 }
38
39 impl From<fidl::endpoints::ServerEnd<fio::DirectoryWatcherMarker>> for DirectoryWatcher {
40 fn from(server_end: fidl::endpoints::ServerEnd<fio::DirectoryWatcherMarker>) -> Self {
41 let channel = fuchsia_async::Channel::from_channel(server_end.into_channel());
42 Self { channel }
43 }
44 }
45}
46
47pub use private::DirectoryWatcher;
48
49pub trait Directory: Node {
52 fn open(
68 self: Arc<Self>,
69 scope: ExecutionScope,
70 path: Path,
71 flags: fio::Flags,
72 object_request: ObjectRequestRef<'_>,
73 ) -> Result<(), Status>;
74
75 fn open_async(
78 self: Arc<Self>,
79 scope: ExecutionScope,
80 path: Path,
81 flags: fio::Flags,
82 object_request: ObjectRequestRef<'_>,
83 ) -> impl Future<Output = Result<(), Status>> + Send
84 where
85 Self: Sized,
86 {
87 ready(self.open(scope, path, flags, object_request))
88 }
89
90 fn read_dirents<'a>(
94 &'a self,
95 pos: &'a TraversalPosition,
96 sink: Box<dyn dirents_sink::Sink>,
97 ) -> impl Future<Output = Result<(TraversalPosition, Box<dyn dirents_sink::Sealed>), Status>> + Send
98 where
99 Self: Sized;
100
101 fn register_watcher(
104 self: Arc<Self>,
105 scope: ExecutionScope,
106 mask: fio::WatchMask,
107 watcher: DirectoryWatcher,
108 ) -> Result<(), Status>;
109
110 fn unregister_watcher(self: Arc<Self>, key: usize);
113
114 fn deprecated_open(
117 self: Arc<Self>,
118 _scope: ExecutionScope,
119 flags: fio::OpenFlags,
120 _path: Path,
121 server_end: ServerEnd<fio::NodeMarker>,
122 ) {
123 flags.to_object_request(server_end.into_channel()).shutdown(Status::NOT_SUPPORTED);
124 }
125}
126
127pub trait MutableDirectory: Directory + Send + Sync {
131 fn link<'a>(
134 self: Arc<Self>,
135 _name: String,
136 _source_dir: Arc<dyn Any + Send + Sync>,
137 _source_name: &'a str,
138 ) -> BoxFuture<'a, Result<(), Status>> {
139 Box::pin(ready(Err(Status::NOT_SUPPORTED)))
140 }
141
142 fn update_attributes(
146 &self,
147 attributes: fio::MutableNodeAttributes,
148 ) -> impl Future<Output = Result<(), Status>> + Send
149 where
150 Self: Sized;
151
152 fn unlink(
154 self: Arc<Self>,
155 name: &str,
156 must_be_directory: bool,
157 ) -> impl Future<Output = Result<(), Status>> + Send
158 where
159 Self: Sized;
160
161 fn sync(&self) -> impl Future<Output = Result<(), Status>> + Send
163 where
164 Self: Sized;
165
166 fn rename(
168 self: Arc<Self>,
169 _src_dir: Arc<dyn MutableDirectory>,
170 _src_name: Path,
171 _dst_name: Path,
172 ) -> BoxFuture<'static, Result<(), Status>> {
173 Box::pin(ready(Err(Status::NOT_SUPPORTED)))
174 }
175
176 fn create_symlink(
178 &self,
179 _name: String,
180 _target: Vec<u8>,
181 _connection: Option<ServerEnd<fio::SymlinkMarker>>,
182 ) -> impl Future<Output = Result<(), Status>> + Send
183 where
184 Self: Sized,
185 {
186 ready(Err(Status::NOT_SUPPORTED))
187 }
188
189 fn list_extended_attributes(&self) -> impl Future<Output = Result<Vec<Vec<u8>>, Status>> + Send
191 where
192 Self: Sized,
193 {
194 ready(Err(Status::NOT_SUPPORTED))
195 }
196
197 fn get_extended_attribute(
199 &self,
200 _name: Vec<u8>,
201 ) -> impl Future<Output = Result<Vec<u8>, Status>> + Send
202 where
203 Self: Sized,
204 {
205 ready(Err(Status::NOT_SUPPORTED))
206 }
207
208 fn set_extended_attribute(
210 &self,
211 _name: Vec<u8>,
212 _value: Vec<u8>,
213 _mode: fio::SetExtendedAttributeMode,
214 ) -> impl Future<Output = Result<(), Status>> + Send
215 where
216 Self: Sized,
217 {
218 ready(Err(Status::NOT_SUPPORTED))
219 }
220
221 fn remove_extended_attribute(
223 &self,
224 _name: Vec<u8>,
225 ) -> impl Future<Output = Result<(), Status>> + Send
226 where
227 Self: Sized,
228 {
229 ready(Err(Status::NOT_SUPPORTED))
230 }
231}