starnix_core/fs/fuchsia/
mod.rs1use crate::task::CurrentTask;
6use crate::vfs::FileHandle;
7use starnix_sync::{FileOpsCore, LockEqualOrBefore, Locked};
8use starnix_uapi::errors::Errno;
9use starnix_uapi::open_flags::OpenFlags;
10
11mod remote;
12mod remote_bundle;
13mod remote_unix_domain_socket;
14mod remote_volume;
15mod syslog;
16mod timer;
17
18pub mod sync_file;
19pub mod zxio;
20
21pub use remote::*;
22pub use remote_bundle::RemoteBundle;
23pub use remote_unix_domain_socket::*;
24pub use remote_volume::*;
25pub use syslog::*;
26pub use timer::*;
27
28pub fn create_file_from_handle<L>(
30 locked: &mut Locked<L>,
31 current_task: &CurrentTask,
32 handle: zx::NullableHandle,
33) -> Result<FileHandle, Errno>
34where
35 L: LockEqualOrBefore<FileOpsCore>,
36{
37 new_remote_file(locked, current_task, handle, OpenFlags::RDWR)
38}
39
40#[cfg(test)]
41mod test {
42 use super::*;
43 use crate::testing::*;
44
45 #[fuchsia::test]
46 async fn test_create_from_invalid_handle() {
47 spawn_kernel_and_run(async |locked, current_task| {
48 assert!(
49 create_file_from_handle(locked, current_task, zx::NullableHandle::invalid())
50 .is_err()
51 );
52 })
53 .await;
54 }
55
56 #[fuchsia::test]
57 async fn test_create_pipe_from_handle() {
58 spawn_kernel_and_run(async |locked, current_task| {
59 let (left_handle, right_handle) = zx::Socket::create_stream();
60 create_file_from_handle(locked, current_task, left_handle.into_handle())
61 .expect("failed to create left FileHandle");
62 create_file_from_handle(locked, current_task, right_handle.into_handle())
63 .expect("failed to create right FileHandle");
64 })
65 .await;
66 }
67}