mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-09 21:36:48 +00:00
Prepare "/dev/shm" for POSIX shared memory
This commit is contained in:
parent
6e4a4c58d0
commit
00b194812d
@ -5,6 +5,7 @@ use cfg_if::cfg_if;
|
|||||||
mod null;
|
mod null;
|
||||||
mod pty;
|
mod pty;
|
||||||
mod random;
|
mod random;
|
||||||
|
mod shm;
|
||||||
pub mod tty;
|
pub mod tty;
|
||||||
mod urandom;
|
mod urandom;
|
||||||
mod zero;
|
mod zero;
|
||||||
@ -54,6 +55,7 @@ pub fn init() -> Result<()> {
|
|||||||
let urandom = Arc::new(urandom::Urandom);
|
let urandom = Arc::new(urandom::Urandom);
|
||||||
add_node(urandom, "urandom")?;
|
add_node(urandom, "urandom")?;
|
||||||
pty::init()?;
|
pty::init()?;
|
||||||
|
shm::init()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
kernel/src/device/shm.rs
Normal file
25
kernel/src/device/shm.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
fs::{
|
||||||
|
fs_resolver::{FsPath, FsResolver},
|
||||||
|
ramfs::RamFS,
|
||||||
|
utils::{InodeMode, InodeType},
|
||||||
|
},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Initializes "/dev/shm" for POSIX shared memory usage.
|
||||||
|
pub fn init() -> Result<()> {
|
||||||
|
let dev_dentry = {
|
||||||
|
let fs = FsResolver::new();
|
||||||
|
fs.lookup(&FsPath::try_from("/dev")?)?
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create the "shm" directory under "/dev" and mount a ramfs on it.
|
||||||
|
let shm_dentry =
|
||||||
|
dev_dentry.new_fs_child("shm", InodeType::Dir, InodeMode::from_bits_truncate(0o1777))?;
|
||||||
|
shm_dentry.mount(RamFS::new())?;
|
||||||
|
log::debug!("Mount RamFS at \"/dev/shm\"");
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user