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 fidl::endpoints::ServerEnd;
17use fidl_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 fidl_fuchsia_io as fio;
26
27 #[derive(Debug)]
29 pub struct DirectoryWatcher {
30 channel: fuchsia_async::Channel,
31 }
32
33 impl DirectoryWatcher {
34 pub fn channel(&self) -> &fuchsia_async::Channel {
36 let Self { channel } = self;
37 channel
38 }
39 }
40
41 impl From<fidl::endpoints::ServerEnd<fio::DirectoryWatcherMarker>> for DirectoryWatcher {
42 fn from(server_end: fidl::endpoints::ServerEnd<fio::DirectoryWatcherMarker>) -> Self {
43 let channel = fuchsia_async::Channel::from_channel(server_end.into_channel());
44 Self { channel }
45 }
46 }
47}
48
49pub use private::DirectoryWatcher;
50
51pub trait Directory: Node {
54 fn open(
70 self: Arc<Self>,
71 scope: ExecutionScope,
72 path: Path,
73 flags: fio::Flags,
74 object_request: ObjectRequestRef<'_>,
75 ) -> Result<(), Status>;
76
77 fn open_async(
80 self: Arc<Self>,
81 scope: ExecutionScope,
82 path: Path,
83 flags: fio::Flags,
84 object_request: ObjectRequestRef<'_>,
85 ) -> impl Future<Output = Result<(), Status>> + Send
86 where
87 Self: Sized,
88 {
89 ready(self.open(scope, path, flags, object_request))
90 }
91
92 fn read_dirents(
95 &self,
96 pos: &TraversalPosition,
97 sink: Box<dyn dirents_sink::Sink>,
98 ) -> impl Future<Output = Result<(TraversalPosition, Box<dyn dirents_sink::Sealed>), Status>> + Send
99 where
100 Self: Sized;
101
102 fn register_watcher(
105 self: Arc<Self>,
106 scope: ExecutionScope,
107 mask: fio::WatchMask,
108 watcher: DirectoryWatcher,
109 ) -> Result<(), Status>;
110
111 fn unregister_watcher(self: Arc<Self>, key: usize);
114
115 #[cfg(any(fuchsia_api_level_at_least = "PLATFORM", not(fuchsia_api_level_at_least = "NEXT")))]
116 fn deprecated_open(
119 self: Arc<Self>,
120 _scope: ExecutionScope,
121 flags: fio::OpenFlags,
122 _path: Path,
123 server_end: ServerEnd<fio::NodeMarker>,
124 ) {
125 flags.to_object_request(server_end.into_channel()).shutdown(Status::NOT_SUPPORTED);
126 }
127}
128
129pub trait MutableDirectory: Directory + Send + Sync {
133 fn link<'a>(
136 self: Arc<Self>,
137 _name: String,
138 _source_dir: Arc<dyn Any + Send + Sync>,
139 _source_name: &'a str,
140 ) -> BoxFuture<'a, Result<(), Status>> {
141 Box::pin(ready(Err(Status::NOT_SUPPORTED)))
142 }
143
144 fn update_attributes(
148 &self,
149 attributes: fio::MutableNodeAttributes,
150 ) -> impl Future<Output = Result<(), Status>> + Send
151 where
152 Self: Sized;
153
154 fn unlink(
156 self: Arc<Self>,
157 name: &str,
158 must_be_directory: bool,
159 ) -> impl Future<Output = Result<(), Status>> + Send
160 where
161 Self: Sized;
162
163 fn sync(&self) -> impl Future<Output = Result<(), Status>> + Send
165 where
166 Self: Sized;
167
168 fn rename(
170 self: Arc<Self>,
171 _src_dir: Arc<dyn MutableDirectory>,
172 _src_name: Path,
173 _dst_name: Path,
174 ) -> BoxFuture<'static, Result<(), Status>> {
175 Box::pin(ready(Err(Status::NOT_SUPPORTED)))
176 }
177
178 fn create_symlink(
180 &self,
181 _name: String,
182 _target: Vec<u8>,
183 _connection: Option<ServerEnd<fio::SymlinkMarker>>,
184 ) -> impl Future<Output = Result<(), Status>> + Send
185 where
186 Self: Sized,
187 {
188 ready(Err(Status::NOT_SUPPORTED))
189 }
190}