Wedson Almeida Filho <wedsonaf@xxxxxxxxx> writes: [...] > @@ -479,6 +500,65 @@ pub fn get_or_create_inode(&self, ino: Ino) -> Result<Either<ARef<INode<T>>, New > }))) > } > } > + > + /// Reads a block from the block device. > + #[cfg(CONFIG_BUFFER_HEAD)] > + pub fn bread(&self, block: u64) -> Result<ARef<buffer::Head>> { > + // Fail requests for non-blockdev file systems. This is a compile-time check. > + match T::SUPER_TYPE { > + Super::BlockDev => {} > + _ => return Err(EIO), > + } > + > + // SAFETY: This function is only valid after the `NeedsInit` typestate, so the block size > + // is known and the superblock can be used to read blocks. > + let ptr = > + ptr::NonNull::new(unsafe { bindings::sb_bread(self.0.get(), block) }).ok_or(EIO)?; > + // SAFETY: `sb_bread` returns a referenced buffer head. Ownership of the increment is > + // passed to the `ARef` instance. > + Ok(unsafe { ARef::from_raw(ptr.cast()) }) I would prefer the target of the cast to be explicit. BR Andreas