[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aPnmriUUdbsQAu3e@google.com>
Date: Thu, 23 Oct 2025 08:26:22 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: gregkh@...uxfoundation.org, rafael@...nel.org, ojeda@...nel.org,
alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net,
bjorn3_gh@...tonmail.com, lossin@...nel.org, a.hindborg@...nel.org,
tmgross@...ch.edu, mmaurer@...gle.com, rust-for-linux@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 06/10] rust: debugfs: support for binary large objects
On Wed, Oct 22, 2025 at 04:30:40PM +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.
>
> Reviewed-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> Reviewed-by: Matthew Maurer <mmaurer@...gle.com>
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
> +extern "C" fn blob_read<T: BinaryWriter>(
> + file: *mut bindings::file,
> + buf: *mut c_char,
> + count: usize,
> + ppos: *mut bindings::loff_t,
> +) -> isize {
> + // SAFETY:
> + // - `file` is a valid pointer to a `struct file`.
> + // - The type invariant of `FileOps` guarantees that `private_data` points to a valid `T`.
> + let this = unsafe { &*((*file).private_data.cast::<T>()) };
> +
> + // SAFETY:
> + // `ppos` is a valid `file::Offset` pointer.
> + // We have exclusive access to `ppos`.
> + let pos = unsafe { file::Offset::from_raw(ppos) };
> +
> + let mut writer = UserSlice::new(UserPtr::from_ptr(buf.cast()), count).writer();
> +
> + let ret = || -> Result<isize> {
> + let written = this.write_to_slice(&mut writer, pos)?;
> +
> + Ok(written.try_into()?)
Hmm ... a conversion? Sounds like write_to_slice() has the wrong return
type.
Alice
Powered by blists - more mailing lists