From: Alice Ryhl <aliceryhl@google.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: gregkh@linuxfoundation.org, rafael@kernel.org, ojeda@kernel.org,
alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu, mmaurer@google.com,
rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 06/10] rust: debugfs: support for binary large objects
Date: Fri, 24 Oct 2025 10:36:55 +0000 [thread overview]
Message-ID: <aPtWx4i3WuIlcWEM@google.com> (raw)
In-Reply-To: <CAH5fLghiEqqccH-0S9-GD7pJaNuVpuo_NecMMmGVF+zR7Xs_dA@mail.gmail.com>
On Thu, Oct 23, 2025 at 12:21:24PM +0200, Alice Ryhl wrote:
> On Thu, Oct 23, 2025 at 12:09 PM Danilo Krummrich <dakr@kernel.org> wrote:
> >
> > On Thu Oct 23, 2025 at 10:26 AM CEST, Alice Ryhl wrote:
> > > 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@linuxfoundation.org>
> > >> Reviewed-by: Matthew Maurer <mmaurer@google.com>
> > >> Signed-off-by: Danilo Krummrich <dakr@kernel.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.
> >
> > write_to_slice() returns the number of bytes written as usize, which seems
> > correct, no?
>
> Yes, you're right, I think usize is the right value. The cast is
> unfortunate, but it can't really be avoided. In practice it should
> never fail because slice lengths always fit in an isize, but isize
> isn't the right type.
>
> Alice
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
next prev parent reply other threads:[~2025-10-24 10:36 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-22 14:30 [PATCH v3 00/10] Binary Large Objects for Rust DebugFS Danilo Krummrich
2025-10-22 14:30 ` [PATCH v3 01/10] rust: fs: add new type file::Offset Danilo Krummrich
2025-10-22 14:42 ` Miguel Ojeda
2025-10-24 12:15 ` Alice Ryhl
2025-10-28 11:04 ` Danilo Krummrich
2025-11-01 14:16 ` Alexandre Courbot
2025-10-22 14:30 ` [PATCH v3 02/10] rust: uaccess: add UserSliceReader::read_slice_partial() Danilo Krummrich
2025-10-24 10:39 ` Alice Ryhl
2025-11-01 14:16 ` Alexandre Courbot
2025-10-22 14:30 ` [PATCH v3 03/10] rust: uaccess: add UserSliceReader::read_slice_file() Danilo Krummrich
2025-11-01 14:16 ` Alexandre Courbot
2025-10-22 14:30 ` [PATCH v3 04/10] rust: uaccess: add UserSliceWriter::write_slice_partial() Danilo Krummrich
2025-10-23 8:33 ` Alice Ryhl
2025-10-28 13:57 ` Miguel Ojeda
2025-11-01 14:19 ` Alexandre Courbot
2025-10-22 14:30 ` [PATCH v3 05/10] rust: uaccess: add UserSliceWriter::write_slice_file() Danilo Krummrich
2025-10-23 8:30 ` Alice Ryhl
2025-10-23 10:35 ` Danilo Krummrich
2025-10-23 10:37 ` Alice Ryhl
2025-10-23 11:03 ` Danilo Krummrich
2025-10-23 11:20 ` Alice Ryhl
2025-10-23 12:43 ` Danilo Krummrich
2025-10-24 10:37 ` Alice Ryhl
2025-10-24 18:02 ` Miguel Ojeda
2025-11-01 14:27 ` Alexandre Courbot
2025-11-01 15:06 ` Miguel Ojeda
2025-10-28 14:07 ` Miguel Ojeda
2025-10-22 14:30 ` [PATCH v3 06/10] rust: debugfs: support for binary large objects Danilo Krummrich
2025-10-23 8:26 ` Alice Ryhl
2025-10-23 10:09 ` Danilo Krummrich
2025-10-23 10:21 ` Alice Ryhl
2025-10-24 10:36 ` Alice Ryhl [this message]
2025-10-22 14:30 ` [PATCH v3 07/10] rust: debugfs: support blobs from smart pointers Danilo Krummrich
2025-10-23 8:24 ` Alice Ryhl
2025-10-22 14:30 ` [PATCH v3 08/10] samples: rust: debugfs: add example for blobs Danilo Krummrich
2025-10-22 14:30 ` [PATCH v3 09/10] rust: debugfs: support binary large objects for ScopedDir Danilo Krummrich
2025-10-23 8:23 ` Alice Ryhl
2025-10-22 14:30 ` [PATCH v3 10/10] samples: rust: debugfs_scoped: add example for blobs Danilo Krummrich
2025-10-28 13:47 ` [PATCH v3 00/10] Binary Large Objects for Rust DebugFS Miguel Ojeda
2025-11-05 0:25 ` Danilo Krummrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aPtWx4i3WuIlcWEM@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=mmaurer@google.com \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.