mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 09:53:24 +00:00
Refine the name about initramfs
The bootloader loads the initramfs, then the kernel unpacks it to rootfs.
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
55267f0d81
commit
7de44a0e0e
@ -3,16 +3,11 @@ use alloc::str;
|
||||
|
||||
use super::file_table::FileDescripter;
|
||||
use super::inode_handle::InodeHandle;
|
||||
use super::ramfs::RamFS;
|
||||
use super::rootfs::root_mount;
|
||||
use super::utils::{
|
||||
AccessMode, CreationFlags, Dentry, InodeMode, InodeType, MountNode, StatusFlags, PATH_MAX,
|
||||
SYMLINKS_MAX,
|
||||
AccessMode, CreationFlags, Dentry, InodeMode, InodeType, StatusFlags, PATH_MAX, SYMLINKS_MAX,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
static ref ROOT_MOUNT: Arc<MountNode> = MountNode::new_root(RamFS::new(true)).unwrap();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FsResolver {
|
||||
root: Arc<Dentry>,
|
||||
@ -31,8 +26,8 @@ impl Clone for FsResolver {
|
||||
impl FsResolver {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
root: ROOT_MOUNT.root_dentry().clone(),
|
||||
cwd: ROOT_MOUNT.root_dentry().clone(),
|
||||
root: root_mount().root_dentry().clone(),
|
||||
cwd: root_mount().root_dentry().clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,9 @@ pub mod epoll;
|
||||
pub mod file_handle;
|
||||
pub mod file_table;
|
||||
pub mod fs_resolver;
|
||||
pub mod initramfs;
|
||||
pub mod inode_handle;
|
||||
pub mod pipe;
|
||||
pub mod procfs;
|
||||
pub mod ramfs;
|
||||
pub mod rootfs;
|
||||
pub mod utils;
|
||||
|
@ -3,18 +3,21 @@ use crate::prelude::*;
|
||||
use super::fs_resolver::{FsPath, FsResolver};
|
||||
use super::procfs::ProcFS;
|
||||
use super::ramfs::RamFS;
|
||||
use super::utils::{InodeMode, InodeType};
|
||||
use super::utils::{InodeMode, InodeType, MountNode};
|
||||
|
||||
use cpio_decoder::{CpioDecoder, FileType};
|
||||
use lending_iterator::LendingIterator;
|
||||
use libflate::gzip::Decoder as GZipDecoder;
|
||||
use spin::Once;
|
||||
|
||||
/// Unpack and prepare the fs from the ramdisk CPIO buffer.
|
||||
pub fn init(gzip_ramdisk_buf: &[u8]) -> Result<()> {
|
||||
println!("[kernel] unzipping ramdisk.cpio.gz ...");
|
||||
/// Unpack and prepare the rootfs from the initramfs CPIO buffer.
|
||||
pub fn init(initramfs_buf: &[u8]) -> Result<()> {
|
||||
init_root_mount()?;
|
||||
|
||||
println!("[kernel] unpacking the initramfs.cpio.gz to rootfs ...");
|
||||
let fs = FsResolver::new();
|
||||
let mut decoder = CpioDecoder::new(
|
||||
GZipDecoder::new(gzip_ramdisk_buf)
|
||||
GZipDecoder::new(initramfs_buf)
|
||||
.map_err(|_| Error::with_message(Errno::EINVAL, "invalid gzip buffer"))?,
|
||||
);
|
||||
|
||||
@ -74,7 +77,23 @@ pub fn init(gzip_ramdisk_buf: &[u8]) -> Result<()> {
|
||||
// Mount DevFS
|
||||
let dev_dentry = fs.lookup(&FsPath::try_from("/dev")?)?;
|
||||
dev_dentry.mount(RamFS::new(false))?;
|
||||
println!("[kernel] initramfs is ready");
|
||||
println!("[kernel] rootfs is ready");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
static ROOT_MOUNT: Once<Arc<MountNode>> = Once::new();
|
||||
|
||||
fn init_root_mount() -> Result<()> {
|
||||
ROOT_MOUNT.try_call_once(|| -> Result<Arc<MountNode>> {
|
||||
let rootfs = RamFS::new(true);
|
||||
let root_mount = MountNode::new_root(rootfs)?;
|
||||
Ok(root_mount)
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn root_mount() -> &'static Arc<MountNode> {
|
||||
ROOT_MOUNT.get().unwrap()
|
||||
}
|
Reference in New Issue
Block a user