summaryrefslogtreecommitdiff
path: root/samples/rust/rust_debugfs_scoped.rs
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2025-10-22 16:30:44 +0200
committerDanilo Krummrich <dakr@kernel.org>2025-11-05 00:35:40 +0100
commitf656279afde16afee3ac163b90584ddceacb4e61 (patch)
treef90abc8807d770d6a4bcced1cdb76fceaaa81df0 /samples/rust/rust_debugfs_scoped.rs
parent35bd14d929af1b16f58d7b786c52187628427922 (diff)
samples: rust: debugfs_scoped: add example for blobs
Extend the rust_debugfs_scoped sample to demonstrate how to export a large binary object through a ScopedDir. Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Matthew Maurer <mmaurer@google.com> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'samples/rust/rust_debugfs_scoped.rs')
-rw-r--r--samples/rust/rust_debugfs_scoped.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/samples/rust/rust_debugfs_scoped.rs b/samples/rust/rust_debugfs_scoped.rs
index b0c4e76b123e..c80312cf168d 100644
--- a/samples/rust/rust_debugfs_scoped.rs
+++ b/samples/rust/rust_debugfs_scoped.rs
@@ -9,6 +9,7 @@
use core::sync::atomic::AtomicUsize;
use kernel::debugfs::{Dir, Scope};
use kernel::prelude::*;
+use kernel::sizes::*;
use kernel::sync::Mutex;
use kernel::{c_str, new_mutex, str::CString};
@@ -66,18 +67,22 @@ fn create_file_write(
GFP_KERNEL,
)?;
}
+ let blob = KBox::pin_init(new_mutex!([0x42; SZ_4K]), GFP_KERNEL)?;
let scope = KBox::pin_init(
- mod_data
- .device_dir
- .scope(DeviceData { name, nums }, &file_name, |dev_data, dir| {
+ mod_data.device_dir.scope(
+ DeviceData { name, nums, blob },
+ &file_name,
+ |dev_data, dir| {
for (idx, val) in dev_data.nums.iter().enumerate() {
let Ok(name) = CString::try_from_fmt(fmt!("{idx}")) else {
return;
};
dir.read_write_file(&name, val);
}
- }),
+ dir.read_write_binary_file(c_str!("blob"), &dev_data.blob);
+ },
+ ),
GFP_KERNEL,
)?;
(*mod_data.devices.lock()).push(scope, GFP_KERNEL)?;
@@ -110,6 +115,7 @@ impl ModuleData {
struct DeviceData {
name: CString,
nums: KVec<AtomicUsize>,
+ blob: Pin<KBox<Mutex<[u8; SZ_4K]>>>,
}
fn init_control(base_dir: &Dir, dyn_dirs: Dir) -> impl PinInit<Scope<ModuleData>> + '_ {