/// Reads the INode at the given inode number.
Reads the INode at the given inode number.
Reads the INode at the given inode number .
pub fn inode(&self, inode_number: u32) -> Result<Arc<INode>, ParsingError> {
        if inode_number < 1 {
            // INode number 0 is not allowed per ext4 spec.
            return Err(ParsingError::InvalidInode(inode_number));
        }
        let sb = self.super_block()?;
        let block_size = self.block_size()?;
        // The first Block Group starts with:
        // - 1024 byte padding
        // - 1024 byte Super Block
        // Then in the next block, there are many blocks worth of Block Group Descriptors.
        // If the block size is 2048 bytes or larger, then the 1024 byte padding, and the
        // Super Block both fit in the first block (0), and the Block Group Descriptors start
        // at block 1.
        //
        // A 1024 byte block size means the padding takes block 0 and the Super Block takes
        // block 1. This means the Block Group Descriptors start in block 2.
        let bgd_table_offset = if block_size >= MIN_EXT4_SIZE {
            // Padding and Super Block both fit in the first block, so offset to the next
            // block.
            block_size
        } else {
            // Block size is less than 2048. The only valid block size smaller than 2048 is 1024.
            // Padding and Super Block take one block each, so offset to the third block.
            block_size * 2
        };
        let bgd_offset = (inode_number - 1) as u64 / sb.e2fs_ipg.get() as u64
            * size_of::<BlockGroupDesc32>() as u64;
        let bgd = BlockGroupDesc32::from_reader_with_offset(
            self.reader.clone(),
            bgd_table_offset + bgd_offset,
            ParsingError::InvalidBlockGroupDesc(block_size),
        )?;
        // Offset could really be anywhere, and the Reader will enforce reading within the
        // filesystem size. Not much can be checked here.
        let inode_table_offset =
            (inode_number - 1) as u64 % sb.e2fs_ipg.get() as u64 * sb.e2fs_inode_size.get() as u64;
        let inode_addr = (bgd.ext2bgd_i_tables.get() as u64 * block_size) + inode_table_offset;
        if inode_addr < MIN_EXT4_SIZE {
            return Err(ParsingError::InvalidAddress(
                InvalidAddressErrorType::Lower,
                inode_addr,
                MIN_EXT4_SIZE,
            ));
        }
        INode::from_reader_with_offset(
            self.reader.clone(),
            inode_addr,
            ParsingError::InvalidInode(inode_number),
        )
    }
pub fn inode ( & self , inode_number : u32 ) -> Result < Arc < INode > , ParsingError > { if inode_number < 1 { // INode number 0 is not allowed per ext4 spec. return Err ( ParsingError :: InvalidInode ( inode_number ) ) ; } let sb = self . super_block ( ) ? ; let block_size = self . block_size ( ) ? ; // The first Block Group starts with: // - 1024 byte padding // - 1024 byte Super Block // Then in the next block, there are many blocks worth of Block Group Descriptors. // If the block size is 2048 bytes or larger, then the 1024 byte padding, and the // Super Block both fit in the first block (0), and the Block Group Descriptors start // at block 1. // // A 1024 byte block size means the padding takes block 0 and the Super Block takes // block 1. This means the Block Group Descriptors start in block 2. let bgd_table_offset = if block_size >= MIN_EXT4_SIZE { // Padding and Super Block both fit in the first block, so offset to the next // block. block_size } else { // Block size is less than 2048. The only valid block size smaller than 2048 is 1024. // Padding and Super Block take one block each, so offset to the third block. block_size * 2 } ; let bgd_offset = ( inode_number - 1 ) as u64 / sb . e2fs_ipg . get ( ) as u64 * size_of :: < BlockGroupDesc32 > ( ) as u64 ; let bgd = BlockGroupDesc32 :: from_reader_with_offset ( self . reader . clone ( ) , bgd_table_offset + bgd_offset , ParsingError :: InvalidBlockGroupDesc ( block_size ) , ) ? ; // Offset could really be anywhere, and the Reader will enforce reading within the // filesystem size. Not much can be checked here. let inode_table_offset = ( inode_number - 1 ) as u64 % sb . e2fs_ipg . get ( ) as u64 * sb . e2fs_inode_size . get ( ) as u64 ; let inode_addr = ( bgd . ext2bgd_i_tables . get ( ) as u64 * block_size ) + inode_table_offset ; if inode_addr < MIN_EXT4_SIZE { return Err ( ParsingError :: InvalidAddress ( InvalidAddressErrorType :: Lower , inode_addr , MIN_EXT4_SIZE , ) ) ; } INode :: from_reader_with_offset ( self . reader . clone ( ) , inode_addr , ParsingError :: InvalidInode ( inode_number ) , ) }
Reads the INode at the given inode number.
Reads the INode at the given inode number .
&self
inode_number
u32