Re: [RFC PATCH 16/19] rust: fs: allow file systems backed by a block device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux