forked from raspberrypi/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
394 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
//! File systems. | ||
//! | ||
//! C headers: [`include/linux/fs.h`](../../../../include/linux/fs.h) | ||
use crate::{bindings, AlwaysRefCounted}; | ||
use core::{cell::UnsafeCell, ptr}; | ||
|
||
/// Wraps the kernel's `struct inode`. | ||
/// | ||
/// # Invariants | ||
/// | ||
/// Instances of this type are always ref-counted, that is, a call to `ihold` ensures that the | ||
/// allocation remains valid at least until the matching call to `iput`. | ||
#[repr(transparent)] | ||
pub struct INode(pub(crate) UnsafeCell<bindings::inode>); | ||
|
||
// SAFETY: The type invariants guarantee that `INode` is always ref-counted. | ||
unsafe impl AlwaysRefCounted for INode { | ||
fn inc_ref(&self) { | ||
// SAFETY: The existence of a shared reference means that the refcount is nonzero. | ||
unsafe { bindings::ihold(self.0.get()) }; | ||
} | ||
|
||
unsafe fn dec_ref(obj: ptr::NonNull<Self>) { | ||
// SAFETY: The safety requirements guarantee that the refcount is nonzero. | ||
unsafe { bindings::iput(obj.cast().as_ptr()) } | ||
} | ||
} | ||
|
||
/// Wraps the kernel's `struct dentry`. | ||
/// | ||
/// # Invariants | ||
/// | ||
/// Instances of this type are always ref-counted, that is, a call to `dget` ensures that the | ||
/// allocation remains valid at least until the matching call to `dput`. | ||
#[repr(transparent)] | ||
pub struct DEntry(pub(crate) UnsafeCell<bindings::dentry>); | ||
|
||
// SAFETY: The type invariants guarantee that `DEntry` is always ref-counted. | ||
unsafe impl AlwaysRefCounted for DEntry { | ||
fn inc_ref(&self) { | ||
// SAFETY: The existence of a shared reference means that the refcount is nonzero. | ||
unsafe { bindings::dget(self.0.get()) }; | ||
} | ||
|
||
unsafe fn dec_ref(obj: ptr::NonNull<Self>) { | ||
// SAFETY: The safety requirements guarantee that the refcount is nonzero. | ||
unsafe { bindings::dput(obj.cast().as_ptr()) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.