Skip to main content

Fs

Struct Fs 

Source
pub struct Fs {
    pub root: Vec<u8>,
    pub bindings: Vec<Binding>,
    pub identity: bool,
    pub proc_is_host: bool,
    root_pin: Pin,
    pins: Vec<Pin>,
    id: u64,
    cache: Arc<DirCache>,
    pub procs: Arc<ProcTable>,
}
Expand description

The guest filesystem view: a root directory plus bind mounts.

Fields§

§root: Vec<u8>

Host directory serving as guest /, no trailing slash.

§bindings: Vec<Binding>

Bindings sorted so that longer guest prefixes come first.

§identity: bool

True when root is / and there are no bindings: translation is a no-op.

§proc_is_host: bool

True when guest /proc is the host’s: its magic links mean what they mean on the host.

§root_pin: Pin

The root’s host side, held open.

§pins: Vec<Pin>

Each binding’s host side, held open; same order as bindings.

§id: u64

Identifies this view’s entries in the shared directory cache.

§cache: Arc<DirCache>

Directory cache shared with every other view of the supervisor.

§procs: Arc<ProcTable>

Per-process records: the program each process runs, since the kernel’s own /proc/<pid>/exe names the dynamic loader after an exec rewrite, and without ptrace the working directory too.

Implementations§

Source§

impl Fs

Source

pub fn new(config: &Config) -> Fs

Builds the view from the parsed configuration with its own process table and directory cache.

§Arguments
  • config - Parsed command line. Bindings are normalized and sorted.
Source

pub fn with_procs(config: &Config, procs: Arc<ProcTable>) -> Fs

Builds the view from the parsed configuration over a shared process table, with a directory cache of its own.

§Arguments
  • config - Parsed command line. Bindings are normalized and sorted.
  • procs - Process table shared with the supervisor.
Source

pub fn with_cache( config: &Config, procs: Arc<ProcTable>, cache: Arc<DirCache>, ) -> Fs

Builds the view from the parsed configuration over a shared process table and a shared directory cache.

The root is made absolute, since it is used from the alias directory as well (loader aliases, the exec shim’s records).

§Arguments
  • config - Parsed command line. Bindings are normalized and sorted.
  • procs - Process table shared with the supervisor.
  • cache - Directory cache shared with the supervisor’s other views.
Source

fn canonicalize_bindings(&mut self)

Rewrites every binding’s guest path to the canonical form lookups use.

A lookup is canonicalized through the view before the binding table is consulted, so a guest path given through a symlink of the rootfs, such as /lib/ld-linux.so.2 on a merged-usr host where /lib points to usr/lib, would never match unless the table holds the /usr/lib/ld-linux.so.2 the lookup resolves to. The final component is kept as given, and a path whose intermediate components are missing stays lexical, as the walk stops there. The table is re-sorted and the identity flag recomputed when anything changed.

Source

pub fn cache_get(&self, guest: &[u8]) -> Option<Arc<OwnedFd>>

The pinned directory of a canonical guest directory the cache has seen in this view.

§Arguments
  • guest - Canonical absolute guest path.
Source

pub fn cache_put(&self, guest: &[u8], fd: Arc<OwnedFd>)

Records the directory guest resolved to in this view.

§Arguments
  • guest - Canonical absolute guest path.
  • fd - Its O_PATH descriptor.
Source

pub fn mount_pin(&self, guest: &[u8]) -> Option<Option<Arc<OwnedFd>>>

The pinned host side of the binding whose guest path is exactly guest, or of the root for /.

§Returns

None when guest is no mount point of this view; Some(None) when it is one whose host side does not exist.

Source

pub fn binding_below(&self, guest: &[u8]) -> bool

Whether a binding lies below guest, which then stands in the view as a directory even where the host side has nothing under the name: in a rootfs the placeholders of glue could not be made in, say.

§Arguments
  • guest - Canonical absolute guest path.
Source

pub fn pin_for_guest<'a>( &self, guest: &'a [u8], ) -> (Option<Arc<OwnedFd>>, &'a [u8])

The pinned mount point under which guest lies, and the path from there.

§Arguments
  • guest - Canonical absolute guest path.
§Returns

The binding’s (or root’s) descriptor, None when its host side does not exist, and the remainder of guest below it with its leading slash (empty for the mount point itself).

Source

pub fn flush_cache(&self)

Forgets every cached directory of every view sharing the cache.

Source

pub fn exe_of(&self, tid: i32) -> Option<Vec<u8>>

The recorded guest program of thread tid, if any.

§Arguments
  • tid - Thread or process id as it appears in a /proc/<n> path.
Source

pub fn virtual_cwd(&self, tid: i32) -> Option<Vec<u8>>

The virtual working directory of thread tid, when cwd is virtual (no ptrace).

§Arguments
  • tid - Thread or process id.
Source

pub fn binding_for_guest(&self, guest: &[u8]) -> Option<&Binding>

Finds the binding whose guest prefix covers guest, if any.

§Arguments
  • guest - Absolute, lexically clean guest path.
Source

pub fn binding_for_host(&self, host: &[u8]) -> Option<&Binding>

Finds the binding whose host prefix covers host, preferring the longest.

§Arguments
  • host - Absolute host path.
Source

pub fn substitute_guest_to_host(&self, guest: &[u8]) -> Vec<u8> ⓘ

Substitutes the guest prefix of an absolute guest path with its host prefix.

This is purely lexical: no symlink is followed. Use crate::fs::translate::translate_path for a real translation.

§Arguments
  • guest - Absolute guest path.
§Returns

The host path the guest path maps to.

Source

pub fn substitute_host_to_guest(&self, host: &[u8]) -> Option<Vec<u8>>

Substitutes the host prefix of a host path with its guest prefix.

§Arguments
  • host - Absolute host path.
§Returns

The guest path, or None when the host path is not visible in the guest.

Trait Implementations§

Source§

impl Debug for Fs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Fs

§

impl RefUnwindSafe for Fs

§

impl Send for Fs

§

impl Sync for Fs

§

impl Unpin for Fs

§

impl UnsafeUnpin for Fs

§

impl UnwindSafe for Fs

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.