Skip to main content

vfs/
lib.rs

1// Copyright 2019 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Fuchsia Rust Virtual File System (VFS) framework.
6//!
7//! This crate provides safe, asynchronous implementations of the `fuchsia.io` VFS protocols
8//! (directories, files, services, symbolic links, and remote directory mounts).
9
10#![recursion_limit = "1024"]
11
12#[macro_use]
13pub mod common;
14
15pub mod directory;
16pub mod execution_scope;
17pub mod file;
18pub mod node;
19pub mod object_request;
20pub mod path;
21mod protocols;
22pub mod remote;
23mod request_handler;
24pub mod service;
25pub mod symlink;
26pub mod temp_clone;
27pub mod test_utils;
28pub mod token_registry;
29pub mod tree_builder;
30
31pub use crate::common::CreationMode;
32pub use crate::execution_scope::{ExecutionScope, WeakExecutionScope};
33pub use crate::object_request::{ObjectRequest, ObjectRequestRef, ToObjectRequest};
34pub use crate::path::Path;
35pub use crate::protocols::ProtocolsExt;
36pub use ::name;
37
38#[cfg(test)]
39use flex_test_placeholders as _;
40#[cfg(all(test, feature = "fdomain"))]
41use fuchsia_fs_fdomain as _;
42
43use directory::entry_container::Directory;
44use flex_fuchsia_io as fio;
45use std::sync::Arc;
46
47/// Helper function to serve a new connection to the directory at `path` under `root` with `flags`.
48/// Errors will be communicated via epitaph on the returned proxy. A new [`ExecutionScope`] will be
49/// created for the request.
50///
51/// To serve `root` itself, use [`crate::directory::serve`] or set `path` to [`Path::dot`].
52pub fn serve_directory<D: Directory + ?Sized>(
53    root: Arc<D>,
54    path: Path,
55    scope: ExecutionScope,
56    flags: fio::Flags,
57) -> fio::DirectoryProxy {
58    let (proxy, server) = scope.domain().create_proxy::<fio::DirectoryMarker>();
59    let request = flags.to_object_request(server);
60    request.handle(|request| root.open(scope, path, flags, request));
61    proxy
62}
63
64/// Helper function to serve a new connection to the file at `path` under `root` with `flags`.
65/// Errors will be communicated via epitaph on the returned proxy. A new [`ExecutionScope`] will be
66/// created for the request.
67///
68/// To serve an object that implements [`crate::file::File`], use [`crate::file::serve`].
69pub fn serve_file<D: Directory + ?Sized>(
70    root: Arc<D>,
71    path: Path,
72    scope: ExecutionScope,
73    flags: fio::Flags,
74) -> fio::FileProxy {
75    let (proxy, server) = scope.domain().create_proxy::<fio::FileMarker>();
76    let request = flags.to_object_request(server);
77    request.handle(|request| root.open(scope, path, flags, request));
78    proxy
79}