rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Danilo Krummrich <dakr@kernel.org>
To: 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, aliceryhl@google.com, tmgross@umich.edu,
	mmaurer@google.com
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	Danilo Krummrich <dakr@kernel.org>
Subject: [PATCH 6/7] rust: debugfs: support binary large objects for ScopedDir
Date: Sat,  4 Oct 2025 00:26:43 +0200	[thread overview]
Message-ID: <20251003222729.322059-7-dakr@kernel.org> (raw)
In-Reply-To: <20251003222729.322059-1-dakr@kernel.org>

Add support for creating binary debugfs files via ScopedDir. This
mirrors the existing functionality for Dir, but without producing an
owning handle -- files are automatically removed when the associated
Scope is dropped.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 rust/kernel/debugfs.rs | 45 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/rust/kernel/debugfs.rs b/rust/kernel/debugfs.rs
index 3c3bbcc126ef..0eb1719e4953 100644
--- a/rust/kernel/debugfs.rs
+++ b/rust/kernel/debugfs.rs
@@ -531,6 +531,20 @@ pub fn read_only_file<T: Writer + Send + Sync + 'static>(&self, name: &CStr, dat
         self.create_file(name, data, &T::FILE_OPS)
     }
 
+    /// Creates a read-only binary file in this directory.
+    ///
+    /// The file's contents are produced by invoking [`BinaryWriter::write_to_slice`].
+    ///
+    /// This function does not produce an owning handle to the file. The created file is removed
+    /// when the [`Scope`] that this directory belongs to is dropped.
+    pub fn read_binary_file<T: BinaryWriter + Send + Sync + 'static>(
+        &self,
+        name: &CStr,
+        data: &'data T,
+    ) {
+        self.create_file(name, data, &T::FILE_OPS)
+    }
+
     /// Creates a read-only file in this directory, with contents from a callback.
     ///
     /// The file contents are generated by calling `f` with `data`.
@@ -568,6 +582,22 @@ pub fn read_write_file<T: Writer + Reader + Send + Sync + 'static>(
         self.create_file(name, data, vtable)
     }
 
+    /// Creates a read-write binary file in this directory.
+    ///
+    /// Reading the file uses the [`BinaryWriter`] implementation on `data`. Writing to the file
+    /// uses the [`BinaryReader`] implementation on `data`.
+    ///
+    /// This function does not produce an owning handle to the file. The created file is removed
+    /// when the [`Scope`] that this directory belongs to is dropped.
+    pub fn read_write_binary_file<T: BinaryWriter + BinaryReader + Send + Sync + 'static>(
+        &self,
+        name: &CStr,
+        data: &'data T,
+    ) {
+        let vtable = &<T as BinaryReadWriteFile<_>>::FILE_OPS;
+        self.create_file(name, data, vtable)
+    }
+
     /// Creates a read-write file in this directory, with logic from callbacks.
     ///
     /// Reading from the file is handled by `f`. Writing to the file is handled by `w`.
@@ -607,6 +637,21 @@ pub fn write_only_file<T: Reader + Send + Sync + 'static>(&self, name: &CStr, da
         self.create_file(name, data, vtable)
     }
 
+    /// Creates a write-only binary file in this directory.
+    ///
+    /// Writing to the file uses the [`BinaryReader`] implementation on `data`.
+    ///
+    /// This function does not produce an owning handle to the file. The created file is removed
+    /// when the [`Scope`] that this directory belongs to is dropped.
+    pub fn write_binary_file<T: BinaryReader + Send + Sync + 'static>(
+        &self,
+        name: &CStr,
+        data: &'data T,
+    ) {
+        let vtable = &<T as BinaryWriteFile<_>>::FILE_OPS;
+        self.create_file(name, data, vtable)
+    }
+
     /// Creates a write-only file in this directory, with write logic from a callback.
     ///
     /// Writing to the file is handled by `w`.
-- 
2.51.0


  parent reply	other threads:[~2025-10-03 22:28 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-03 22:26 [PATCH 0/7] Binary Large Objects for Rust DebugFS Danilo Krummrich
2025-10-03 22:26 ` [PATCH 1/7] rust: uaccess: add UserSliceReader::read_slice_partial() Danilo Krummrich
2025-10-17 11:11   ` Alice Ryhl
2025-10-17 11:50     ` Danilo Krummrich
2025-10-03 22:26 ` [PATCH 2/7] rust: uaccess: add UserSliceWriter::write_slice_partial() Danilo Krummrich
2025-10-03 22:26 ` [PATCH 3/7] rust: debugfs: support for binary large objects Danilo Krummrich
2025-10-17 12:59   ` Alice Ryhl
2025-10-17 14:37     ` Danilo Krummrich
2025-10-17 14:53       ` Danilo Krummrich
2025-10-19  9:44         ` Alice Ryhl
2025-10-19 12:01           ` Danilo Krummrich
2025-10-20  8:12             ` Alice Ryhl
2025-10-20  9:40               ` Danilo Krummrich
2025-10-20  9:42                 ` Alice Ryhl
2025-10-20  9:49                   ` Danilo Krummrich
2025-10-19  9:50       ` Alice Ryhl
2025-10-19 11:24         ` Danilo Krummrich
2025-10-20  8:13           ` Alice Ryhl
2025-10-20  9:35             ` Danilo Krummrich
2025-10-20  9:39               ` Alice Ryhl
2025-10-20  9:41                 ` Danilo Krummrich
2025-10-03 22:26 ` [PATCH 4/7] rust: debugfs: support blobs from smart pointers Danilo Krummrich
2025-10-03 23:12   ` Matthew Maurer
2025-10-03 23:26     ` Danilo Krummrich
2025-10-03 23:36       ` Matthew Maurer
2025-10-03 22:26 ` [PATCH 5/7] samples: rust: debugfs: add example for blobs Danilo Krummrich
2025-10-20 10:01   ` Alice Ryhl
2025-10-03 22:26 ` Danilo Krummrich [this message]
2025-10-17 13:00   ` [PATCH 6/7] rust: debugfs: support binary large objects for ScopedDir Alice Ryhl
2025-10-17 14:55     ` Danilo Krummrich
2025-10-03 22:26 ` [PATCH 7/7] samples: rust: debugfs_scoped: add example for blobs Danilo Krummrich
2025-10-20 10:02   ` Alice Ryhl

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=20251003222729.322059-7-dakr@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).