//! An immutable file-page snapshot seeds the existing reference-counted pager. //! The caller binds the borrowed page plan to its validated open inode. use super::{file_map::{Page,Error as FileError},turkfs_reader::BlockReader}; use super::mapping::Owner; use super::page_faults::pager::{Backend,Pager,Error}; pub struct Source<'a>{plan:Page<'a>,bytes:[u8;4096]} impl<'a> Source<'a>{ pub fn read(plan:Page<'a>,reader:&mut R)->Result{ let mut bytes=[0xa5;4096];plan.populate(reader,&mut bytes)?;Ok(Self{plan,bytes}) } pub fn file_bytes(&self)->usize{self.plan.file_bytes()} pub fn offset(&self)->usize{self.plan.offset()} pub fn bytes(&self)->&[u8;4096]{&self.bytes} /// The pager retains a single shared RO lease. A write fault copies that /// lease through its existing transactional backend, preserving this source. pub fn share(&self,pager:&mut Pager,a:Owner,b:Owner,address_a:u64,address_b:u64)->Result<(),Error>{ pager.share_cow(a,b,address_a,address_b,&self.bytes) } }