mirror of
https://github.com/hexagonal-sun/moss-kernel.git
synced 2025-12-23 14:37:57 -05:00
drivers: fs: tmpfs: new
Add tmpfs driver and register with the kernel driver's FS subsystem.
This commit is contained in:
committed by
Ashwin Naren
parent
a867493fa7
commit
264d603044
@@ -1,15 +1,18 @@
|
||||
use alloc::sync::Arc;
|
||||
use dev::DevFsDriver;
|
||||
use fat32::Fat32FsDriver;
|
||||
use tmpfs::TmpFsDriver;
|
||||
|
||||
use super::DM;
|
||||
|
||||
pub mod dev;
|
||||
pub mod fat32;
|
||||
pub mod tmpfs;
|
||||
|
||||
pub fn register_fs_drivers() {
|
||||
let mut dm = DM.lock_save_irq();
|
||||
|
||||
dm.insert_driver(Arc::new(Fat32FsDriver::new()));
|
||||
dm.insert_driver(Arc::new(DevFsDriver::new()));
|
||||
dm.insert_driver(Arc::new(TmpFsDriver::new()));
|
||||
}
|
||||
|
||||
47
src/drivers/fs/tmpfs.rs
Normal file
47
src/drivers/fs/tmpfs.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use crate::{arch::ArchImpl, drivers::Driver, fs::FilesystemDriver, memory::{PageOffsetTranslator, page::PgAllocGetter}};
|
||||
use alloc::{boxed::Box, sync::Arc};
|
||||
use async_trait::async_trait;
|
||||
use libkernel::{
|
||||
error::{KernelError, Result},
|
||||
fs::{BlockDevice, Filesystem},
|
||||
};
|
||||
use log::warn;
|
||||
|
||||
pub struct TmpFsDriver {}
|
||||
|
||||
impl TmpFsDriver {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Driver for TmpFsDriver {
|
||||
fn name(&self) -> &'static str {
|
||||
"tmpfs"
|
||||
}
|
||||
|
||||
fn as_filesystem_driver(self: Arc<Self>) -> Option<Arc<dyn FilesystemDriver>> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl FilesystemDriver for TmpFsDriver {
|
||||
async fn construct(
|
||||
&self,
|
||||
fs_id: u64,
|
||||
device: Option<Box<dyn BlockDevice>>,
|
||||
) -> Result<Arc<dyn Filesystem>> {
|
||||
match device {
|
||||
Some(_) => {
|
||||
warn!("Unexpected block device for tmpfs");
|
||||
Err(KernelError::InvalidValue)
|
||||
}
|
||||
None => Ok(libkernel::fs::filesystems::tmpfs::TmpFs::<
|
||||
ArchImpl,
|
||||
PgAllocGetter,
|
||||
PageOffsetTranslator,
|
||||
>::new(fs_id)),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user