Lines Matching +full:entry +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0
58 mod entry;
60 use entry::Entry;
66 // If we have a parent, we hold a reference to it in the `Entry`. This prevents the `dentry`
67 // we point to from being cleaned up if our parent `Dir`/`Entry` is dropped before us.
73 pub struct Dir(#[cfg(CONFIG_DEBUG_FS)] Option<Arc<Entry<'static>>>);
77 fn create(name: &CStr, parent: Option<&Dir>) -> Self {
81 // If the parent couldn't be allocated, just early-return
83 Some(Dir(Some(entry))) => Some(entry.clone()),
87 // If Arc creation fails, the `Entry` will be dropped, so the directory will be
89 Arc::new(Entry::dynamic_dir(name, parent_entry), GFP_KERNEL).ok(),
100 name: &'a CStr,
103 ) -> impl PinInit<File<T>, E> + 'a
110 // SAFETY: Because data derives from a scope, and our entry will be dropped before
111 // the data is dropped, it is guaranteed to outlive the entry we return.
112 unsafe { Entry::dynamic_file(name, parent.clone(), data, file_ops) }
114 Entry::empty()
119 scope <- scope
132 pub fn new(name: &CStr) -> Self {
133 Dir::create(name, None)
145 pub fn subdir(&self, name: &CStr) -> Self {
146 Dir::create(name, Some(self))
149 /// Creates a read-only file in this directory.
167 name: &'a CStr,
169 ) -> impl PinInit<File<T>, E> + 'a
174 self.create_file(name, data, file_ops)
177 /// Creates a read-only binary file in this directory.
193 name: &'a CStr,
195 ) -> impl PinInit<File<T>, E> + 'a
199 self.create_file(name, data, &T::FILE_OPS)
202 /// Creates a read-only file in this directory, with contents from a callback.
204 /// `f` must be a function item or a non-capturing closure.
234 name: &'a CStr,
237 ) -> impl PinInit<File<T>, E> + 'a
240 F: Fn(&T, &mut fmt::Formatter<'_>) -> fmt::Result + Send + Sync,
243 self.create_file(name, data, file_ops)
246 /// Creates a read-write file in this directory.
252 name: &'a CStr,
254 ) -> impl PinInit<File<T>, E> + 'a
259 self.create_file(name, data, file_ops)
262 /// Creates a read-write binary file in this directory.
268 name: &'a CStr,
270 ) -> impl PinInit<File<T>, E> + 'a
275 self.create_file(name, data, file_ops)
278 /// Creates a read-write file in this directory, with logic from callbacks.
282 /// `f` and `w` must be function items or non-capturing closures.
286 name: &'a CStr,
290 ) -> impl PinInit<File<T>, E> + 'a
293 F: Fn(&T, &mut fmt::Formatter<'_>) -> fmt::Result + Send + Sync,
294 W: Fn(&T, &mut UserSliceReader) -> Result + Send + Sync,
300 self.create_file(name, data, file_ops)
303 /// Creates a write-only file in this directory.
311 name: &'a CStr,
313 ) -> impl PinInit<File<T>, E> + 'a
317 self.create_file(name, data, &T::FILE_OPS)
320 /// Creates a write-only binary file in this directory.
328 name: &'a CStr,
330 ) -> impl PinInit<File<T>, E> + 'a
334 self.create_file(name, data, &T::FILE_OPS)
337 /// Creates a write-only file in this directory, with write logic from a callback.
339 /// `w` must be a function item or a non-capturing closure.
343 name: &'a CStr,
346 ) -> impl PinInit<File<T>, E> + 'a
349 W: Fn(&T, &mut UserSliceReader) -> Result + Send + Sync,
354 self.create_file(name, data, file_ops)
360 // Unless you also extract the `entry` later and schedule it for `Drop` at the appropriate
362 fn scoped_dir<'data>(&self, name: &CStr) -> ScopedDir<'data, 'static> {
367 Some(entry) => entry.clone(),
370 entry: ManuallyDrop::new(Entry::dynamic_dir(name, Some(parent_entry))),
389 name: &'a CStr,
391 ) -> impl PinInit<Scope<T>, E> + 'a
396 let scoped = self.scoped_dir(name);
404 /// Handle to a DebugFS scope, which ensures that attached `data` will outlive the DebugFS entry
414 // This order is load-bearing for drops - `_entry` must be dropped before `data`.
416 _entry: Entry<'static>,
435 fn new<E: 'b, F>(data: impl PinInit<T, E> + 'b, init: F) -> impl PinInit<Self, E> + 'b
441 data <- data,
454 fn entry_mut(self: Pin<&mut Self>) -> &mut Entry<'static> {
459 fn new<E: 'b, F>(data: impl PinInit<T, E> + 'b, init: F) -> impl PinInit<Self, E> + 'b
461 F: for<'a> FnOnce(&'a T) -> Entry<'static> + 'b,
465 _entry: Entry::empty(),
466 data <- data,
488 name: &'a CStr,
490 ) -> impl PinInit<Self, E> + 'a
495 let scoped = ScopedDir::new(name);
504 fn deref(&self) -> &T {
511 fn deref(&self) -> &T {
523 entry: ManuallyDrop<Entry<'dir>>,
524 _phantom: PhantomData<fn(&'data ()) -> &'dir ()>,
531 pub fn dir<'dir2>(&'dir2 self, name: &CStr) -> ScopedDir<'data, 'dir2> {
533 let _ = name;
536 entry: ManuallyDrop::new(Entry::dir(name, Some(&*self.entry))),
541 fn create_file<T: Sync>(&self, name: &CStr, data: &'data T, vtable: &'static FileOps<T>) {
543 core::mem::forget(Entry::file(name, &self.entry, data, vtable));
546 /// Creates a read-only file in this directory.
553 pub fn read_only_file<T: Writer + Send + Sync + 'static>(&self, name: &CStr, data: &'data T) {
554 self.create_file(name, data, &T::FILE_OPS)
557 /// Creates a read-only binary file in this directory.
565 name: &CStr,
568 self.create_file(name, data, &T::FILE_OPS)
571 /// Creates a read-only file in this directory, with contents from a callback.
576 /// `f` must be a function item or a non-capturing closure.
582 pub fn read_callback_file<T, F>(&self, name: &CStr, data: &'data T, _f: &'static F)
585 F: Fn(&T, &mut fmt::Formatter<'_>) -> fmt::Result + Send + Sync,
588 self.create_file(name, data, vtable)
591 /// Creates a read-write file in this directory.
601 name: &CStr,
605 self.create_file(name, data, vtable)
608 /// Creates a read-write binary file in this directory.
617 name: &CStr,
621 self.create_file(name, data, vtable)
624 /// Creates a read-write file in this directory, with logic from callbacks.
628 /// `f` and `w` must be function items or non-capturing closures.
636 name: &CStr,
642 F: Fn(&T, &mut fmt::Formatter<'_>) -> fmt::Result + Send + Sync,
643 W: Fn(&T, &mut UserSliceReader) -> Result + Send + Sync,
648 self.create_file(name, data, vtable)
651 /// Creates a write-only file in this directory.
658 pub fn write_only_file<T: Reader + Send + Sync + 'static>(&self, name: &CStr, data: &'data T) {
660 self.create_file(name, data, vtable)
663 /// Creates a write-only binary file in this directory.
671 name: &CStr,
674 self.create_file(name, data, &T::FILE_OPS)
677 /// Creates a write-only file in this directory, with write logic from a callback.
681 /// `w` must be a function item or a non-capturing closure.
687 pub fn write_only_callback_file<T, W>(&self, name: &CStr, data: &'data T, _w: &'static W)
690 W: Fn(&T, &mut UserSliceReader) -> Result + Send + Sync,
695 self.create_file(name, data, vtable)
698 fn empty() -> Self {
701 entry: ManuallyDrop::new(Entry::empty()),
706 fn into_entry(self) -> Entry<'dir> {
707 ManuallyDrop::into_inner(self.entry)
715 // parent will never be released by default, and needs to have its entry extracted and used
717 fn new(name: &CStr) -> ScopedDir<'data, 'static> {
720 entry: ManuallyDrop::new(Entry::dir(name, None)),