Skip to content

Commit

Permalink
Merge pull request #821 from stlankes/feature_fs
Browse files Browse the repository at this point in the history
add option to disable filesystem support
  • Loading branch information
mkroening authored Aug 7, 2023
2 parents 362b282 + 2fc2c4b commit 6d07976
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -57,6 +57,7 @@ smp = ["include-transformed"]
fsgsbase = []
trace = []
rtl8139 = ["tcp", "pci"]
fs = ["pci"]
tcp = [
"smoltcp",
]
Expand Down
7 changes: 7 additions & 0 deletions src/drivers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! 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;
#[cfg(feature = "tcp")]
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.
Expand All @@ -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<VirtioError> for DriverError {
fn from(err: VirtioError) -> Self {
DriverError::InitVirtioDevFail(err)
Expand All @@ -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:?}")
}
Expand Down
14 changes: 13 additions & 1 deletion src/drivers/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ 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,
};

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.
Expand Down Expand Up @@ -455,6 +460,7 @@ pub(crate) fn print_information() {

#[allow(clippy::large_enum_variant)]
pub(crate) enum PciDriver {
#[cfg(feature = "fs")]
VirtioFs(InterruptTicketMutex<VirtioFsDriver>),
#[cfg(all(not(feature = "rtl8139"), feature = "tcp"))]
VirtioNet(InterruptTicketMutex<VirtioNetDriver>),
Expand All @@ -465,6 +471,7 @@ pub(crate) enum PciDriver {
impl PciDriver {
#[cfg(all(not(feature = "rtl8139"), feature = "tcp"))]
fn get_network_driver(&self) -> Option<&InterruptTicketMutex<VirtioNetDriver>> {
#[allow(unreachable_patterns)]
match self {
Self::VirtioNet(drv) => Some(drv),
_ => None,
Expand All @@ -473,12 +480,14 @@ impl PciDriver {

#[cfg(all(feature = "rtl8139", feature = "tcp"))]
fn get_network_driver(&self) -> Option<&InterruptTicketMutex<RTL8139Driver>> {
#[allow(unreachable_patterns)]
match self {
Self::RTL8139Net(drv) => Some(drv),
_ => None,
}
}

#[cfg(feature = "fs")]
fn get_filesystem_driver(&self) -> Option<&InterruptTicketMutex<VirtioFsDriver>> {
match self {
Self::VirtioFs(drv) => Some(drv),
Expand All @@ -504,6 +513,7 @@ pub(crate) fn get_network_driver() -> Option<&'static InterruptTicketMutex<RTL81
unsafe { PCI_DRIVERS.iter().find_map(|drv| drv.get_network_driver()) }
}

#[cfg(feature = "fs")]
pub(crate) fn get_filesystem_driver() -> Option<&'static InterruptTicketMutex<VirtioFsDriver>> {
unsafe {
PCI_DRIVERS
Expand All @@ -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)))
}
Expand Down
6 changes: 3 additions & 3 deletions src/drivers/virtio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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!"),
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/virtio/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1315,6 +1317,7 @@ pub(crate) fn init_device(

Ok(drv)
}
#[cfg(feature = "fs")]
VirtioDriver::FileSystem(_) => Ok(drv),
}
}
Expand All @@ -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),
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/syscalls/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}

Expand Down

0 comments on commit 6d07976

Please sign in to comment.