When a file operation occurs, the VFS checks if the path falls under a mount:
Mount lookup
// src/vfs/mod.rsfn find_mount(&self, vfs_path: &str) -> Option<&MountPoint> { self.mounts .iter() .filter(|m| vfs_path == m.vfs_path || vfs_path.starts_with(&format!("{}/", m.vfs_path))) .max_by_key(|m| m.vfs_path.len()) // Most specific mount wins}
If a mount is found, the VFS translates the path and forwards the operation to std::fs:
Read through mount
pub fn read(&self, path: &str) -> Result<Vec<u8>> { let p = VfsPath::normalize(path); // Try in-memory first if let Some(node) = self.nodes.get(&p) { return /* ... */; } // Fall back to host mount if let Some(mp) = self.find_mount(&p) { let rel = p.strip_prefix(&mp.vfs_path).unwrap_or(""); let host = format!("{}/{}", mp.host_path, rel); return std::fs::read(&host)?; // Read from real filesystem } bail!("no such file: {}", path)}
Write operations with mounts
Write to mounted path
pub fn write(&mut self, path: &str, data: Vec<u8>) -> Result<()> { let p = VfsPath::normalize(path); // Check read-only protection self.check_write_allowed(&p)?; // Try host mount first if let Some(mp) = self.find_mount_mut(&p) { let rel = p.strip_prefix(&mp.vfs_path).unwrap_or(""); let host = format!("{}/{}", mp.host_path, rel); return std::fs::write(&host, &data)?; // Write to real filesystem } // Otherwise store in memory self.nodes.insert(p, FsNode::File(data)); Ok(())}
Security reminder: Only mount directories that you trust Nash to access. Mounted paths give Nash full read (and write, unless read-only) access to those host locations.