Re: [PATCH v2 1/4] rust: debugfs: Bind DebugFS directory creation
From: Danilo Krummrich
Date: Thu May 01 2025 - 06:17:04 EST
On Wed, Apr 30, 2025 at 11:31:56PM +0000, Matthew Maurer wrote:
>
> + /// Create a DebugFS subdirectory.
> + ///
> + /// # Examples
> + ///
> + /// ```
> + /// # use kernel::c_str;
> + /// # use kernel::debugfs::Dir;
> + /// {
> + /// let parent = Dir::new(c_str!("parent"));
> + /// // parent exists in DebugFS here.
> + /// let child = parent.subdir(c_str!("child"));
> + /// // parent/child exists in DebugFS here.
> + /// }
> + /// // Neither exist here.
> + /// ```
> + pub fn subdir(&self, name: &CStr) -> Self {
> + Self::create(name, Some(self))
> + }
I think this should return a new type (SubDir), which is a transparent wrapper
of Dir and dereferences to Dir.
Subsequently, we can remove Dir::keep() implement SubDir::keep() instead. This
ensures that we can never call keep() on the root directory, which would always
be a bug.
As an alternative to the Deref impl, you can also implement
`From<SubDir> for Dir`, such that a SubDir can either be "kept" or converted to
a Dir. Probably, that's even better.