Add pseudo `Mount`
This commit is contained in:
parent
184e803869
commit
fe633972f3
|
|
@ -64,6 +64,8 @@ bitflags! {
|
|||
const NODIRATIME = 1 << 11;
|
||||
/// Update atime relative to mtime/ctime.
|
||||
const RELATIME = 1 << 21;
|
||||
/// Kernel (pseudo) mount.
|
||||
const KERNMOUNT = 1 << 22;
|
||||
/// Always perform atime updates.
|
||||
const STRICTATIME = 1 << 24;
|
||||
}
|
||||
|
|
@ -188,11 +190,19 @@ impl Mount {
|
|||
Self::new(fs, PerMountFlags::default(), None, mnt_ns)
|
||||
}
|
||||
|
||||
/// Creates a pseudo mount node with an associated FS.
|
||||
///
|
||||
/// This pseudo mount is not mounted on other mount nodes, has no parent, and does not
|
||||
/// belong to any mount namespace.
|
||||
pub(in crate::fs) fn new_pseudo(fs: Arc<dyn FileSystem>) -> Arc<Self> {
|
||||
Self::new(fs, PerMountFlags::KERNMOUNT, None, Weak::new())
|
||||
}
|
||||
|
||||
/// The internal constructor.
|
||||
///
|
||||
/// Root mount node has no mountpoint which other mount nodes must have mountpoint.
|
||||
/// A root mount node has no mountpoint, while other mount nodes must have one.
|
||||
///
|
||||
/// Here, a Mount is instantiated without an initial mountpoint,
|
||||
/// Here, a `Mount` is instantiated without an initial mountpoint,
|
||||
/// avoiding fixed mountpoint limitations. This allows the root mount node to
|
||||
/// exist without a mountpoint, ensuring uniformity and security, while all other
|
||||
/// mount nodes must be explicitly assigned a mountpoint to maintain structural integrity.
|
||||
|
|
@ -203,6 +213,7 @@ impl Mount {
|
|||
mnt_ns: Weak<MountNamespace>,
|
||||
) -> Arc<Self> {
|
||||
let id = ID_ALLOCATOR.get().unwrap().lock().alloc().unwrap();
|
||||
|
||||
Arc::new_cyclic(|weak_self| Self {
|
||||
id,
|
||||
root_dentry: Dentry::new_root(fs.root_inode()),
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use spin::Once;
|
|||
use super::utils::{Extension, InodeIo, StatusFlags};
|
||||
use crate::{
|
||||
fs::{
|
||||
path::Mount,
|
||||
registry::{FsProperties, FsType},
|
||||
utils::{
|
||||
FileSystem, FsEventSubscriberStats, FsFlags, Inode, InodeMode, InodeType, Metadata,
|
||||
|
|
@ -105,6 +106,13 @@ impl PipeFs {
|
|||
|
||||
PseudoFs::singleton(&PIPEFS, "pipefs", PIPEFS_MAGIC)
|
||||
}
|
||||
|
||||
/// Returns the pseudo mount node of the pipe file system.
|
||||
fn mount_node() -> &'static Arc<Mount> {
|
||||
static PIPEFS_MOUNT: Once<Arc<Mount>> = Once::new();
|
||||
|
||||
PIPEFS_MOUNT.call_once(|| Mount::new_pseudo(Self::singleton().clone()))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SockFs {
|
||||
|
|
@ -118,6 +126,13 @@ impl SockFs {
|
|||
|
||||
PseudoFs::singleton(&SOCKFS, "sockfs", SOCKFS_MAGIC)
|
||||
}
|
||||
|
||||
/// Returns the pseudo mount node of the socket file system.
|
||||
pub fn mount_node() -> &'static Arc<Mount> {
|
||||
static SOCKFS_MOUNT: Once<Arc<Mount>> = Once::new();
|
||||
|
||||
SOCKFS_MOUNT.call_once(|| Mount::new_pseudo(Self::singleton().clone()))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AnonInodeFs {
|
||||
|
|
@ -132,6 +147,13 @@ impl AnonInodeFs {
|
|||
PseudoFs::singleton(&ANON_INODEFS, "anon_inodefs", ANON_INODEFS_MAGIC)
|
||||
}
|
||||
|
||||
/// Returns the pseudo mount node of the anonymous inode file system.
|
||||
pub fn mount_node() -> &'static Arc<Mount> {
|
||||
static ANON_INODEFS_MOUNT: Once<Arc<Mount>> = Once::new();
|
||||
|
||||
ANON_INODEFS_MOUNT.call_once(|| Mount::new_pseudo(Self::singleton().clone()))
|
||||
}
|
||||
|
||||
/// Returns the shared inode of the anonymous inode file system singleton.
|
||||
//
|
||||
// Some members of anon_inodefs (such as epollfd, eventfd, timerfd, etc.) share
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use crate::{
|
|||
file_handle::{FileLike, Mappable},
|
||||
file_table::FdFlags,
|
||||
inode_handle::{do_fallocate_util, do_resize_util, do_seek_util},
|
||||
path::{RESERVED_MOUNT_ID, check_open_util},
|
||||
path::{Mount, RESERVED_MOUNT_ID, check_open_util},
|
||||
tmpfs::TmpFs,
|
||||
utils::{
|
||||
AccessMode, CachePage, CreationFlags, Extension, FallocMode, FileSystem, Inode,
|
||||
|
|
@ -231,9 +231,26 @@ impl Inode for MemfdInode {
|
|||
}
|
||||
|
||||
fn fs(&self) -> Arc<dyn FileSystem> {
|
||||
// Reference: <https://elixir.bootlin.com/linux/v6.16.5/source/mm/shmem.c#L3828-L3850>
|
||||
MemfdTmpFs::singleton().clone()
|
||||
}
|
||||
}
|
||||
|
||||
struct MemfdTmpFs {
|
||||
_private: (),
|
||||
}
|
||||
|
||||
impl MemfdTmpFs {
|
||||
// Reference: <https://elixir.bootlin.com/linux/v6.16.5/source/mm/shmem.c#L3828-L3850>
|
||||
fn singleton() -> &'static Arc<TmpFs> {
|
||||
static MEMFD_TMPFS: Once<Arc<TmpFs>> = Once::new();
|
||||
MEMFD_TMPFS.call_once(TmpFs::new).clone()
|
||||
|
||||
MEMFD_TMPFS.call_once(TmpFs::new)
|
||||
}
|
||||
|
||||
fn mount_node() -> &'static Arc<Mount> {
|
||||
static MEMFD_TMPFS_MOUNT: Once<Arc<Mount>> = Once::new();
|
||||
|
||||
MEMFD_TMPFS_MOUNT.call_once(|| Mount::new_pseudo(Self::singleton().clone()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue