diff --git a/dsk/lib/lisp/file.lsp b/dsk/lib/lisp/file.lsp index bac39f98..ac48f286 100644 --- a/dsk/lib/lisp/file.lsp +++ b/dsk/lib/lisp/file.lsp @@ -77,11 +77,11 @@ (def (clock/boot) "Returns the number of seconds since boot" - (binary->number (read-binary "/dev/clk/boot") "float")) + (str->num (read "/dev/clk/boot"))) (def (clock/epoch) "Returns the number of seconds since epoch" - (binary->number (read-binary "/dev/clk/epoch") "float")) + (str->num (read "/dev/clk/epoch"))) # Path diff --git a/src/sys/clk/boot.rs b/src/sys/clk/boot.rs index bb9e1d64..727f342a 100644 --- a/src/sys/clk/boot.rs +++ b/src/sys/clk/boot.rs @@ -2,6 +2,8 @@ use super::timer; use crate::api::fs::{FileIO, IO}; +use alloc::format; + #[derive(Debug, Clone)] pub struct BootTime; @@ -11,16 +13,17 @@ impl BootTime { } pub fn size() -> usize { - core::mem::size_of::() + // Must be at least 20 + 1 + 6 bytes: "." + 32 } } impl FileIO for BootTime { fn read(&mut self, buf: &mut [u8]) -> Result { - let time = boot_time().to_be_bytes(); + let time = format!("{:.6}", boot_time()); let n = time.len(); if buf.len() >= n { - buf[0..n].clone_from_slice(&time); + buf[0..n].clone_from_slice(time.as_bytes()); Ok(n) } else { Err(()) diff --git a/src/sys/clk/epoch.rs b/src/sys/clk/epoch.rs index 5ce264c0..8d437a8a 100644 --- a/src/sys/clk/epoch.rs +++ b/src/sys/clk/epoch.rs @@ -3,6 +3,8 @@ use super::timer; use crate::api::fs::{FileIO, IO}; +use alloc::format; + const DAYS_BEFORE_MONTH: [u64; 13] = [ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 ]; @@ -16,16 +18,17 @@ impl EpochTime { } pub fn size() -> usize { - core::mem::size_of::() + // Must be at least 20 + 1 + 6 bytes: "." + 32 } } impl FileIO for EpochTime { fn read(&mut self, buf: &mut [u8]) -> Result { - let time = epoch_time().to_be_bytes(); + let time = format!("{:.6}", epoch_time()); let n = time.len(); if buf.len() >= n { - buf[0..n].clone_from_slice(&time); + buf[0..n].clone_from_slice(time.as_bytes()); Ok(n) } else { Err(()) diff --git a/src/sys/vga/screen.rs b/src/sys/vga/screen.rs index 023eed09..a28fac97 100644 --- a/src/sys/vga/screen.rs +++ b/src/sys/vga/screen.rs @@ -197,7 +197,8 @@ impl VgaMode { } pub fn size() -> usize { - 16 // Must be larger than 8 bytes to be readable as a block device + // Must be at least 4 + 1 + 4 bytes: "x" + 16 } } diff --git a/src/usr/read.rs b/src/usr/read.rs index 26e20098..db778223 100644 --- a/src/usr/read.rs +++ b/src/usr/read.rs @@ -8,7 +8,6 @@ use crate::{api, usr}; use alloc::borrow::ToOwned; use alloc::format; use alloc::vec::Vec; -use core::convert::TryInto; pub fn main(args: &[&str]) -> Result<(), ExitCode> { if args.len() != 2 { @@ -94,7 +93,6 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> { // file. let n = info.size(); let is_char_device = n == 4; - let is_float_device = n == 8; let is_block_device = n > 8; loop { if console::end_of_text() || console::end_of_transmission() { @@ -115,12 +113,6 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> { _ => {} } } - if is_float_device && bytes.len() == 8 { - let f = f64::from_be_bytes(bytes[0..8].try_into(). - unwrap()); - println!("{:.6}", f); - return Ok(()); - } for b in bytes { print!("{}", b as char); }