diff --git a/src/allocator.rs b/src/allocator.rs index c3a35421e6..862d9fada2 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -2,9 +2,10 @@ use alloc::vec::Vec; use core::{fmt, mem, ops, slice}; use simple_endian::*; -use crate::BlockPtr; +use crate::{BlockPtr, BLOCK_SIZE}; -pub const ALLOC_LIST_ENTRIES: usize = 255; +pub const ALLOC_LIST_ENTRIES: usize = + (BLOCK_SIZE as usize - mem::size_of::>()) / mem::size_of::(); #[derive(Clone, Default)] pub struct Allocator { diff --git a/src/bin/mount.rs b/src/bin/mount.rs index e7347e2a97..707607ffaa 100644 --- a/src/bin/mount.rs +++ b/src/bin/mount.rs @@ -13,11 +13,7 @@ use std::os::unix::io::{FromRawFd, RawFd}; use std::process; #[cfg(target_os = "redox")] -use std::{ - mem::MaybeUninit, - ptr::addr_of_mut, - sync::atomic::Ordering, -}; +use std::{mem::MaybeUninit, ptr::addr_of_mut, sync::atomic::Ordering}; use redoxfs::{mount, DiskCache, DiskFile, FileSystem}; use termion::input::TermRead; @@ -37,12 +33,17 @@ fn setsig() { unsafe { let mut action = MaybeUninit::::uninit(); - assert_eq!(libc::sigemptyset(addr_of_mut!((*action.as_mut_ptr()).sa_mask)), 0); + assert_eq!( + libc::sigemptyset(addr_of_mut!((*action.as_mut_ptr()).sa_mask)), + 0 + ); addr_of_mut!((*action.as_mut_ptr()).sa_flags).write(0); addr_of_mut!((*action.as_mut_ptr()).sa_sigaction).write(unmount_handler as usize); - - assert_eq!(libc::sigaction(libc::SIGTERM, action.as_ptr(), core::ptr::null_mut()), 0); + assert_eq!( + libc::sigaction(libc::SIGTERM, action.as_ptr(), core::ptr::null_mut()), + 0 + ); } } @@ -94,14 +95,19 @@ fn bootloader_password() -> Option> { unsafe { let aligned_size = size.next_multiple_of(syscall::PAGE_SIZE); - let fd = syscall::open("memory:physical", syscall::O_CLOEXEC).expect("failed to open physical memory file"); + let fd = syscall::open("memory:physical", syscall::O_CLOEXEC) + .expect("failed to open physical memory file"); - let password_map = syscall::fmap(fd, &syscall::Map { - offset: addr, - size: aligned_size, - flags: MapFlags::PROT_READ | MapFlags::MAP_SHARED, - address: 0, // ignored - }).expect("failed to map REDOXFS_PASSWORD"); + let password_map = syscall::fmap( + fd, + &syscall::Map { + offset: addr, + size: aligned_size, + flags: MapFlags::PROT_READ | MapFlags::MAP_SHARED, + address: 0, // ignored + }, + ) + .expect("failed to map REDOXFS_PASSWORD"); let _ = syscall::close(fd); @@ -163,8 +169,7 @@ fn filesystem_by_path( println!( "redoxfs: opened filesystem on {} with uuid {}", path, - Uuid::from_bytes(filesystem.header.uuid()) - .hyphenated() + Uuid::from_bytes(filesystem.header.uuid()).hyphenated() ); return Some((path.to_string(), filesystem)); diff --git a/src/block.rs b/src/block.rs index bc1fabb068..266648a2d9 100644 --- a/src/block.rs +++ b/src/block.rs @@ -3,6 +3,8 @@ use simple_endian::*; use crate::BLOCK_SIZE; +const BLOCK_LIST_ENTRIES: usize = BLOCK_SIZE as usize / mem::size_of::>(); + #[derive(Clone, Copy, Debug, Default)] pub struct BlockData { addr: u64, @@ -50,7 +52,7 @@ impl> BlockData { #[repr(packed)] pub struct BlockList { - pub ptrs: [BlockPtr; 256], + pub ptrs: [BlockPtr; BLOCK_LIST_ENTRIES], } impl BlockList { @@ -67,7 +69,7 @@ impl BlockList { impl Default for BlockList { fn default() -> Self { Self { - ptrs: [BlockPtr::default(); 256], + ptrs: [BlockPtr::default(); BLOCK_LIST_ENTRIES], } } } diff --git a/src/dir.rs b/src/dir.rs index 20cd74f6a5..d6c047b903 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -1,6 +1,8 @@ use core::{mem, ops, slice, str}; -use crate::{Node, TreePtr}; +use crate::{Node, TreePtr, BLOCK_SIZE}; + +const DIR_LIST_ENTRIES: usize = BLOCK_SIZE as usize / mem::size_of::(); #[repr(packed)] pub struct DirEntry { @@ -63,7 +65,7 @@ impl Default for DirEntry { #[repr(packed)] pub struct DirList { - pub entries: [DirEntry; 16], + pub entries: [DirEntry; DIR_LIST_ENTRIES], } impl DirList { @@ -80,7 +82,7 @@ impl DirList { impl Default for DirList { fn default() -> Self { Self { - entries: [DirEntry::default(); 16], + entries: [DirEntry::default(); DIR_LIST_ENTRIES], } } } diff --git a/src/extent.rs b/src/extent.rs deleted file mode 100644 index 56b2c041a5..0000000000 --- a/src/extent.rs +++ /dev/null @@ -1,57 +0,0 @@ -use core::cmp::min; - -use BLOCK_SIZE; - -pub struct BlockIter { - block: u64, - length: u64, - i: u64, -} - -impl Iterator for BlockIter { - type Item = (u64, u64); - fn next(&mut self) -> Option { - if self.i < (self.length + BLOCK_SIZE - 1) / BLOCK_SIZE { - let ret = Some(( - self.block + self.i, - min(BLOCK_SIZE, self.length - self.i * BLOCK_SIZE), - )); - self.i += 1; - ret - } else { - None - } - } -} - -/// A disk extent, [wikipedia](https://en.wikipedia.org/wiki/Extent_(file_systems)) -#[derive(Copy, Clone, Debug, Default)] -#[repr(packed)] -pub struct Extent { - pub block: u64, - pub length: u64, -} - -impl Extent { - pub fn default() -> Extent { - Extent { - block: 0, - length: 0, - } - } - - pub fn new(block: u64, length: u64) -> Extent { - Extent { - block: block, - length: length, - } - } - - pub fn blocks(&self) -> BlockIter { - BlockIter { - block: self.block, - length: self.length, - i: 0, - } - } -} diff --git a/src/filesystem.rs b/src/filesystem.rs index bb099579d9..491eba2b89 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -1,7 +1,7 @@ use aes::{Aes128, BlockDecrypt, BlockEncrypt}; use alloc::{collections::VecDeque, vec::Vec}; use core::mem; -use syscall::error::{Error, Result, EKEYREJECTED, EIO, ENOENT, ENOKEY, ENOSPC}; +use syscall::error::{Error, Result, EIO, EKEYREJECTED, ENOENT, ENOKEY, ENOSPC}; use crate::{ AllocEntry, AllocList, Allocator, BlockData, Disk, Header, Key, KeySlot, Node, Salt, @@ -159,9 +159,7 @@ impl FileSystem { }; // Write header generation zero - let count = unsafe { - fs.disk.write_at(fs.block, &fs.header)? - }; + let count = unsafe { fs.disk.write_at(fs.block, &fs.header)? }; if count != mem::size_of_val(&fs.header) { // Wrote wrong number of bytes #[cfg(feature = "log")] diff --git a/src/mount/fuse.rs b/src/mount/fuse.rs index 24494620b4..8714e3d13d 100644 --- a/src/mount/fuse.rs +++ b/src/mount/fuse.rs @@ -44,7 +44,9 @@ where let res = { let mut session = Session::new( - Fuse { fs: &mut filesystem }, + Fuse { + fs: &mut filesystem, + }, mountpoint, if cfg!(target_os = "macos") { &defer_permissions diff --git a/src/node.rs b/src/node.rs index 30c382c2e8..59f6b2be74 100644 --- a/src/node.rs +++ b/src/node.rs @@ -1,7 +1,7 @@ use core::{fmt, mem, ops, slice}; use simple_endian::*; -use crate::{BlockList, BlockPtr, BlockRaw}; +use crate::{BlockList, BlockPtr, BlockRaw, BLOCK_SIZE}; pub enum NodeLevel { L0(usize), @@ -93,7 +93,7 @@ pub struct Node { pub mtime_nsec: u32le, pub atime: u64le, pub atime_nsec: u32le, - pub padding: [u8; 6], + pub padding: [u8; BLOCK_SIZE as usize - 4090], // 128 * BLOCK_SIZE (512 KiB, 4 KiB each) pub level0: [BlockPtr; 128], // 64 * 256 * BLOCK_SIZE (64 MiB, 1 MiB each) @@ -120,7 +120,7 @@ impl Default for Node { mtime_nsec: 0.into(), atime: 0.into(), atime_nsec: 0.into(), - padding: [0; 6], + padding: [0; BLOCK_SIZE as usize - 4090], level0: [BlockPtr::default(); 128], level1: [BlockPtr::default(); 64], level2: [BlockPtr::default(); 32], diff --git a/src/transaction.rs b/src/transaction.rs index 35e3ad2ebc..ce33303261 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -626,7 +626,10 @@ impl<'a, D: Disk> Transaction<'a, D> { // Read node and test type against requested type let node = self.read_tree(node_ptr)?; if node.data().mode() & Node::MODE_TYPE == mode { - if node.data().is_dir() && node.data().size() > 0 && node.data().links() == 1 { + if node.data().is_dir() + && node.data().size() > 0 + && node.data().links() == 1 + { // Tried to remove directory that still has entries return Err(Error::new(ENOTEMPTY)); } diff --git a/src/tree.rs b/src/tree.rs index 8148c93c8b..4526d37781 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -5,6 +5,7 @@ use crate::{BlockPtr, BlockRaw}; // 1 << 8 = 256, this is the number of entries in a TreeList const TREE_LIST_SHIFT: u32 = 8; +const TREE_LIST_ENTRIES: usize = 1 << TREE_LIST_SHIFT; // Tree with 4 levels pub type Tree = TreeList>>>; @@ -46,13 +47,13 @@ impl TreeData { #[repr(packed)] pub struct TreeList { - pub ptrs: [BlockPtr; 1 << TREE_LIST_SHIFT], + pub ptrs: [BlockPtr; TREE_LIST_ENTRIES], } impl Default for TreeList { fn default() -> Self { Self { - ptrs: [BlockPtr::default(); 1 << TREE_LIST_SHIFT], + ptrs: [BlockPtr::default(); TREE_LIST_ENTRIES], } } } diff --git a/src/unmount.rs b/src/unmount.rs index 8577233a02..368fd5910f 100644 --- a/src/unmount.rs +++ b/src/unmount.rs @@ -43,7 +43,10 @@ pub fn unmount_path(mount_path: &str) -> Result<(), io::Error> { let status = status_res?; if !status.success() { - return Err(io::Error::new(io::ErrorKind::Other, "redoxfs umount failed")); + return Err(io::Error::new( + io::ErrorKind::Other, + "redoxfs umount failed", + )); } }