Re: [PATCH v2 4/8] rust: debugfs: support for binary large objects

Alice Ryhl
2025-10-21T14:03:15Z

On Tue, Oct 21, 2025 at 12:26:16AM +0200, Danilo Krummrich wrote:
> Introduce support for read-only, write-only, and read-write binary files
> in Rust debugfs. This adds:
>
> - BinaryWriter and BinaryReader traits for writing to and reading from
> user slices in binary form.
> - New Dir methods: read_binary_file(), write_binary_file(),
> `read_write_binary_file`.
> - Corresponding FileOps implementations: BinaryReadFile,
> BinaryWriteFile, BinaryReadWriteFile.
>
> This allows kernel modules to expose arbitrary binary data through
> debugfs, with proper support for offsets and partial reads/writes.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>

> +/// Trait for types that can be constructed from a binary representation.
> +pub trait BinaryReader {
> + /// Reads the binary form of `self` from `reader`.
> + ///
> + /// `offset` is the requested offset into the binary representation of `self`.
> + ///
> + /// On success, returns the number of bytes read from `reader`.
> + fn read_from_slice(&self, reader: &mut UserSliceReader, offset: file::Offset) -> Result<usize>;

Maybe this should just take a `&mut Offset` to fit what I suggested
under the uaccess slice patch?

Alice