Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+10 -4
+10 -4
samples/rust/rust_debugfs_scoped.rs
··· 9 9 use core::sync::atomic::AtomicUsize; 10 10 use kernel::debugfs::{Dir, Scope}; 11 11 use kernel::prelude::*; 12 + use kernel::sizes::*; 12 13 use kernel::sync::Mutex; 13 14 use kernel::{c_str, new_mutex, str::CString}; 14 15 ··· 67 66 GFP_KERNEL, 68 67 )?; 69 68 } 69 + let blob = KBox::pin_init(new_mutex!([0x42; SZ_4K]), GFP_KERNEL)?; 70 70 71 71 let scope = KBox::pin_init( 72 - mod_data 73 - .device_dir 74 - .scope(DeviceData { name, nums }, &file_name, |dev_data, dir| { 72 + mod_data.device_dir.scope( 73 + DeviceData { name, nums, blob }, 74 + &file_name, 75 + |dev_data, dir| { 75 76 for (idx, val) in dev_data.nums.iter().enumerate() { 76 77 let Ok(name) = CString::try_from_fmt(fmt!("{idx}")) else { 77 78 return; 78 79 }; 79 80 dir.read_write_file(&name, val); 80 81 } 81 - }), 82 + dir.read_write_binary_file(c_str!("blob"), &dev_data.blob); 83 + }, 84 + ), 82 85 GFP_KERNEL, 83 86 )?; 84 87 (*mod_data.devices.lock()).push(scope, GFP_KERNEL)?; ··· 115 110 struct DeviceData { 116 111 name: CString, 117 112 nums: KVec<AtomicUsize>, 113 + blob: Pin<KBox<Mutex<[u8; SZ_4K]>>>, 118 114 } 119 115 120 116 fn init_control(base_dir: &Dir, dyn_dirs: Dir) -> impl PinInit<Scope<ModuleData>> + '_ {