Make everything scale with block size and format
This commit is contained in:
+3
-2
@@ -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::<BlockPtr<AllocList>>()) / mem::size_of::<AllocEntry>();
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Allocator {
|
||||
|
||||
+22
-17
@@ -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::<libc::sigaction>::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<Vec<u8>> {
|
||||
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));
|
||||
|
||||
+4
-2
@@ -3,6 +3,8 @@ use simple_endian::*;
|
||||
|
||||
use crate::BLOCK_SIZE;
|
||||
|
||||
const BLOCK_LIST_ENTRIES: usize = BLOCK_SIZE as usize / mem::size_of::<BlockPtr<BlockRaw>>();
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct BlockData<T> {
|
||||
addr: u64,
|
||||
@@ -50,7 +52,7 @@ impl<T: ops::Deref<Target = [u8]>> BlockData<T> {
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct BlockList<T> {
|
||||
pub ptrs: [BlockPtr<T>; 256],
|
||||
pub ptrs: [BlockPtr<T>; BLOCK_LIST_ENTRIES],
|
||||
}
|
||||
|
||||
impl<T> BlockList<T> {
|
||||
@@ -67,7 +69,7 @@ impl<T> BlockList<T> {
|
||||
impl<T> Default for BlockList<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
ptrs: [BlockPtr::default(); 256],
|
||||
ptrs: [BlockPtr::default(); BLOCK_LIST_ENTRIES],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -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::<DirEntry>();
|
||||
|
||||
#[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],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Self::Item> {
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -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<D: Disk> FileSystem<D> {
|
||||
};
|
||||
|
||||
// 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")]
|
||||
|
||||
+3
-1
@@ -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
|
||||
|
||||
+3
-3
@@ -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<BlockRaw>; 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],
|
||||
|
||||
+4
-1
@@ -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));
|
||||
}
|
||||
|
||||
+3
-2
@@ -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<TreeList<TreeList<TreeList<BlockRaw>>>>;
|
||||
@@ -46,13 +47,13 @@ impl<T> TreeData<T> {
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct TreeList<T> {
|
||||
pub ptrs: [BlockPtr<T>; 1 << TREE_LIST_SHIFT],
|
||||
pub ptrs: [BlockPtr<T>; TREE_LIST_ENTRIES],
|
||||
}
|
||||
|
||||
impl<T> Default for TreeList<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
ptrs: [BlockPtr::default(); 1 << TREE_LIST_SHIFT],
|
||||
ptrs: [BlockPtr::default(); TREE_LIST_ENTRIES],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -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",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user