Struct Dir

Source
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

Source

pub fn new(name: &CStr) -> Self

Create a new directory in DebugFS at the root.

§Examples
let debugfs = Dir::new(c_str!("parent"));
Source

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"));
Source

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
where T: Writer + Send + Sync + 'static,

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.
Source

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
where T: Send + Sync + 'static, F: Fn(&T, &mut Formatter<'_>) -> Result + Send + Sync,

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".
Source

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
where T: Writer + Reader + Send + Sync + 'static,

Creates a read-write file in this directory.

Reading the file uses the Writer implementation. Writing to the file uses the Reader implementation.

Source

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
where T: Send + Sync + 'static, F: Fn(&T, &mut Formatter<'_>) -> Result + Send + Sync, W: Fn(&T, &mut UserSliceReader) -> Result + Send + Sync,

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.

Source

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
where T: Reader + Send + Sync + 'static,

Creates a write-only file in this directory.

The file owns its backing data. Writing to the file uses the Reader implementation.

The file is removed when the returned File is dropped.

Source

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
where T: Send + Sync + 'static, W: Fn(&T, &mut UserSliceReader) -> Result + Send + Sync,

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.

Source

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
where F: for<'data, 'dir> FnOnce(&'data T, &'dir ScopedDir<'data, 'dir>) + '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§

Source§

impl Clone for Dir

Source§

fn clone(&self) -> Dir

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Init<T> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PinInit<T> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.