drivers: fs: tmpfs: new

Add tmpfs driver and register with the kernel driver's FS subsystem.
This commit is contained in:
Matthew Leach
2025-12-17 22:09:03 +00:00
committed by Ashwin Naren
parent a867493fa7
commit 264d603044
2 changed files with 50 additions and 0 deletions

View File

@@ -1,15 +1,18 @@
use alloc::sync::Arc; use alloc::sync::Arc;
use dev::DevFsDriver; use dev::DevFsDriver;
use fat32::Fat32FsDriver; use fat32::Fat32FsDriver;
use tmpfs::TmpFsDriver;
use super::DM; use super::DM;
pub mod dev; pub mod dev;
pub mod fat32; pub mod fat32;
pub mod tmpfs;
pub fn register_fs_drivers() { pub fn register_fs_drivers() {
let mut dm = DM.lock_save_irq(); let mut dm = DM.lock_save_irq();
dm.insert_driver(Arc::new(Fat32FsDriver::new())); dm.insert_driver(Arc::new(Fat32FsDriver::new()));
dm.insert_driver(Arc::new(DevFsDriver::new())); dm.insert_driver(Arc::new(DevFsDriver::new()));
dm.insert_driver(Arc::new(TmpFsDriver::new()));
} }

47
src/drivers/fs/tmpfs.rs Normal file
View 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)),
}
}
}