diff --git a/Cargo.toml b/Cargo.toml index 8c019f29ad..b212466a67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ name = "measure_startup_time" harness = false [features] -default = ["pci", "pci-ids", "acpi", "fsgsbase", "smp", "tcp", "dhcpv4"] +default = ["pci", "pci-ids", "acpi", "fsgsbase", "smp", "tcp", "dhcpv4", "fs"] vga = [] newlib = [] pci = [] @@ -57,6 +57,7 @@ smp = ["include-transformed"] fsgsbase = [] trace = [] rtl8139 = ["tcp", "pci"] +fs = ["pci"] tcp = [ "smoltcp", ] diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs index 06aae0af26..04f06bf4d3 100644 --- a/src/drivers/mod.rs +++ b/src/drivers/mod.rs @@ -1,5 +1,6 @@ //! A module containing hermit-rs driver, hermit-rs driver trait and driver specific errors. +#[cfg(feature = "fs")] pub mod fs; #[cfg(not(feature = "pci"))] pub mod mmio; @@ -7,6 +8,7 @@ pub mod mmio; pub mod net; #[cfg(feature = "pci")] pub mod pci; +#[cfg(any(all(feature = "tcp", not(feature = "rtl8139")), feature = "fs"))] pub mod virtio; /// A common error module for drivers. @@ -17,15 +19,18 @@ pub mod error { #[cfg(feature = "rtl8139")] use crate::drivers::net::rtl8139::RTL8139Error; + #[cfg(any(all(feature = "tcp", not(feature = "rtl8139")), feature = "fs"))] use crate::drivers::virtio::error::VirtioError; #[derive(Debug)] pub enum DriverError { + #[cfg(any(all(feature = "tcp", not(feature = "rtl8139")), feature = "fs"))] InitVirtioDevFail(VirtioError), #[cfg(feature = "rtl8139")] InitRTL8139DevFail(RTL8139Error), } + #[cfg(any(all(feature = "tcp", not(feature = "rtl8139")), feature = "fs"))] impl From for DriverError { fn from(err: VirtioError) -> Self { DriverError::InitVirtioDevFail(err) @@ -40,8 +45,10 @@ pub mod error { } impl fmt::Display for DriverError { + #[allow(unused_variables)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { + #[cfg(any(all(feature = "tcp", not(feature = "rtl8139")), feature = "fs"))] DriverError::InitVirtioDevFail(ref err) => { write!(f, "Virtio driver failed: {err:?}") } diff --git a/src/drivers/pci.rs b/src/drivers/pci.rs index e116f71f14..22f7fb0f33 100644 --- a/src/drivers/pci.rs +++ b/src/drivers/pci.rs @@ -4,7 +4,9 @@ use alloc::vec::Vec; use core::fmt; use bitflags::bitflags; -use hermit_sync::{without_interrupts, InterruptTicketMutex}; +use hermit_sync::without_interrupts; +#[cfg(any(feature = "tcp", feature = "fs"))] +use hermit_sync::InterruptTicketMutex; use pci_types::{ Bar, ConfigRegionAccess, DeviceId, EndpointHeader, InterruptLine, InterruptPin, PciAddress, PciHeader, VendorId, MAX_BARS, @@ -12,12 +14,15 @@ use pci_types::{ use crate::arch::mm::{PhysAddr, VirtAddr}; use crate::arch::pci::PciConfigRegion; +#[cfg(feature = "fs")] use crate::drivers::fs::virtio_fs::VirtioFsDriver; #[cfg(feature = "rtl8139")] use crate::drivers::net::rtl8139::{self, RTL8139Driver}; #[cfg(all(not(feature = "rtl8139"), feature = "tcp"))] use crate::drivers::net::virtio_net::VirtioNetDriver; +#[cfg(any(all(feature = "tcp", not(feature = "rtl8139")), feature = "fs"))] use crate::drivers::virtio::transport::pci as pci_virtio; +#[cfg(any(all(feature = "tcp", not(feature = "rtl8139")), feature = "fs"))] use crate::drivers::virtio::transport::pci::VirtioDriver; /// Converts a given little endian coded u32 to native endian coded. @@ -455,6 +460,7 @@ pub(crate) fn print_information() { #[allow(clippy::large_enum_variant)] pub(crate) enum PciDriver { + #[cfg(feature = "fs")] VirtioFs(InterruptTicketMutex), #[cfg(all(not(feature = "rtl8139"), feature = "tcp"))] VirtioNet(InterruptTicketMutex), @@ -465,6 +471,7 @@ pub(crate) enum PciDriver { impl PciDriver { #[cfg(all(not(feature = "rtl8139"), feature = "tcp"))] fn get_network_driver(&self) -> Option<&InterruptTicketMutex> { + #[allow(unreachable_patterns)] match self { Self::VirtioNet(drv) => Some(drv), _ => None, @@ -473,12 +480,14 @@ impl PciDriver { #[cfg(all(feature = "rtl8139", feature = "tcp"))] fn get_network_driver(&self) -> Option<&InterruptTicketMutex> { + #[allow(unreachable_patterns)] match self { Self::RTL8139Net(drv) => Some(drv), _ => None, } } + #[cfg(feature = "fs")] fn get_filesystem_driver(&self) -> Option<&InterruptTicketMutex> { match self { Self::VirtioFs(drv) => Some(drv), @@ -504,6 +513,7 @@ pub(crate) fn get_network_driver() -> Option<&'static InterruptTicketMutex Option<&'static InterruptTicketMutex> { unsafe { PCI_DRIVERS @@ -526,11 +536,13 @@ pub(crate) fn init_drivers() { adapter.device_id() ); + #[cfg(any(all(feature = "tcp", not(feature = "rtl8139")), feature = "fs"))] match pci_virtio::init_device(adapter) { #[cfg(all(not(feature = "rtl8139"), feature = "tcp"))] Ok(VirtioDriver::Network(drv)) => { register_driver(PciDriver::VirtioNet(InterruptTicketMutex::new(drv))) } + #[cfg(feature = "fs")] Ok(VirtioDriver::FileSystem(drv)) => { register_driver(PciDriver::VirtioFs(InterruptTicketMutex::new(drv))) } diff --git a/src/drivers/virtio/mod.rs b/src/drivers/virtio/mod.rs index d40c7c8b57..9cd0970c3a 100644 --- a/src/drivers/virtio/mod.rs +++ b/src/drivers/virtio/mod.rs @@ -8,7 +8,7 @@ pub mod virtqueue; pub mod error { use core::fmt; - #[cfg(feature = "pci")] + #[cfg(feature = "fs")] pub use crate::drivers::fs::virtio_fs::error::VirtioFsError; #[cfg(all(not(feature = "rtl8139"), feature = "tcp"))] pub use crate::drivers::net::virtio_net::error::VirtioNetError; @@ -23,7 +23,7 @@ pub mod error { DevNotSupported(u16), #[cfg(all(not(feature = "rtl8139"), feature = "tcp"))] NetDriver(VirtioNetError), - #[cfg(feature = "pci")] + #[cfg(feature = "fs")] FsDriver(VirtioFsError), #[cfg(not(feature = "pci"))] Unknown, @@ -56,7 +56,7 @@ pub mod error { VirtioNetError::ProcessOngoing => write!(f, "Virtio network performed an unsuitable operation upon an ongoging transfer."), VirtioNetError::Unknown => write!(f, "Virtio network driver failed due unknown reason!"), }, - #[cfg(feature = "pci")] + #[cfg(feature = "fs")] VirtioError::FsDriver(fs_error) => match fs_error { VirtioFsError::NoDevCfg(id) => write!(f, "Virtio filesystem driver failed, for device {id:x}, due to a missing or malformed device config!"), VirtioFsError::NoComCfg(id) => write!(f, "Virtio filesystem driver failed, for device {id:x}, due to a missing or malformed common config!"), diff --git a/src/drivers/virtio/transport/pci.rs b/src/drivers/virtio/transport/pci.rs index f4b64c6f56..c6f0337578 100644 --- a/src/drivers/virtio/transport/pci.rs +++ b/src/drivers/virtio/transport/pci.rs @@ -15,6 +15,7 @@ use crate::arch::memory_barrier; use crate::arch::mm::PhysAddr; use crate::arch::pci::PciConfigRegion; use crate::drivers::error::DriverError; +#[cfg(feature = "fs")] use crate::drivers::fs::virtio_fs::VirtioFsDriver; #[cfg(all(not(feature = "rtl8139"), feature = "tcp"))] use crate::drivers::net::network_irqhandler; @@ -1272,6 +1273,7 @@ pub(crate) fn init_device( Err(DriverError::InitVirtioDevFail(virtio_error)) } }, + #[cfg(feature = "fs")] DevId::VIRTIO_DEV_ID_FS => { // TODO: check subclass // TODO: proper error handling on driver creation fail @@ -1315,6 +1317,7 @@ pub(crate) fn init_device( Ok(drv) } + #[cfg(feature = "fs")] VirtioDriver::FileSystem(_) => Ok(drv), } } @@ -1325,5 +1328,6 @@ pub(crate) fn init_device( pub(crate) enum VirtioDriver { #[cfg(all(not(feature = "rtl8139"), feature = "tcp"))] Network(VirtioNetDriver), + #[cfg(feature = "fs")] FileSystem(VirtioFsDriver), } diff --git a/src/lib.rs b/src/lib.rs index d5c9734038..db6b1efe8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,6 +73,7 @@ mod env; pub mod errno; mod executor; pub(crate) mod fd; +#[cfg(feature = "fs")] pub(crate) mod fs; mod mm; mod scheduler; @@ -264,6 +265,7 @@ extern "C" fn initd(_arg: usize) { syscalls::init(); fd::init(); + #[cfg(feature = "fs")] fs::init(); // Get the application arguments and environment variables. diff --git a/src/mm/mod.rs b/src/mm/mod.rs index 1a51c6e7cf..0f3c0cdd2b 100644 --- a/src/mm/mod.rs +++ b/src/mm/mod.rs @@ -231,6 +231,7 @@ pub fn print_information() { arch::mm::virtualmem::print_information(); } +#[allow(dead_code)] pub fn allocate(sz: usize, no_execution: bool) -> VirtAddr { let size = sz.align_up(BasePageSize::SIZE as usize); let physical_address = arch::mm::physicalmem::allocate(size).unwrap(); @@ -247,6 +248,7 @@ pub fn allocate(sz: usize, no_execution: bool) -> VirtAddr { virtual_address } +#[allow(dead_code)] pub fn deallocate(virtual_address: VirtAddr, sz: usize) { let size = sz.align_up(BasePageSize::SIZE as usize); diff --git a/src/syscalls/fs.rs b/src/syscalls/fs.rs index 2694bdb838..de588603b1 100644 --- a/src/syscalls/fs.rs +++ b/src/syscalls/fs.rs @@ -161,7 +161,7 @@ impl Filesystem { } /// Create new backing-fs at mountpoint mntpath - #[cfg(feature = "pci")] + #[cfg(feature = "fs")] pub fn mount( &mut self, mntpath: &str, @@ -200,9 +200,9 @@ impl Filesystem { #[derive(Debug)] pub enum FileError { ENOENT, - #[cfg(feature = "pci")] + #[cfg(feature = "fs")] ENOSYS, - #[cfg(feature = "pci")] + #[cfg(feature = "fs")] EIO, }