diff options
Diffstat (limited to 'rsnix/src/fs.rs')
| -rw-r--r-- | rsnix/src/fs.rs | 13 |
1 files changed, 11 insertions, 2 deletions
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) { | |||
| 203 | /// its backing info), and tombstone nodes whose volume was unmounted. | 203 | /// its backing info), and tombstone nodes whose volume was unmounted. |
| 204 | /// Returns (added, removed) node ops. | 204 | /// Returns (added, removed) node ops. |
| 205 | pub fn rescan_disks() -> (usize, usize) { | 205 | pub fn rescan_disks() -> (usize, usize) { |
| 206 | let _lock = crate::fat::DiskGuard::acquire(); | ||
| 206 | let mut added = 0usize; | 207 | let mut added = 0usize; |
| 207 | let mut removed = 0usize; | 208 | let mut removed = 0usize; |
| 208 | let disk_dir = match lookup(0, "disk") { | 209 | let disk_dir = match lookup(0, "disk") { |
| @@ -428,6 +429,7 @@ pub fn read(h: usize, buf: &mut [u8], pos: u64) -> Result<usize, ()> { | |||
| 428 | } | 429 | } |
| 429 | 430 | ||
| 430 | pub fn write(h: usize, buf: &[u8], pos: u64) -> Result<usize, ()> { | 431 | pub fn write(h: usize, buf: &[u8], pos: u64) -> Result<usize, ()> { |
| 432 | let _lock = crate::fat::DiskGuard::acquire(); | ||
| 431 | match &mut nodes()[h].data { | 433 | match &mut nodes()[h].data { |
| 432 | NodeData::Regular(v) => { | 434 | NodeData::Regular(v) => { |
| 433 | let p = pos as usize; | 435 | let p = pos as usize; |
| @@ -533,7 +535,10 @@ pub fn write_crash_log(lines: &[&str]) { | |||
| 533 | let mut tb = [0u8; 48]; | 535 | let mut tb = [0u8; 48]; |
| 534 | let tn = { | 536 | let tn = { |
| 535 | let mut w = crate::strbuf::FmtBuf::new(&mut tb); | 537 | let mut w = crate::strbuf::FmtBuf::new(&mut tb); |
| 536 | let _ = core::fmt::write(&mut w, core::format_args!("crashlog: vol {} ({})\r\n", vol, label)); | 538 | let _ = core::fmt::write( |
| 539 | &mut w, | ||
| 540 | core::format_args!("crashlog: vol {} ({})\r\n", vol, label), | ||
| 541 | ); | ||
| 537 | w.len() | 542 | w.len() |
| 538 | }; | 543 | }; |
| 539 | crate::serial::write_raw(core::str::from_utf8(&tb[..tn]).unwrap_or("?")); | 544 | crate::serial::write_raw(core::str::from_utf8(&tb[..tn]).unwrap_or("?")); |
| @@ -555,7 +560,9 @@ pub fn write_crash_log(lines: &[&str]) { | |||
| 555 | } | 560 | } |
| 556 | 561 | ||
| 557 | /// Truncate/resize a regular file. | 562 | /// Truncate/resize a regular file. |
| 558 | pub fn set_len(h: usize, len: u64) -> Result<(), ()> { match &mut nodes()[h].data { | 563 | pub fn set_len(h: usize, len: u64) -> Result<(), ()> { |
| 564 | let _lock = crate::fat::DiskGuard::acquire(); | ||
| 565 | match &mut nodes()[h].data { | ||
| 559 | NodeData::Regular(v) => { | 566 | NodeData::Regular(v) => { |
| 560 | v.resize(len as usize, 0); | 567 | v.resize(len as usize, 0); |
| 561 | Ok(()) | 568 | Ok(()) |
| @@ -567,6 +574,7 @@ pub fn set_len(h: usize, len: u64) -> Result<(), ()> { match &mut nodes()[h]. | |||
| 567 | 574 | ||
| 568 | /// Create a Regular or Dir child. Fails if the name exists or is invalid. | 575 | /// Create a Regular or Dir child. Fails if the name exists or is invalid. |
| 569 | pub fn create(parent: usize, name: &str, kind: FileType) -> Result<usize, ()> { | 576 | pub fn create(parent: usize, name: &str, kind: FileType) -> Result<usize, ()> { |
| 577 | let _lock = crate::fat::DiskGuard::acquire(); | ||
| 570 | if name.is_empty() || name.contains('/') || kind == FileType::Char { | 578 | if name.is_empty() || name.contains('/') || kind == FileType::Char { |
| 571 | return Err(()); | 579 | return Err(()); |
| 572 | } | 580 | } |
| @@ -608,6 +616,7 @@ pub fn create(parent: usize, name: &str, kind: FileType) -> Result<usize, ()> { | |||
| 608 | 616 | ||
| 609 | /// Remove a regular file or an empty directory (tombstone). | 617 | /// Remove a regular file or an empty directory (tombstone). |
| 610 | pub fn remove(h: usize) -> Result<(), ()> { | 618 | pub fn remove(h: usize) -> Result<(), ()> { |
| 619 | let _lock = crate::fat::DiskGuard::acquire(); | ||
| 611 | // Disk nodes: delete through the FAT volume (dirs must be empty). | 620 | // Disk nodes: delete through the FAT volume (dirs must be empty). |
| 612 | if let NodeData::Disk(i) = &nodes()[h].data { | 621 | if let NodeData::Disk(i) = &nodes()[h].data { |
| 613 | if i.name.is_empty() { | 622 | if i.name.is_empty() { |
