From fd8dabd1bc72e80ff342f7e3cb4bd4ddd585f07a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 11 Jul 2024 21:14:42 +0200 Subject: [PATCH] Use the new scheme format in most places The graphics subsystem still uses the old format as orbital manually parses the fpath result. --- README.md | 12 ++++++------ acpid/src/main.rs | 10 +++++----- audio/ihdad/src/main.rs | 4 ++-- audio/sb16d/src/main.rs | 2 +- common/src/dma.rs | 2 +- common/src/lib.rs | 2 +- graphics/bgad/src/main.rs | 2 +- graphics/fbcond/src/display.rs | 2 +- graphics/fbcond/src/main.rs | 2 +- inputd/src/lib.rs | 2 +- inputd/src/main.rs | 4 ++-- net/alxd/src/main.rs | 2 +- net/virtio-netd/src/main.rs | 2 +- pcid/src/cfg_access/mod.rs | 2 +- pcid/src/driver_interface/irq_helpers.rs | 16 ++++++++-------- pcid/src/driver_interface/mod.rs | 2 +- ps2d/src/main.rs | 20 ++++++++++---------- storage/ided/src/main.rs | 4 ++-- storage/lived/src/main.rs | 4 ++-- storage/nvmed/src/nvme/cq_reactor.rs | 2 +- usbhidd/src/main.rs | 2 +- xhcid/src/driver_interface.rs | 12 ++++++------ 22 files changed, 56 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 6eba98ce74..93a21c3cf1 100644 --- a/README.md +++ b/README.md @@ -46,12 +46,12 @@ This section cover the interfaces used by Redox drivers. ### Schemes -- `memory:physical` - allows mapping physical memory frames to driver-accessible virtual memory pages, with various available memory types: - - `memory:physical`: default memory type (currently writeback) - - `memory:physical@wb` writeback cached memory - - `memory:physical@uc`: uncacheable memory - - `memory:physical@wc`: write-combining memory -- `irq:` - allows getting events from interrupts. It is used primarily by listening for its file descriptors using the `event:` scheme. +- `/scheme/memory/physical` - allows mapping physical memory frames to driver-accessible virtual memory pages, with various available memory types: + - `/scheme/memory/physical`: default memory type (currently writeback) + - `/scheme/memory/physical@wb` writeback cached memory + - `/scheme/memory/physical@uc`: uncacheable memory + - `/scheme/memory/physical@wc`: write-combining memory +- `/scheme/irq` - allows getting events from interrupts. It is used primarily by listening for its file descriptors using the `/scheme/event` scheme. ## Contributing diff --git a/acpid/src/main.rs b/acpid/src/main.rs index 93c54f9558..1aebe40a97 100644 --- a/acpid/src/main.rs +++ b/acpid/src/main.rs @@ -81,8 +81,8 @@ fn setup_logging() -> Option<&'static RedoxLogger> { fn daemon(daemon: redox_daemon::Daemon) -> ! { setup_logging(); - let rxsdt_raw_data: Arc<[u8]> = std::fs::read("kernel.acpi:rxsdt") - .expect("acpid: failed to read `kernel.acpi:rxsdt`") + let rxsdt_raw_data: Arc<[u8]> = std::fs::read("/scheme/kernel.acpi/rxsdt") + .expect("acpid: failed to read `/scheme/kernel.acpi/rxsdt`") .into(); let sdt = self::acpi::Sdt::new(rxsdt_raw_data) @@ -116,14 +116,14 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { // TODO: I/O permission bitmap? common::acquire_port_io_rights().expect("acpid: failed to set I/O privilege level to Ring 3"); - let shutdown_pipe = File::open("kernel.acpi:kstop") - .expect("acpid: failed to open `kernel.acpi:kstop`"); + let shutdown_pipe = File::open("/scheme/kernel.acpi/kstop") + .expect("acpid: failed to open `/scheme/kernel.acpi/kstop`"); let mut event_queue = OpenOptions::new() .write(true) .read(true) .create(false) - .open("event:") + .open("/scheme/event") .expect("acpid: failed to open event queue"); let mut scheme_socket = OpenOptions::new() diff --git a/audio/ihdad/src/main.rs b/audio/ihdad/src/main.rs index 78f2ebbe32..755a5bcc4e 100755 --- a/audio/ihdad/src/main.rs +++ b/audio/ihdad/src/main.rs @@ -113,7 +113,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { log::debug!("Legacy IRQ {}", irq); // legacy INTx# interrupt pins. - File::open(format!("irq:{}", irq)).expect("ihdad: failed to open legacy IRQ file") + irq.irq_handle("ihdad") } else { panic!("ihdad: no interrupts supported at all") } @@ -126,7 +126,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. - File::open(format!("irq:{}", irq)).expect("ihdad: failed to open legacy IRQ file") + irq.irq_handle("ihdad") } else { panic!("ihdad: no interrupts supported at all") } diff --git a/audio/sb16d/src/main.rs b/audio/sb16d/src/main.rs index e01125ce4e..002c707974 100644 --- a/audio/sb16d/src/main.rs +++ b/audio/sb16d/src/main.rs @@ -73,7 +73,7 @@ fn main() { //TODO: error on multiple IRQs? let irq_file = match device.irqs.first() { - Some(irq) => Fd::open(&format!("irq:{}", irq), flag::O_RDWR, 0).expect("sb16d: failed to open IRQ file"), + Some(irq) => Fd::open(&format!("/scheme/irq/{}", irq), flag::O_RDWR, 0).expect("sb16d: failed to open IRQ file"), None => panic!("sb16d: no IRQs found"), }; user_data! { diff --git a/common/src/dma.rs b/common/src/dma.rs index 4c723a001b..fef60d04e0 100644 --- a/common/src/dma.rs +++ b/common/src/dma.rs @@ -22,7 +22,7 @@ const DMA_MEMTY: MemoryType = { pub(crate) fn phys_contiguous_fd() -> Result { Fd::open( - &format!("memory:zeroed@{DMA_MEMTY}?phys_contiguous"), + &format!("/scheme/memory/zeroed@{DMA_MEMTY}?phys_contiguous"), flag::O_CLOEXEC, 0, ) diff --git a/common/src/lib.rs b/common/src/lib.rs index b22d93bcda..c96e3e8c4e 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -51,7 +51,7 @@ pub unsafe fn physmap( ) -> Result<*mut ()> { // TODO: arraystring? let path = format!( - "memory:physical@{}", + "/scheme/memory/physical@{}", match ty { MemoryType::Writeback => "wb", MemoryType::Uncacheable => "uc", diff --git a/graphics/bgad/src/main.rs b/graphics/bgad/src/main.rs index c4832e8560..ad3a4fe393 100644 --- a/graphics/bgad/src/main.rs +++ b/graphics/bgad/src/main.rs @@ -35,7 +35,7 @@ fn main() { let mut scheme = BgaScheme { bga, - display: File::open("input:producer").ok(), + display: File::open("/scheme/input/producer").ok(), }; scheme.update_size(); diff --git a/graphics/fbcond/src/display.rs b/graphics/fbcond/src/display.rs index e2d3798046..4a7e005ce2 100644 --- a/graphics/fbcond/src/display.rs +++ b/graphics/fbcond/src/display.rs @@ -56,7 +56,7 @@ impl Display { let input_handle = OpenOptions::new() .read(true) .custom_flags(O_NONBLOCK as i32) - .open(format!("input:consumer/{vt}"))?; + .open(format!("/scheme/input/consumer/{vt}"))?; let fd = input_handle.as_raw_fd(); let written = libredox::call::fpath(fd as usize, &mut buffer) diff --git a/graphics/fbcond/src/main.rs b/graphics/fbcond/src/main.rs index 4db9e1b5fc..7f0df69b69 100644 --- a/graphics/fbcond/src/main.rs +++ b/graphics/fbcond/src/main.rs @@ -41,7 +41,7 @@ fn inner(daemon: redox_daemon::Daemon, vt_ids: &[usize]) -> ! { .create(true) .truncate(true) .custom_flags(O_NONBLOCK as i32) - .open(":fbcon") + .open("/scheme/fbcon") .expect("fbcond: failed to create fbcon scheme"); event_queue .subscribe( diff --git a/inputd/src/lib.rs b/inputd/src/lib.rs index 3112964993..1747e02106 100644 --- a/inputd/src/lib.rs +++ b/inputd/src/lib.rs @@ -25,7 +25,7 @@ pub struct Handle(File); impl Handle { pub fn new>(device_name: S) -> Result { - let path = format!("input:handle/display/{}", device_name.into()); + let path = format!("/scheme/input/handle/display/{}", device_name.into()); Ok(Self(File::open(path)?)) } diff --git a/inputd/src/main.rs b/inputd/src/main.rs index e8b34c9585..27d7f0ad12 100644 --- a/inputd/src/main.rs +++ b/inputd/src/main.rs @@ -73,7 +73,7 @@ impl Vt { pub fn inner(&self) -> &Mutex { self.inner.call_once(|| { - let handle_file = File::open(format!("{}:handle", self.display)).unwrap(); + let handle_file = File::open(format!("/scheme/{}/handle", self.display)).unwrap(); Mutex::new(VtInner { handle_file, mode: VtMode::Default, @@ -531,7 +531,7 @@ pub fn main() { "-A" => { let vt = args.next().unwrap().parse::().unwrap(); - let handle = File::open(format!("input:consumer/{vt}")) + let handle = File::open(format!("/scheme/input/consumer/{vt}")) .expect("inputd: failed to open consumer handle"); let mut display_path = [0; 4096]; diff --git a/net/alxd/src/main.rs b/net/alxd/src/main.rs index 2ffce2e201..e6c54024aa 100644 --- a/net/alxd/src/main.rs +++ b/net/alxd/src/main.rs @@ -40,7 +40,7 @@ fn main() { daemon.ready().expect("alxd: failed to signal readiness"); - let mut irq_file = File::open(format!("irq:{}", irq)).expect("alxd: failed to open IRQ file"); + let mut irq_file = File::open(format!("/scheme/irq/{}", irq)).expect("alxd: failed to open IRQ file"); let address = unsafe { common::physmap(bar, 128*1024, common::Prot::RW, common::MemoryType::Uncacheable).expect("alxd: failed to map address") as usize }; { diff --git a/net/virtio-netd/src/main.rs b/net/virtio-netd/src/main.rs index 76e07b160f..e4ad270df9 100644 --- a/net/virtio-netd/src/main.rs +++ b/net/virtio-netd/src/main.rs @@ -95,7 +95,7 @@ fn deamon(daemon: redox_daemon::Daemon) -> Result<(), Box let device = VirtioNet::new(mac_address, rx_queue, tx_queue); let mut scheme = NetworkScheme::new(device, format!("network.{name}")); - let mut event_queue = File::open("event:")?; + let mut event_queue = File::open("/scheme/event")?; event_queue.write(&syscall::Event { id: scheme.event_handle() as usize, flags: syscall::EVENT_READ, diff --git a/pcid/src/cfg_access/mod.rs b/pcid/src/cfg_access/mod.rs index 894f4f448b..434f106020 100644 --- a/pcid/src/cfg_access/mod.rs +++ b/pcid/src/cfg_access/mod.rs @@ -126,7 +126,7 @@ struct PcieAllocs<'a>(&'a [PcieAlloc]); impl Mcfg { fn with(f: impl FnOnce(PcieAllocs<'_>) -> io::Result) -> io::Result { - let table_dir = fs::read_dir("acpi:tables")?; + let table_dir = fs::read_dir("/scheme/acpi/tables")?; // TODO: validate/print MCFG? diff --git a/pcid/src/driver_interface/irq_helpers.rs b/pcid/src/driver_interface/irq_helpers.rs index 82f444eabe..b900068456 100644 --- a/pcid/src/driver_interface/irq_helpers.rs +++ b/pcid/src/driver_interface/irq_helpers.rs @@ -1,7 +1,7 @@ //! IRQ helpers. //! -//! This module allows easy handling of the `irq:` scheme, and allocating interrupt vectors for use -//! by INTx#, MSI, or MSI-X. +//! This module allows easy handling of the `/scheme/irq` scheme, and allocating interrupt vectors +//! for use by INTx#, MSI, or MSI-X. use std::convert::TryFrom; use std::fs::{self, File}; @@ -14,7 +14,7 @@ use crate::driver_interface::msi::MsiAddrAndData; pub fn read_bsp_apic_id() -> io::Result { let mut buffer = [0u8; 8]; - let mut file = File::open("irq:bsp")?; + let mut file = File::open("/scheme/irq/bsp")?; let bytes_read = file.read(&mut buffer)?; (if bytes_read == 8 { @@ -25,7 +25,7 @@ pub fn read_bsp_apic_id() -> io::Result { ])) } else { panic!( - "`irq:` scheme responded with {} bytes, expected {}", + "`/scheme/irq` scheme responded with {} bytes, expected {}", bytes_read, std::mem::size_of::() ); @@ -41,7 +41,7 @@ pub fn read_bsp_apic_id() -> io::Result { /// capability structs or MSI-X tables. pub fn cpu_ids() -> io::Result> + 'static> { Ok( - fs::read_dir("irq:")?.filter_map(|entry| -> Option> { + fs::read_dir("/scheme/irq")?.filter_map(|entry| -> Option> { match entry { Ok(e) => { let path = e.path(); @@ -88,7 +88,7 @@ pub fn allocate_aligned_interrupt_vectors( return Ok(None); } - let available_irqs = fs::read_dir(format!("irq:cpu-{:02x}", cpu_id))?; + let available_irqs = fs::read_dir(format!("/scheme/irq/cpu-{:02x}", cpu_id))?; let mut available_irq_numbers = available_irqs.filter_map(|entry| -> Option> { let entry = match entry { Ok(e) => e, @@ -113,7 +113,7 @@ pub fn allocate_aligned_interrupt_vectors( } }); - // TODO: fcntl F_SETLK on `irq:/`? + // TODO: fcntl F_SETLK on `/scheme/irq/`? let mut handles = Vec::with_capacity(usize::from(count)); @@ -137,7 +137,7 @@ pub fn allocate_aligned_interrupt_vectors( } // if found, reserve the irq - let irq_handle = match File::create(format!("irq:cpu-{:02x}/{}", cpu_id, irq_number)) { + let irq_handle = match File::create(format!("/scheme/irq/cpu-{:02x}/{}", cpu_id, irq_number)) { Ok(handle) => handle, // return early if the entire range couldn't be allocated diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index ece101d3bb..2900a1e68c 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -26,7 +26,7 @@ pub struct LegacyInterruptLine(#[doc(hidden)] pub u8); impl LegacyInterruptLine { /// Get an IRQ handle for this interrupt line. pub fn irq_handle(self, driver: &str) -> File { - File::open(format!("irq:{}", self.0)) + File::open(format!("/scheme/irq/{}", self.0)) .unwrap_or_else(|err| panic!("{driver}: failed to open IRQ file: {err}")) } } diff --git a/ps2d/src/main.rs b/ps2d/src/main.rs index aa4ec5df2c..64910d95ef 100644 --- a/ps2d/src/main.rs +++ b/ps2d/src/main.rs @@ -45,40 +45,40 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let input = OpenOptions::new() .write(true) - .open("input:producer") - .expect("ps2d: failed to open input:producer"); + .open("/scheme/input/producer") + .expect("ps2d: failed to open /scheme/input/producer"); let mut event_file = OpenOptions::new() .read(true) .write(true) - .open("event:") - .expect("ps2d: failed to open event:"); + .open("/scheme/event") + .expect("ps2d: failed to open /scheme/event"); let mut key_file = OpenOptions::new() .read(true) .write(true) .custom_flags(syscall::O_NONBLOCK as i32) - .open("serio:0") - .expect("ps2d: failed to open serio:0"); + .open("/scheme/serio/0") + .expect("ps2d: failed to open /scheme/serio/0"); event_file.write(&syscall::Event { id: key_file.as_raw_fd() as usize, flags: syscall::EVENT_READ, data: 0 - }).expect("ps2d: failed to event serio:0"); + }).expect("ps2d: failed to event /scheme/serio/0"); let mut mouse_file = OpenOptions::new() .read(true) .write(true) .custom_flags(syscall::O_NONBLOCK as i32) - .open("serio:1") - .expect("ps2d: failed to open serio:1"); + .open("/scheme/serio/1") + .expect("ps2d: failed to open /scheme/serio/1"); event_file.write(&syscall::Event { id: mouse_file.as_raw_fd() as usize, flags: syscall::EVENT_READ, data: 1 - }).expect("ps2d: failed to event irq:12"); + }).expect("ps2d: failed to event /scheme/serio/1"); libredox::call::setrens(0, 0).expect("ps2d: failed to enter null namespace"); diff --git a/storage/ided/src/main.rs b/storage/ided/src/main.rs index c4723fad54..c69ac46d18 100644 --- a/storage/ided/src/main.rs +++ b/storage/ided/src/main.rs @@ -238,14 +238,14 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { .expect("ided: failed to create disk scheme"); let primary_irq_fd = libredox::call::open( - &format!("irq:{}", primary_irq), + &format!("/scheme/irq/{}", primary_irq), flag::O_RDWR | flag::O_NONBLOCK, 0, ).expect("ided: failed to open irq file"); let mut primary_irq_file = unsafe { File::from_raw_fd(primary_irq_fd as RawFd) }; let secondary_irq_fd = libredox::call::open( - &format!("irq:{}", secondary_irq), + &format!("/scheme/irq/{}", secondary_irq), flag::O_RDWR | flag::O_NONBLOCK, 0, ).expect("ided: failed to open irq file"); diff --git a/storage/lived/src/main.rs b/storage/lived/src/main.rs index ce6dbd95ab..038b53388d 100644 --- a/storage/lived/src/main.rs +++ b/storage/lived/src/main.rs @@ -46,7 +46,7 @@ impl DiskScheme { let mut size = 0; // TODO: handle error - for line in std::fs::read_to_string("sys:env").context("failed to read env")?.lines() { + for line in std::fs::read_to_string("/scheme/sys/env").context("failed to read env")?.lines() { let mut parts = line.splitn(2, '='); let name = parts.next().unwrap_or(""); let value = parts.next().unwrap_or(""); @@ -69,7 +69,7 @@ impl DiskScheme { let size = end - start; let the_data = unsafe { - let file = File::open("memory:physical")?; + let file = File::open("/scheme/memory/physical")?; let base = libredox::call::mmap(MmapArgs { fd: file.as_raw_fd() as usize, addr: core::ptr::null_mut(), diff --git a/storage/nvmed/src/nvme/cq_reactor.rs b/storage/nvmed/src/nvme/cq_reactor.rs index a41f576f64..cf65635de7 100644 --- a/storage/nvmed/src/nvme/cq_reactor.rs +++ b/storage/nvmed/src/nvme/cq_reactor.rs @@ -66,7 +66,7 @@ struct CqReactor { impl CqReactor { fn create_event_queue(int_sources: &mut InterruptSources) -> Result { use libredox::flag::*; - let fd = libredox::call::open("event:", O_CLOEXEC | O_RDWR, 0)?; + let fd = libredox::call::open("/scheme/event", O_CLOEXEC | O_RDWR, 0)?; let mut file = unsafe { File::from_raw_fd(fd as RawFd) }; for (num, irq_handle) in int_sources.iter_mut() { diff --git a/usbhidd/src/main.rs b/usbhidd/src/main.rs index 5e338cfcbe..0551cd0953 100644 --- a/usbhidd/src/main.rs +++ b/usbhidd/src/main.rs @@ -313,7 +313,7 @@ fn main() { let report_id = 0; let mut display = - File::open("input:producer").expect("Failed to open orbital input socket"); + File::open("/scheme/input/producer").expect("Failed to open orbital input socket"); let mut endpoint_opt = match endpoint_num_opt { Some(endpoint_num) => match handle.open_endpoint(endpoint_num as u8) { Ok(ok) => Some(ok), diff --git a/xhcid/src/driver_interface.rs b/xhcid/src/driver_interface.rs index c850f252d6..a1eedb7381 100644 --- a/xhcid/src/driver_interface.rs +++ b/xhcid/src/driver_interface.rs @@ -414,7 +414,7 @@ impl XhciClientHandle { } pub fn get_standard_descs(&self) -> result::Result { - let path = format!("{}:port{}/descriptors", self.scheme, self.port); + let path = format!("/scheme/{}/port{}/descriptors", self.scheme, self.port); let json = std::fs::read(path)?; Ok(serde_json::from_slice(&json)?) } @@ -422,7 +422,7 @@ impl XhciClientHandle { &self, req: &ConfigureEndpointsReq, ) -> result::Result<(), XhciClientHandleError> { - let path = format!("{}:port{}/configure", self.scheme, self.port); + let path = format!("/scheme/{}/port{}/configure", self.scheme, self.port); let json = serde_json::to_vec(req)?; let mut file = OpenOptions::new().read(false).write(true).open(path)?; let json_bytes_written = file.write(&json)?; @@ -434,16 +434,16 @@ impl XhciClientHandle { Ok(()) } pub fn port_state(&self) -> result::Result { - let path = format!("{}:port{}/state", self.scheme, self.port); + let path = format!("/scheme/{}/port{}/state", self.scheme, self.port); let string = std::fs::read_to_string(path)?; Ok(string.parse()?) } pub fn open_endpoint_ctl(&self, num: u8) -> result::Result { - let path = format!("{}:port{}/endpoints/{}/ctl", self.scheme, self.port, num); + let path = format!("/scheme/{}/port{}/endpoints/{}/ctl", self.scheme, self.port, num); Ok(File::open(path)?) } pub fn open_endpoint_data(&self, num: u8) -> result::Result { - let path = format!("{}:port{}/endpoints/{}/data", self.scheme, self.port, num); + let path = format!("/scheme/{}/port{}/endpoints/{}/data", self.scheme, self.port, num); Ok(File::open(path)?) } pub fn open_endpoint(&self, num: u8) -> result::Result { @@ -476,7 +476,7 @@ impl XhciClientHandle { }; let json = serde_json::to_vec(&req)?; - let path = format!("{}:port{}/request", self.scheme, self.port); + let path = format!("/scheme/{}/port{}/request", self.scheme, self.port); let mut file = File::open(path)?; let json_bytes_written = file.write(&json)?;