58 lines
1.6 KiB
Rust
58 lines
1.6 KiB
Rust
//! Filesystem implementations
|
|
|
|
use core::ptr::NonNull;
|
|
|
|
use kernel_util::util::OneTimeInit;
|
|
use memfs::block::{self, BlockAllocator};
|
|
use vfs::VnodeRef;
|
|
use yggdrasil_abi::{error::Error, io::MountOptions};
|
|
|
|
use crate::mem::{
|
|
self,
|
|
phys::{self, PageUsage},
|
|
ConvertAddress,
|
|
};
|
|
|
|
pub mod devfs;
|
|
|
|
/// Describes in-memory filesystem image used as initial root
|
|
pub struct Initrd {
|
|
/// Page-aligned start address of the initrd
|
|
pub phys_page_start: usize,
|
|
/// Page-aligned length
|
|
pub phys_page_len: usize,
|
|
/// Safe reference to the initrd data slice
|
|
pub data: &'static [u8],
|
|
}
|
|
|
|
/// Holds reference to the data of initrd as well as its page-aligned physical memory region
|
|
pub static INITRD_DATA: OneTimeInit<Initrd> = OneTimeInit::new();
|
|
|
|
/// Implementation of [memfs::block::BlockAllocator] for the kernel
|
|
pub struct FileBlockAllocator;
|
|
|
|
unsafe impl BlockAllocator for FileBlockAllocator {
|
|
fn alloc() -> Result<NonNull<u8>, Error> {
|
|
// TODO make this a static assertion
|
|
assert_eq!(block::SIZE, 4096);
|
|
let page = phys::alloc_page(PageUsage::Used)?;
|
|
Ok(unsafe { NonNull::new_unchecked(page.virtualize() as *mut _) })
|
|
}
|
|
|
|
unsafe fn dealloc(block: NonNull<u8>) {
|
|
let page = block.as_ptr() as usize;
|
|
assert!(page > mem::KERNEL_VIRT_OFFSET);
|
|
phys::free_page(page.physicalize());
|
|
}
|
|
}
|
|
|
|
/// Constructs an instance of a filesystem for given set of [MountOptions]
|
|
pub fn create_filesystem(options: &MountOptions) -> Result<VnodeRef, Error> {
|
|
let fs_name = options.filesystem.unwrap();
|
|
|
|
match fs_name {
|
|
"devfs" => Ok(devfs::root().clone()),
|
|
_ => todo!(),
|
|
}
|
|
}
|