From 4b61e7bc866223e9da942d052682aeb69d9500d8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 22 Feb 2025 16:27:27 +0100 Subject: [PATCH 1/2] graphics/fbbootlogd: Inline TextScreen into FbbootlogScheme --- graphics/fbbootlogd/src/main.rs | 1 - graphics/fbbootlogd/src/scheme.rs | 28 +++++++++++++++------ graphics/fbbootlogd/src/text.rs | 41 ------------------------------- 3 files changed, 20 insertions(+), 50 deletions(-) delete mode 100644 graphics/fbbootlogd/src/text.rs diff --git a/graphics/fbbootlogd/src/main.rs b/graphics/fbbootlogd/src/main.rs index cd4d44ff07..ca1c3863df 100644 --- a/graphics/fbbootlogd/src/main.rs +++ b/graphics/fbbootlogd/src/main.rs @@ -16,7 +16,6 @@ use crate::scheme::FbbootlogScheme; mod display; mod scheme; -mod text; fn main() { redox_daemon::Daemon::new(|daemon| inner(daemon)).expect("failed to create daemon"); diff --git a/graphics/fbbootlogd/src/scheme.rs b/graphics/fbbootlogd/src/scheme.rs index 7e37aa8cb6..1e9f408ef8 100644 --- a/graphics/fbbootlogd/src/scheme.rs +++ b/graphics/fbbootlogd/src/scheme.rs @@ -1,10 +1,9 @@ -use std::collections::BTreeMap; +use std::collections::{BTreeMap, VecDeque}; use redox_scheme::Scheme; use syscall::{Error, EventFlags, Result, EBADF, EINVAL, ENOENT}; use crate::display::Display; -use crate::text::TextScreen; pub struct Handle { pub events: EventFlags, @@ -12,18 +11,17 @@ pub struct Handle { } pub struct FbbootlogScheme { - pub screen: TextScreen, + display: Display, + text_screen: console_draw::TextScreen, next_id: usize, pub handles: BTreeMap, } impl FbbootlogScheme { pub fn new() -> FbbootlogScheme { - let display = Display::open_first_vt().expect("Failed to open display for vt"); - let screen = TextScreen::new(display); - FbbootlogScheme { - screen, + display: Display::open_first_vt().expect("Failed to open display for vt"), + text_screen: console_draw::TextScreen::new(), next_id: 0, handles: BTreeMap::new(), } @@ -94,7 +92,21 @@ impl Scheme for FbbootlogScheme { fn write(&mut self, id: usize, buf: &[u8], _offset: u64, _fcntl_flags: u32) -> Result { let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - self.screen.write(buf) + let mut map = self.display.map.lock().unwrap(); + let damage = self.text_screen.write( + &mut console_draw::DisplayMap { + offscreen: map.inner.ptr_mut(), + width: map.inner.width(), + height: map.inner.height(), + }, + buf, + &mut VecDeque::new(), + ); + drop(map); + + self.display.sync_rects(damage); + + Ok(buf.len()) } fn close(&mut self, id: usize) -> Result { diff --git a/graphics/fbbootlogd/src/text.rs b/graphics/fbbootlogd/src/text.rs deleted file mode 100644 index 15e34e0584..0000000000 --- a/graphics/fbbootlogd/src/text.rs +++ /dev/null @@ -1,41 +0,0 @@ -extern crate ransid; - -use std::collections::VecDeque; - -use syscall::error::*; - -use crate::display::Display; - -pub struct TextScreen { - pub display: Display, - inner: console_draw::TextScreen, -} - -impl TextScreen { - pub fn new(display: Display) -> TextScreen { - TextScreen { - display, - inner: console_draw::TextScreen::new(), - } - } -} - -impl TextScreen { - pub fn write(&mut self, buf: &[u8]) -> Result { - let mut map = self.display.map.lock().unwrap(); - let damage = self.inner.write( - &mut console_draw::DisplayMap { - offscreen: map.inner.ptr_mut(), - width: map.inner.width(), - height: map.inner.height(), - }, - buf, - &mut VecDeque::new(), - ); - drop(map); - - self.display.sync_rects(damage); - - Ok(buf.len()) - } -} From 31450e577047d93fee6eca6c7160b00fccf1b09d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 22 Feb 2025 16:32:56 +0100 Subject: [PATCH 2/2] graphics/fbbootlogd: Get rid of fevent and tracking handles Fbbootlogd doesn't do non-blocking operations, so fevent isn't needed. And the kernel shouldn't pass closed handles to us and even if it does due to a bug, it is harmless to silently ignore the fact that the handle was closed. --- graphics/fbbootlogd/src/scheme.rs | 56 +++++-------------------------- 1 file changed, 9 insertions(+), 47 deletions(-) diff --git a/graphics/fbbootlogd/src/scheme.rs b/graphics/fbbootlogd/src/scheme.rs index 1e9f408ef8..3447a91466 100644 --- a/graphics/fbbootlogd/src/scheme.rs +++ b/graphics/fbbootlogd/src/scheme.rs @@ -1,20 +1,13 @@ -use std::collections::{BTreeMap, VecDeque}; +use std::collections::VecDeque; use redox_scheme::Scheme; -use syscall::{Error, EventFlags, Result, EBADF, EINVAL, ENOENT}; +use syscall::{Error, Result, EINVAL, ENOENT}; use crate::display::Display; -pub struct Handle { - pub events: EventFlags, - pub notified_read: bool, -} - pub struct FbbootlogScheme { display: Display, text_screen: console_draw::TextScreen, - next_id: usize, - pub handles: BTreeMap, } impl FbbootlogScheme { @@ -22,8 +15,6 @@ impl FbbootlogScheme { FbbootlogScheme { display: Display::open_first_vt().expect("Failed to open display for vt"), text_screen: console_draw::TextScreen::new(), - next_id: 0, - handles: BTreeMap::new(), } } } @@ -34,32 +25,10 @@ impl Scheme for FbbootlogScheme { return Err(Error::new(ENOENT)); } - let id = self.next_id; - self.next_id += 1; - - self.handles.insert( - id, - Handle { - events: EventFlags::empty(), - notified_read: false, - }, - ); - - Ok(id) + Ok(0) } - fn fevent(&mut self, id: usize, flags: syscall::EventFlags) -> Result { - let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?; - - handle.notified_read = false; - - handle.events = flags; - Ok(syscall::EventFlags::empty()) - } - - fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result { - let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - + fn fpath(&mut self, _id: usize, buf: &mut [u8]) -> Result { let path = b"fbbootlog:"; let mut i = 0; @@ -71,27 +40,21 @@ impl Scheme for FbbootlogScheme { Ok(i) } - fn fsync(&mut self, id: usize) -> Result { - let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - - return Ok(0); + fn fsync(&mut self, _id: usize) -> Result { + Ok(0) } fn read( &mut self, - id: usize, + _id: usize, _buf: &mut [u8], _offset: u64, _fcntl_flags: u32, ) -> Result { - let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - Err(Error::new(EINVAL)) } - fn write(&mut self, id: usize, buf: &[u8], _offset: u64, _fcntl_flags: u32) -> Result { - let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - + fn write(&mut self, _id: usize, buf: &[u8], _offset: u64, _fcntl_flags: u32) -> Result { let mut map = self.display.map.lock().unwrap(); let damage = self.text_screen.write( &mut console_draw::DisplayMap { @@ -109,8 +72,7 @@ impl Scheme for FbbootlogScheme { Ok(buf.len()) } - fn close(&mut self, id: usize) -> Result { - self.handles.remove(&id).ok_or(Error::new(EBADF))?; + fn close(&mut self, _id: usize) -> Result { Ok(0) } }