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: boolTrue when root is / and there are no bindings: translation is a no-op.
proc_is_host: boolTrue when guest /proc is the host’s: its magic links mean what they
mean on the host.
root_pin: PinThe root’s host side, held open.
pins: Vec<Pin>Each binding’s host side, held open; same order as bindings.
id: u64Identifies 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
impl Fs
Sourcepub fn new(config: &Config) -> Fs
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.
Sourcepub fn with_procs(config: &Config, procs: Arc<ProcTable>) -> Fs
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.
Sourcepub fn with_cache(
config: &Config,
procs: Arc<ProcTable>,
cache: Arc<DirCache>,
) -> Fs
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.
Sourcefn canonicalize_bindings(&mut self)
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.
Sourcepub fn cache_get(&self, guest: &[u8]) -> Option<Arc<OwnedFd>>
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.
Sourcepub fn cache_put(&self, guest: &[u8], fd: Arc<OwnedFd>)
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- ItsO_PATHdescriptor.
Sourcepub fn mount_pin(&self, guest: &[u8]) -> Option<Option<Arc<OwnedFd>>>
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.
Sourcepub fn binding_below(&self, guest: &[u8]) -> bool
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.
Sourcepub fn pin_for_guest<'a>(
&self,
guest: &'a [u8],
) -> (Option<Arc<OwnedFd>>, &'a [u8])
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).
Sourcepub fn flush_cache(&self)
pub fn flush_cache(&self)
Forgets every cached directory of every view sharing the cache.
Sourcepub fn exe_of(&self, tid: i32) -> Option<Vec<u8>>
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.
Sourcepub fn virtual_cwd(&self, tid: i32) -> Option<Vec<u8>>
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.
Sourcepub fn binding_for_guest(&self, guest: &[u8]) -> Option<&Binding>
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.
Sourcepub fn binding_for_host(&self, host: &[u8]) -> Option<&Binding>
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.
Sourcepub fn substitute_guest_to_host(&self, guest: &[u8]) -> Vec<u8> ⓘ
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.