[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DDOMCSEPNIIT.24H3Y1KQYHYG0@nvidia.com>
Date: Wed, 22 Oct 2025 14:58:35 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Danilo Krummrich" <dakr@...nel.org>, <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>, <aliceryhl@...gle.com>,
<tmgross@...ch.edu>, <mmaurer@...gle.com>
Cc: <rust-for-linux@...r.kernel.org>, <linux-fsdevel@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 4/8] rust: debugfs: support for binary large objects
On Tue Oct 21, 2025 at 7:26 AM JST, Danilo Krummrich wrote:
<snip>
> @@ -65,8 +66,8 @@ fn deref(&self) -> &Self::Target {
>
> struct WriterAdapter<T>(T);
>
> -impl<'a, T: Writer> Display for WriterAdapter<&'a T> {
> - fn fmt(&self, f: &mut Formatter<'_>) -> Result {
> +impl<'a, T: Writer> fmt::Display for WriterAdapter<&'a T> {
> + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
> self.0.write(f)
> }
> }
> @@ -245,3 +246,139 @@ impl<T: Reader + Sync> WriteFile<T> for T {
> unsafe { FileOps::new(operations, 0o200) }
> };
> }
> +
> +extern "C" fn blob_read<T: BinaryWriter>(
> + file: *mut bindings::file,
> + buf: *mut c_char,
> + count: usize,
> + ppos: *mut file::Offset,
> +) -> 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.
> + let pos = unsafe { &mut *ppos };
> +
> + let mut writer = UserSlice::new(UserPtr::from_ptr(buf.cast()), count).writer();
> +
> + let ret = || -> Result<isize> {
> + let offset = *pos;
> +
> + let written = this.write_to_slice(&mut writer, offset)?;
> + *pos = offset.saturating_add(file::Offset::try_from(written)?);
> +
> + Ok(written.try_into()?)
> + }();
> +
> + match ret {
> + Ok(n) => n,
> + Err(e) => e.to_errno() as isize,
> + }
> +}
> +
> +pub(crate) trait BinaryReadFile<T> {
I know this trait is crate-local, but having a short documentation for
it would be helpful for first-time readers like myself. :)
Powered by blists - more mailing lists