/// Load RAFS super block and optionally cache inodes.
Load RAFS super block and optionally cache inodes.
Load RAFS super block and optionally cache inodes .
pub fn load(&mut self, r: &mut RafsIoReader) -> Result<()> {
        let mut sb = OndiskSuperBlock::new();
        r.read_exact(sb.as_mut())?;
        sb.validate()?;
        self.meta.magic = sb.magic();
        self.meta.version = sb.version();
        self.meta.sb_size = sb.sb_size();
        self.meta.block_size = sb.block_size();
        self.meta.flags = RafsSuperFlags::from_bits(sb.flags())
            .ok_or_else(|| einval!(format!("invalid super flags {:x}", sb.flags())))?;
        self.meta.prefetch_table_offset = sb.prefetch_table_offset();
        self.meta.prefetch_table_entries = sb.prefetch_table_entries();
        info!("rafs superblock features: {}", self.meta.flags);
        match self.meta.version {
            RAFS_SUPER_VERSION_V4 => {
                self.meta.inodes_count = std::u64::MAX;
            }
            RAFS_SUPER_VERSION_V5 => {
                self.meta.inodes_count = sb.inodes_count();
                self.meta.inode_table_entries = sb.inode_table_entries();
                self.meta.inode_table_offset = sb.inode_table_offset();
                self.meta.blob_table_offset = sb.blob_table_offset();
                self.meta.blob_table_size = sb.blob_table_size();
            }
            _ => return Err(ebadf!("invalid superblock version number")),
        }
        match sb.version() {
            RAFS_SUPER_VERSION_V4 => {
                // TODO: Support Rafs v4
                unimplemented!();
            }
            RAFS_SUPER_VERSION_V5 => match self.mode {
                RafsMode::Direct => {
                    let mut inodes = Box::new(DirectMapping::new(&self.meta, self.digest_validate));
                    inodes.load(r)?;
                    self.inodes = inodes;
                }
                RafsMode::Cached => {
                    r.seek(SeekFrom::Start(sb.blob_table_offset()))?;
                    let mut blob_table = OndiskBlobTable::new();
                    blob_table.load(r, sb.blob_table_size() as usize)?;
                    let mut inodes = Box::new(CachedInodes::new(
                        self.meta,
                        blob_table,
                        self.digest_validate,
                    ));
                    inodes.load(r)?;
                    self.inodes = inodes;
                }
            },
            _ => return Err(einval!("invalid superblock version number")),
        }
        Ok(())
    }
pub fn load ( & mut self , r : & mut RafsIoReader ) -> Result < ( ) > { let mut sb = OndiskSuperBlock :: new ( ) ; r . read_exact ( sb . as_mut ( ) ) ? ; sb . validate ( ) ? ; self . meta . magic = sb . magic ( ) ; self . meta . version = sb . version ( ) ; self . meta . sb_size = sb . sb_size ( ) ; self . meta . block_size = sb . block_size ( ) ; self . meta . flags = RafsSuperFlags :: from_bits ( sb . flags ( ) ) . ok_or_else ( | | einval ! ( format ( " " sb flags ( ) ) ) ) ? ; self . meta . prefetch_table_offset = sb . prefetch_table_offset ( ) ; self . meta . prefetch_table_entries = sb . prefetch_table_entries ( ) ; info ! ( " " self meta flags ) ; match self . meta . version { RAFS_SUPER_VERSION_V4 => { self . meta . inodes_count = std :: u64 :: MAX ; } RAFS_SUPER_VERSION_V5 => { self . meta . inodes_count = sb . inodes_count ( ) ; self . meta . inode_table_entries = sb . inode_table_entries ( ) ; self . meta . inode_table_offset = sb . inode_table_offset ( ) ; self . meta . blob_table_offset = sb . blob_table_offset ( ) ; self . meta . blob_table_size = sb . blob_table_size ( ) ; } _ => return Err ( ebadf ! ( " " ) ) , } match sb . version ( ) { RAFS_SUPER_VERSION_V4 => { // TODO: Support Rafs v4 unimplemented ! ( ) ; } RAFS_SUPER_VERSION_V5 => match self . mode { RafsMode :: Direct => { let mut inodes = Box :: new ( DirectMapping :: new ( & self . meta , self . digest_validate ) ) ; inodes . load ( r ) ? ; self . inodes = inodes ; } RafsMode :: Cached => { r . seek ( SeekFrom :: Start ( sb . blob_table_offset ( ) ) ) ? ; let mut blob_table = OndiskBlobTable :: new ( ) ; blob_table . load ( r , sb . blob_table_size ( ) as usize ) ? ; let mut inodes = Box :: new ( CachedInodes :: new ( self . meta , blob_table , self . digest_validate , ) ) ; inodes . load ( r ) ? ; self . inodes = inodes ; } } , _ => return Err ( einval ! ( " " ) ) , } Ok ( ( ) ) }
Load RAFS super block and optionally cache inodes.
Load RAFS super block and optionally cache inodes .
&mut self
r
&mut RafsIoReader