From 126d5b2e55dca93e024f5654fed6fae37a012369 Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 17 Aug 2026 19:56:24 +0200 Subject: Terminal-app design (ADR 0005) + disk-write controller - ADR 0005: persistent home terminal (full-screen, chrome-less, bottom-pinned), F1 terminal windows, per-instance vt/tty/shell, queue-based input for all terminals, and the disk controller - Glossary: add the Terminal term; update Task/App for the new model - Add a re-entrant disk lock (DiskGuard over the preemption-depth counter) and wrap all fs/fat mutating operations per-call --- rsnix/src/fs.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'rsnix/src/fs.rs') diff --git a/rsnix/src/fs.rs b/rsnix/src/fs.rs index 24d8fcd..3585c00 100644 --- a/rsnix/src/fs.rs +++ b/rsnix/src/fs.rs @@ -203,6 +203,7 @@ pub fn init() -> (usize, usize) { /// its backing info), and tombstone nodes whose volume was unmounted. /// Returns (added, removed) node ops. pub fn rescan_disks() -> (usize, usize) { + let _lock = crate::fat::DiskGuard::acquire(); let mut added = 0usize; let mut removed = 0usize; let disk_dir = match lookup(0, "disk") { @@ -428,6 +429,7 @@ pub fn read(h: usize, buf: &mut [u8], pos: u64) -> Result { } pub fn write(h: usize, buf: &[u8], pos: u64) -> Result { + let _lock = crate::fat::DiskGuard::acquire(); match &mut nodes()[h].data { NodeData::Regular(v) => { let p = pos as usize; @@ -533,7 +535,10 @@ pub fn write_crash_log(lines: &[&str]) { let mut tb = [0u8; 48]; let tn = { let mut w = crate::strbuf::FmtBuf::new(&mut tb); - let _ = core::fmt::write(&mut w, core::format_args!("crashlog: vol {} ({})\r\n", vol, label)); + let _ = core::fmt::write( + &mut w, + core::format_args!("crashlog: vol {} ({})\r\n", vol, label), + ); w.len() }; crate::serial::write_raw(core::str::from_utf8(&tb[..tn]).unwrap_or("?")); @@ -555,7 +560,9 @@ pub fn write_crash_log(lines: &[&str]) { } /// Truncate/resize a regular file. -pub fn set_len(h: usize, len: u64) -> Result<(), ()> { match &mut nodes()[h].data { +pub fn set_len(h: usize, len: u64) -> Result<(), ()> { + let _lock = crate::fat::DiskGuard::acquire(); + match &mut nodes()[h].data { NodeData::Regular(v) => { v.resize(len as usize, 0); Ok(()) @@ -567,6 +574,7 @@ pub fn set_len(h: usize, len: u64) -> Result<(), ()> { match &mut nodes()[h]. /// Create a Regular or Dir child. Fails if the name exists or is invalid. pub fn create(parent: usize, name: &str, kind: FileType) -> Result { + let _lock = crate::fat::DiskGuard::acquire(); if name.is_empty() || name.contains('/') || kind == FileType::Char { return Err(()); } @@ -608,6 +616,7 @@ pub fn create(parent: usize, name: &str, kind: FileType) -> Result { /// Remove a regular file or an empty directory (tombstone). pub fn remove(h: usize) -> Result<(), ()> { + let _lock = crate::fat::DiskGuard::acquire(); // Disk nodes: delete through the FAT volume (dirs must be empty). if let NodeData::Disk(i) = &nodes()[h].data { if i.name.is_empty() { -- cgit v1.2.3