pub struct Dir(/* private fields */);
Expand description
Owning handle to a DebugFS directory.
The directory in the filesystem represented by Dir
will be removed when handle has been
dropped and all children have been removed.
Implementations§
Source§impl Dir
impl Dir
Sourcepub fn subdir(&self, name: &CStr) -> Self
pub fn subdir(&self, name: &CStr) -> Self
Creates a subdirectory within this directory.
§Examples
let parent = Dir::new(c_str!("parent"));
let child = parent.subdir(c_str!("child"));
Sourcepub fn read_only_file<'a, T, E: 'a>(
&'a self,
name: &'a CStr,
data: impl PinInit<T, E> + 'a,
) -> impl PinInit<File<T>, E> + 'a
pub fn read_only_file<'a, T, E: 'a>( &'a self, name: &'a CStr, data: impl PinInit<T, E> + 'a, ) -> impl PinInit<File<T>, E> + 'a
Creates a read-only file in this directory.
The file’s contents are produced by invoking Writer::write
on the value initialized by
data
.
§Examples
let file = KBox::pin_init(dir.read_only_file(c_str!("foo"), 200), GFP_KERNEL)?;
// "my_debugfs_dir/foo" now contains the number 200.
// The file is removed when `file` is dropped.
Sourcepub fn read_callback_file<'a, T, E: 'a, F>(
&'a self,
name: &'a CStr,
data: impl PinInit<T, E> + 'a,
_f: &'static F,
) -> impl PinInit<File<T>, E> + 'a
pub fn read_callback_file<'a, T, E: 'a, F>( &'a self, name: &'a CStr, data: impl PinInit<T, E> + 'a, _f: &'static F, ) -> impl PinInit<File<T>, E> + 'a
Creates a read-only file in this directory, with contents from a callback.
f
must be a function item or a non-capturing closure.
This is statically asserted and not a safety requirement.
§Examples
let file = KBox::pin_init(
dir.read_callback_file(c_str!("bar"),
AtomicU32::new(3),
&|val, f| {
let out = val.load(Ordering::Relaxed);
writeln!(f, "{out:#010x}")
}),
GFP_KERNEL)?;
// Reading "foo/bar" will show "0x00000003".
file.store(10, Ordering::Relaxed);
// Reading "foo/bar" will now show "0x0000000a".
Sourcepub fn read_write_file<'a, T, E: 'a>(
&'a self,
name: &'a CStr,
data: impl PinInit<T, E> + 'a,
) -> impl PinInit<File<T>, E> + 'a
pub fn read_write_file<'a, T, E: 'a>( &'a self, name: &'a CStr, data: impl PinInit<T, E> + 'a, ) -> impl PinInit<File<T>, E> + 'a
Sourcepub fn read_write_callback_file<'a, T, E: 'a, F, W>(
&'a self,
name: &'a CStr,
data: impl PinInit<T, E> + 'a,
_f: &'static F,
_w: &'static W,
) -> impl PinInit<File<T>, E> + 'a
pub fn read_write_callback_file<'a, T, E: 'a, F, W>( &'a self, name: &'a CStr, data: impl PinInit<T, E> + 'a, _f: &'static F, _w: &'static W, ) -> impl PinInit<File<T>, E> + 'a
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
.
f
and w
must be function items or non-capturing closures.
This is statically asserted and not a safety requirement.
Sourcepub fn write_only_file<'a, T, E: 'a>(
&'a self,
name: &'a CStr,
data: impl PinInit<T, E> + 'a,
) -> impl PinInit<File<T>, E> + 'a
pub fn write_only_file<'a, T, E: 'a>( &'a self, name: &'a CStr, data: impl PinInit<T, E> + 'a, ) -> impl PinInit<File<T>, E> + 'a
Sourcepub fn write_callback_file<'a, T, E: 'a, W>(
&'a self,
name: &'a CStr,
data: impl PinInit<T, E> + 'a,
_w: &'static W,
) -> impl PinInit<File<T>, E> + 'a
pub fn write_callback_file<'a, T, E: 'a, W>( &'a self, name: &'a CStr, data: impl PinInit<T, E> + 'a, _w: &'static W, ) -> impl PinInit<File<T>, E> + 'a
Creates a write-only file in this directory, with write logic from a callback.
w
must be a function item or a non-capturing closure.
This is statically asserted and not a safety requirement.
Sourcepub fn scope<'a, T: 'a, E: 'a, F>(
&'a self,
data: impl PinInit<T, E> + 'a,
name: &'a CStr,
init: F,
) -> impl PinInit<Scope<T>, E> + 'a
pub fn scope<'a, T: 'a, E: 'a, F>( &'a self, data: impl PinInit<T, E> + 'a, name: &'a CStr, init: F, ) -> impl PinInit<Scope<T>, E> + 'a
Creates a new scope, which is a directory associated with some data T
.
The created directory will be a subdirectory of self
. The init
closure is called to
populate the directory with files and subdirectories. These files can reference the data
stored in the scope.
The entire directory tree created within the scope will be removed when the returned
Scope
handle is dropped.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Dir
impl !RefUnwindSafe for Dir
impl Send for Dir
impl Sync for Dir
impl Unpin for Dir
impl !UnwindSafe for Dir
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
slot
. Read more