refactor: clean up non-doc warnings
This commit is contained in:
@@ -356,7 +356,7 @@ mod cow_tests {
|
||||
assert_eq!(buf[i], ((i + 512) & 0xFF) as u8);
|
||||
}
|
||||
|
||||
bvec.write(source_data.len(), b"test");
|
||||
bvec.write(source_data.len(), b"test").unwrap();
|
||||
assert_eq!(bvec.size(), 4096 * 2 + 2);
|
||||
assert_eq!(bvec.capacity, 3);
|
||||
|
||||
|
||||
+2
-4
@@ -150,14 +150,12 @@ impl<A: BlockAllocator + Copy + 'static> Filesystem for Ramfs<A> {
|
||||
}
|
||||
|
||||
impl<A: BlockAllocator + Copy + 'static> Ramfs<A> {
|
||||
pub fn open(base: *const u8, size: usize, alloc: A) -> Result<Rc<Self>, Errno> {
|
||||
pub unsafe fn open(base: *const u8, size: usize, alloc: A) -> Result<Rc<Self>, Errno> {
|
||||
let res = Rc::new(Self {
|
||||
root: RefCell::new(None),
|
||||
alloc,
|
||||
});
|
||||
unsafe {
|
||||
*res.root.borrow_mut() = Some(res.clone().load_tar(base, size)?);
|
||||
}
|
||||
*res.root.borrow_mut() = Some(res.clone().load_tar(base, size)?);
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
||||
+18
-3
@@ -1,6 +1,4 @@
|
||||
use crate::VnodeRef;
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
use core::cmp::min;
|
||||
use error::Errno;
|
||||
use libcommon::{Read, Seek, SeekDir, Write};
|
||||
@@ -12,6 +10,9 @@ struct NormalFile {
|
||||
|
||||
enum FileInner {
|
||||
Normal(NormalFile),
|
||||
// TODO
|
||||
#[allow(dead_code)]
|
||||
Socket,
|
||||
}
|
||||
|
||||
pub struct File {
|
||||
@@ -31,6 +32,19 @@ impl Read for File {
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for File {
|
||||
fn write(&mut self, data: &[u8]) -> Result<usize, Errno> {
|
||||
match &mut self.inner {
|
||||
FileInner::Normal(inner) => {
|
||||
let count = inner.vnode.write(inner.pos, data)?;
|
||||
inner.pos += count;
|
||||
Ok(count)
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Seek for File {
|
||||
fn seek(&mut self, off: isize, whence: SeekDir) -> Result<usize, Errno> {
|
||||
match &mut self.inner {
|
||||
@@ -65,7 +79,8 @@ impl File {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{node::VnodeData, Filesystem, Ioctx, Vnode, VnodeImpl, VnodeKind, VnodeRef};
|
||||
use crate::{node::VnodeData, Filesystem, Vnode, VnodeImpl, VnodeKind, VnodeRef};
|
||||
use alloc::rc::Rc;
|
||||
use alloc::boxed::Box;
|
||||
use core::ffi::c_void;
|
||||
|
||||
|
||||
+1
-1
@@ -116,7 +116,7 @@ impl Vnode {
|
||||
let index = parent_borrow
|
||||
.children
|
||||
.iter()
|
||||
.position(|it| Rc::ptr_eq(&it, self))
|
||||
.position(|it| Rc::ptr_eq(it, self))
|
||||
.unwrap();
|
||||
parent_borrow.children.remove(index);
|
||||
}
|
||||
|
||||
@@ -75,12 +75,12 @@ fn dump_node(level: Level, node: &INode, depth: usize) {
|
||||
|
||||
fn find_node<'a>(at: INode<'a>, path: &str) -> Option<INode<'a>> {
|
||||
let (item, path) = path_component_left(path);
|
||||
if item == "" {
|
||||
if item.is_empty() {
|
||||
assert_eq!(path, "");
|
||||
Some(at)
|
||||
} else {
|
||||
let child = at.children().find(|c| c.name().unwrap() == item)?;
|
||||
if path == "" {
|
||||
if path.is_empty() {
|
||||
Some(child)
|
||||
} else {
|
||||
find_node(child, path)
|
||||
@@ -92,13 +92,13 @@ fn find_prop<'a>(at: INode<'a>, name: &str) -> Option<IProp<'a>> {
|
||||
at.props().find(|p| p.name().unwrap() == name)
|
||||
}
|
||||
|
||||
fn read_cells(prop: &IProp, off: usize, cells: u32) -> Option<u64> {
|
||||
Some(match cells {
|
||||
1 => prop.u32(off).ok()? as u64,
|
||||
2 => (prop.u32(off).ok()? as u64) | ((prop.u32(off + 1).ok()? as u64) << 32),
|
||||
_ => todo!(),
|
||||
})
|
||||
}
|
||||
// fn read_cells(prop: &IProp, off: usize, cells: u32) -> Option<u64> {
|
||||
// Some(match cells {
|
||||
// 1 => prop.u32(off).ok()? as u64,
|
||||
// 2 => (prop.u32(off).ok()? as u64) | ((prop.u32(off + 1).ok()? as u64) << 32),
|
||||
// _ => todo!(),
|
||||
// })
|
||||
// }
|
||||
|
||||
impl DeviceTree {
|
||||
pub fn dump(&self, level: Level) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use crate::mem::{self, phys::{self, PageUsage}};
|
||||
use crate::mem::{
|
||||
self,
|
||||
phys::{self, PageUsage},
|
||||
};
|
||||
use memfs::BlockAllocator;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -8,7 +11,7 @@ pub struct MemfsBlockAlloc;
|
||||
|
||||
unsafe impl BlockAllocator for MemfsBlockAlloc {
|
||||
fn alloc(&self) -> *mut u8 {
|
||||
if let Ok(page) = phys::alloc_page(PageUsage::Kernel) {
|
||||
if let Ok(page) = phys::alloc_page(PageUsage::Filesystem) {
|
||||
mem::virtualize(page) as *mut u8
|
||||
} else {
|
||||
core::ptr::null_mut()
|
||||
@@ -16,6 +19,7 @@ unsafe impl BlockAllocator for MemfsBlockAlloc {
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&self, data: *mut u8) {
|
||||
todo!()
|
||||
let phys = (data as usize) - mem::KERNEL_OFFSET;
|
||||
phys::free_page(phys).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ impl SimpleManager {
|
||||
let pages: &'static mut [PageInfo] =
|
||||
core::slice::from_raw_parts_mut(virtualize(at) as *mut _, count);
|
||||
// Initialize uninit pages
|
||||
for index in 0..count {
|
||||
for entry in pages.iter_mut() {
|
||||
mem::forget(mem::replace(
|
||||
&mut pages[index],
|
||||
entry,
|
||||
PageInfo {
|
||||
refcount: 0,
|
||||
usage: PageUsage::Reserved,
|
||||
|
||||
@@ -29,6 +29,8 @@ pub enum PageUsage {
|
||||
Paging,
|
||||
/// Userspace page
|
||||
UserPrivate,
|
||||
/// Filesystem data and blocks
|
||||
Filesystem,
|
||||
}
|
||||
|
||||
/// Data structure representing a single physical memory page
|
||||
@@ -79,6 +81,11 @@ pub fn alloc_page(pu: PageUsage) -> Result<usize, Errno> {
|
||||
MANAGER.lock().as_mut().unwrap().alloc_page(pu)
|
||||
}
|
||||
|
||||
/// Releases a single physical memory page back for further allocation.
|
||||
pub unsafe fn free_page(page: usize) -> Result<(), Errno> {
|
||||
MANAGER.lock().as_mut().unwrap().free_page(page)
|
||||
}
|
||||
|
||||
fn find_contiguous<T: Iterator<Item = MemoryRegion>>(iter: T, count: usize) -> Option<usize> {
|
||||
for region in iter {
|
||||
let mut collected = 0;
|
||||
|
||||
@@ -67,7 +67,9 @@ pub unsafe fn enter(initrd: Option<(usize, usize)>) -> ! {
|
||||
let size = end - start;
|
||||
|
||||
infoln!("Constructing initrd filesystem in memory, this may take a while...");
|
||||
let fs = Ramfs::open(start as *mut u8, size, MemfsBlockAlloc {}).unwrap();
|
||||
let fs = unsafe {
|
||||
Ramfs::open(start as *mut u8, size, MemfsBlockAlloc {}).unwrap()
|
||||
};
|
||||
infoln!("Done constructing ramfs");
|
||||
let root = fs.root().unwrap();
|
||||
let ioctx = Ioctx::new(root);
|
||||
|
||||
+3
-5
@@ -48,11 +48,9 @@ impl<T> IrqSafeSpinLock<T> {
|
||||
cortex_a::asm::wfe();
|
||||
}
|
||||
|
||||
unsafe {
|
||||
IrqSafeSpinLockGuard {
|
||||
lock: self,
|
||||
irq_state
|
||||
}
|
||||
IrqSafeSpinLockGuard {
|
||||
lock: self,
|
||||
irq_state
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user