refactor: fix clippy warnings
This commit is contained in:
parent
d0681eb589
commit
a577b2dcc4
@ -2,6 +2,7 @@ use crate::{VnodeKind, VnodeRef, Vnode};
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
use core::cmp::min;
|
||||
use core::str::FromStr;
|
||||
use libsys::{
|
||||
error::Errno,
|
||||
stat::DirectoryEntry,
|
||||
@ -142,7 +143,7 @@ impl File {
|
||||
return Ok(offset);
|
||||
}
|
||||
|
||||
entries[offset] = DirectoryEntry::from_str(".");
|
||||
entries[offset] = DirectoryEntry::from_str(".").unwrap();
|
||||
inner.pos = Self::POS_CACHE_DOT_DOT;
|
||||
|
||||
offset += 1;
|
||||
@ -154,7 +155,7 @@ impl File {
|
||||
return Ok(offset);
|
||||
}
|
||||
|
||||
entries[offset] = DirectoryEntry::from_str("..");
|
||||
entries[offset] = DirectoryEntry::from_str("..").unwrap();
|
||||
inner.pos = 0;
|
||||
|
||||
offset += 1;
|
||||
@ -166,7 +167,7 @@ impl File {
|
||||
}
|
||||
|
||||
let count = inner.vnode.for_each_entry(inner.pos, count, |i, e| {
|
||||
entries[offset + i] = DirectoryEntry::from_str(e.name());
|
||||
entries[offset + i] = DirectoryEntry::from_str(e.name()).unwrap();
|
||||
});
|
||||
inner.pos += count;
|
||||
Ok(offset + count)
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{File, FileRef, Filesystem, Ioctx};
|
||||
use alloc::{borrow::ToOwned, boxed::Box, rc::Rc, string::String, vec::Vec};
|
||||
use core::cell::{RefCell, RefMut, Ref};
|
||||
use core::cell::{Ref, RefCell, RefMut};
|
||||
use core::fmt;
|
||||
use libsys::{
|
||||
error::Errno,
|
||||
@ -288,10 +288,8 @@ impl Vnode {
|
||||
/// vnode and will load it from disk if it's missing.
|
||||
pub fn lookup_or_load(self: &VnodeRef, name: &str) -> Result<VnodeRef, Errno> {
|
||||
if let Some(node) = self.lookup(name) {
|
||||
return Ok(node);
|
||||
}
|
||||
|
||||
if let Some(ref mut data) = *self.data() {
|
||||
Ok(node)
|
||||
} else if let Some(ref mut data) = *self.data() {
|
||||
let vnode = data.lookup(self.clone(), name)?;
|
||||
if let Some(fs) = self.fs() {
|
||||
vnode.set_fs(fs);
|
||||
@ -386,13 +384,11 @@ impl Vnode {
|
||||
|
||||
if self.kind == VnodeKind::Directory && self.flags & Vnode::CACHE_READDIR != 0 {
|
||||
Ok(File::normal(self.clone(), File::POS_CACHE_DOT, open_flags))
|
||||
} else if let Some(ref mut data) = *self.data() {
|
||||
let pos = data.open(self.clone(), flags)?;
|
||||
Ok(File::normal(self.clone(), pos, open_flags))
|
||||
} else {
|
||||
if let Some(ref mut data) = *self.data() {
|
||||
let pos = data.open(self.clone(), flags)?;
|
||||
Ok(File::normal(self.clone(), pos, open_flags))
|
||||
} else {
|
||||
Err(Errno::NotImplemented)
|
||||
}
|
||||
Err(Errno::NotImplemented)
|
||||
}
|
||||
}
|
||||
|
||||
@ -400,22 +396,18 @@ impl Vnode {
|
||||
pub fn close(self: &VnodeRef) -> Result<(), Errno> {
|
||||
if self.kind == VnodeKind::Directory && self.flags & Vnode::CACHE_READDIR != 0 {
|
||||
Ok(())
|
||||
} else if let Some(ref mut data) = *self.data() {
|
||||
data.close(self.clone())
|
||||
} else {
|
||||
if let Some(ref mut data) = *self.data() {
|
||||
data.close(self.clone())
|
||||
} else {
|
||||
Err(Errno::NotImplemented)
|
||||
}
|
||||
Err(Errno::NotImplemented)
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads data from offset `pos` into `buf`
|
||||
pub fn read(self: &VnodeRef, pos: usize, buf: &mut [u8]) -> Result<usize, Errno> {
|
||||
if self.kind == VnodeKind::Directory {
|
||||
return Err(Errno::IsADirectory);
|
||||
}
|
||||
|
||||
if let Some(ref mut data) = *self.data() {
|
||||
Err(Errno::IsADirectory)
|
||||
} else if let Some(ref mut data) = *self.data() {
|
||||
data.read(self.clone(), pos, buf)
|
||||
} else {
|
||||
Err(Errno::NotImplemented)
|
||||
@ -425,10 +417,8 @@ impl Vnode {
|
||||
/// Writes data from `buf` to offset `pos`
|
||||
pub fn write(self: &VnodeRef, pos: usize, buf: &[u8]) -> Result<usize, Errno> {
|
||||
if self.kind == VnodeKind::Directory {
|
||||
return Err(Errno::IsADirectory);
|
||||
}
|
||||
|
||||
if let Some(ref mut data) = *self.data() {
|
||||
Err(Errno::IsADirectory)
|
||||
} else if let Some(ref mut data) = *self.data() {
|
||||
data.write(self.clone(), pos, buf)
|
||||
} else {
|
||||
Err(Errno::NotImplemented)
|
||||
@ -438,10 +428,8 @@ impl Vnode {
|
||||
/// Resizes the vnode data
|
||||
pub fn truncate(self: &VnodeRef, size: usize) -> Result<(), Errno> {
|
||||
if self.kind != VnodeKind::Regular {
|
||||
return Err(Errno::IsADirectory);
|
||||
}
|
||||
|
||||
if let Some(ref mut data) = *self.data() {
|
||||
Err(Errno::IsADirectory)
|
||||
} else if let Some(ref mut data) = *self.data() {
|
||||
data.truncate(self.clone(), size)
|
||||
} else {
|
||||
Err(Errno::NotImplemented)
|
||||
@ -464,7 +452,7 @@ impl Vnode {
|
||||
Ok(Stat {
|
||||
blksize: 0,
|
||||
size: 0,
|
||||
mode: props.mode
|
||||
mode: props.mode,
|
||||
})
|
||||
} else if let Some(ref mut data) = *self.data() {
|
||||
data.stat(self.clone())
|
||||
@ -500,7 +488,6 @@ impl Vnode {
|
||||
if access.intersects(AccessMode::R_OK | AccessMode::W_OK | AccessMode::X_OK) {
|
||||
return Err(Errno::InvalidArgument);
|
||||
}
|
||||
return Ok(());
|
||||
} else {
|
||||
if access.contains(AccessMode::F_OK) {
|
||||
return Err(Errno::InvalidArgument);
|
||||
@ -519,9 +506,9 @@ impl Vnode {
|
||||
|
||||
// TODO check group
|
||||
// TODO check other
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -410,7 +410,7 @@ impl Process {
|
||||
let mut data_offset = 0usize;
|
||||
for arg in argv.iter() {
|
||||
// XXX this is really unsafe and I am not really sure ABI will stay like this XXX
|
||||
Self::write_paged(space, base + offset + 0, base + data_offset)?;
|
||||
Self::write_paged(space, base + offset, base + data_offset)?;
|
||||
Self::write_paged(space, base + offset + 8, arg.len())?;
|
||||
offset += 16;
|
||||
data_offset += arg.len();
|
||||
|
@ -237,6 +237,7 @@ impl Thread {
|
||||
|
||||
/// Changes process wait condition status
|
||||
pub fn setup_wait(&self, wait: *const Wait) {
|
||||
#![allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
let mut lock = self.inner.lock();
|
||||
// FIXME this is not cool
|
||||
lock.pending_wait = Some(unsafe { &*wait });
|
||||
|
@ -83,8 +83,12 @@ pub fn select(
|
||||
}
|
||||
let read = rfds.as_deref().map(FdSet::clone);
|
||||
let write = wfds.as_deref().map(FdSet::clone);
|
||||
rfds.as_deref_mut().map(FdSet::reset);
|
||||
wfds.as_deref_mut().map(FdSet::reset);
|
||||
if let Some(rfds) = &mut rfds {
|
||||
rfds.reset();
|
||||
}
|
||||
if let Some(wfds) = &mut wfds {
|
||||
wfds.reset();
|
||||
}
|
||||
|
||||
let deadline = timeout.map(|v| v + machine::local_timer().timestamp().unwrap());
|
||||
let proc = thread.owner().unwrap();
|
||||
|
@ -75,9 +75,6 @@ macro_rules! argp {
|
||||
// ($a:expr) => ($a as *const core::ffi::c_void as usize)
|
||||
// }
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub fn sys_exit(code: ExitCode) -> ! {
|
||||
unsafe {
|
||||
@ -86,17 +83,11 @@ pub fn sys_exit(code: ExitCode) -> ! {
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub fn sys_close(fd: FileDescriptor) -> Result<(), Errno> {
|
||||
Errno::from_syscall_unit(unsafe { syscall!(SystemCall::Close, argn!(u32::from(fd))) })
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub fn sys_ex_nanosleep(ns: u64, rem: &mut [u64; 2]) -> Result<(), Errno> {
|
||||
Errno::from_syscall_unit(unsafe {
|
||||
@ -104,9 +95,6 @@ pub fn sys_ex_nanosleep(ns: u64, rem: &mut [u64; 2]) -> Result<(), Errno> {
|
||||
})
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub fn sys_ex_debug_trace(level: TraceLevel, msg: &[u8]) -> Result<(), Errno> {
|
||||
Errno::from_syscall_unit(unsafe {
|
||||
@ -119,9 +107,6 @@ pub fn sys_ex_debug_trace(level: TraceLevel, msg: &[u8]) -> Result<(), Errno> {
|
||||
})
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub fn sys_openat(
|
||||
at: Option<FileDescriptor>,
|
||||
@ -142,9 +127,6 @@ pub fn sys_openat(
|
||||
.map(|e| FileDescriptor::from(e as u32))
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub fn sys_read(fd: FileDescriptor, data: &mut [u8]) -> Result<usize, Errno> {
|
||||
Errno::from_syscall(unsafe {
|
||||
@ -169,9 +151,6 @@ pub fn sys_write(fd: FileDescriptor, data: &[u8]) -> Result<usize, Errno> {
|
||||
})
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub fn sys_fstatat(
|
||||
at: Option<FileDescriptor>,
|
||||
@ -205,9 +184,6 @@ pub unsafe fn sys_fork() -> Result<Option<Pid>, Errno> {
|
||||
})
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub fn sys_execve(pathname: &str, argv: &[&str]) -> Result<(), Errno> {
|
||||
Errno::from_syscall_unit(unsafe {
|
||||
@ -221,9 +197,6 @@ pub fn sys_execve(pathname: &str, argv: &[&str]) -> Result<(), Errno> {
|
||||
})
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub fn sys_waitpid(pid: Pid, status: &mut i32) -> Result<(), Errno> {
|
||||
Errno::from_syscall_unit(unsafe {
|
||||
@ -235,9 +208,6 @@ pub fn sys_waitpid(pid: Pid, status: &mut i32) -> Result<(), Errno> {
|
||||
})
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub fn sys_ioctl(
|
||||
fd: FileDescriptor,
|
||||
@ -474,6 +444,10 @@ pub fn sys_mmap(
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// System call
|
||||
#[inline(always)]
|
||||
pub unsafe fn sys_munmap(addr: usize, len: usize) -> Result<(), Errno> {
|
||||
Errno::from_syscall_unit(syscall!(SystemCall::UnmapMemory, argn!(addr), argn!(len)))
|
||||
|
@ -31,8 +31,8 @@ bitflags! {
|
||||
|
||||
bitflags! {
|
||||
pub struct MemoryMap: u32 {
|
||||
const BACKEND = 0x3 << 0;
|
||||
const ANONYMOUS = 1 << 0;
|
||||
const BACKEND = 0x3;
|
||||
const ANONYMOUS = 1;
|
||||
|
||||
const SHARING = 0x3 << 2;
|
||||
const PRIVATE = 1 << 2;
|
||||
@ -58,9 +58,6 @@ impl From<ExitCode> for i32 {
|
||||
}
|
||||
|
||||
impl Pid {
|
||||
// /// Kernel idle process always has PID of zero
|
||||
// pub const IDLE: Self = Self(Self::KERNEL_BIT);
|
||||
|
||||
const KERNEL_BIT: u32 = 1 << 31;
|
||||
const USER_MAX: u32 = 256;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
// TODO split up this file
|
||||
use crate::error::Errno;
|
||||
use core::str::FromStr;
|
||||
use core::fmt;
|
||||
|
||||
const AT_FDCWD: i32 = -2;
|
||||
@ -143,19 +144,23 @@ impl DirectoryEntry {
|
||||
Self { name: [0; 64] }
|
||||
}
|
||||
|
||||
pub fn from_str(i: &str) -> DirectoryEntry {
|
||||
let mut res = DirectoryEntry { name: [0; 64] };
|
||||
let bytes = i.as_bytes();
|
||||
res.name[..bytes.len()].copy_from_slice(bytes);
|
||||
res
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
let zero = self.name.iter().position(|&c| c == 0).unwrap();
|
||||
core::str::from_utf8(&self.name[..zero]).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for DirectoryEntry {
|
||||
type Err = Errno;
|
||||
|
||||
fn from_str(i: &str) -> Result<Self, Errno> {
|
||||
let mut res = DirectoryEntry { name: [0; 64] };
|
||||
let bytes = i.as_bytes();
|
||||
res.name[..bytes.len()].copy_from_slice(bytes);
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for DirectoryEntry {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("DirectoryEntry")
|
||||
|
@ -102,7 +102,7 @@ impl Zone {
|
||||
|
||||
unsafe fn free(zone: *mut Self) {
|
||||
trace_debug!("Zone::free({:p})", zone);
|
||||
sys_munmap(zone as usize, (&*zone).size + size_of::<Zone>())
|
||||
sys_munmap(zone as usize, (*zone).size + size_of::<Zone>())
|
||||
.expect("Failed to unmap heap pages");
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ unsafe fn alloc_from(list: &mut ZoneList, zone_size: usize, size: usize) -> *mut
|
||||
if !ptr.is_null() {
|
||||
return ptr;
|
||||
}
|
||||
zone = (&mut *zone).next;
|
||||
zone = (*zone).next;
|
||||
}
|
||||
|
||||
let zone = match Zone::alloc(zone_size) {
|
||||
@ -175,7 +175,7 @@ unsafe fn alloc_from(list: &mut ZoneList, zone_size: usize, size: usize) -> *mut
|
||||
return null_mut();
|
||||
}
|
||||
};
|
||||
list.add(&mut (&mut *zone).list);
|
||||
list.add(&mut (*zone).list);
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ unsafe impl GlobalAlloc for Allocator {
|
||||
if !next.is_null() && next_ref.flags & BLOCK_ALLOC == 0 {
|
||||
next_ref.flags = 0;
|
||||
if !next_ref.next.is_null() {
|
||||
(&mut *(next_ref.next)).prev = block;
|
||||
(*next_ref.next).prev = block;
|
||||
}
|
||||
block_ref.next = next_ref.next;
|
||||
block_ref.size += (next_ref.size as usize + size_of::<Block>()) as u32;
|
||||
@ -241,15 +241,15 @@ unsafe impl GlobalAlloc for Allocator {
|
||||
if block_ref.prev.is_null() && block_ref.next.is_null() {
|
||||
let zone = (block as usize - size_of::<Zone>()) as *mut Zone;
|
||||
assert_eq!((zone as usize) & 0xFFF, 0);
|
||||
(&mut *zone).list.del();
|
||||
(*zone).list.del();
|
||||
Zone::free(zone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[alloc_error_handler]
|
||||
fn alloc_error_handler(_layout: Layout) -> ! {
|
||||
loop {}
|
||||
fn alloc_error_handler(layout: Layout) -> ! {
|
||||
panic!("Allocation failed: {:?}", layout);
|
||||
}
|
||||
|
||||
#[global_allocator]
|
||||
|
@ -10,7 +10,7 @@ pub fn args() -> &'static [&'static str] {
|
||||
|
||||
pub(crate) unsafe fn setup_env(arg: &ProgramArgs) {
|
||||
for i in 0..arg.argc {
|
||||
let base = core::ptr::read((arg.argv + i * 16 + 0) as *const *const u8);
|
||||
let base = core::ptr::read((arg.argv + i * 16) as *const *const u8);
|
||||
let len = core::ptr::read((arg.argv + i * 16 + 8) as *const usize);
|
||||
|
||||
let string = core::str::from_utf8(core::slice::from_raw_parts(base, len)).unwrap();
|
||||
|
@ -8,7 +8,8 @@ macro_rules! print {
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! println {
|
||||
($($args:tt)+) => (print!("{}\n", format_args!($($args)+)))
|
||||
($($args:tt)+) => (print!("{}\n", format_args!($($args)+)));
|
||||
() => (print!("\n"));
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
@ -18,7 +19,8 @@ macro_rules! eprint {
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! eprintln {
|
||||
($($args:tt)+) => (eprint!("{}\n", format_args!($($args)+)))
|
||||
($($args:tt)+) => (eprint!("{}\n", format_args!($($args)+)));
|
||||
() => (eprint!("\n"));
|
||||
}
|
||||
|
||||
pub fn _print<T: Write>(out: fn() -> T, args: fmt::Arguments) {
|
||||
|
@ -30,7 +30,7 @@ fn main() -> i32 {
|
||||
|
||||
if args.len() == 1 {
|
||||
if let Err(e) = do_cat(io::stdin()) {
|
||||
eprintln!("{}: {:?}", ".", e);
|
||||
eprintln!(".: {:?}", e);
|
||||
res = -1;
|
||||
}
|
||||
} else {
|
||||
|
@ -27,7 +27,7 @@ fn line_print(off: usize, line: &[u8]) {
|
||||
print!(".");
|
||||
}
|
||||
}
|
||||
println!("");
|
||||
println!();
|
||||
}
|
||||
|
||||
fn do_hexd<F: Read>(mut fd: F) -> Result<(), io::Error> {
|
||||
@ -53,7 +53,7 @@ fn main() -> i32 {
|
||||
|
||||
if args.len() == 1 {
|
||||
if let Err(e) = do_hexd(io::stdin()) {
|
||||
eprintln!("{}: {:?}", ".", e);
|
||||
eprintln!(".: {:?}", e);
|
||||
res = -1;
|
||||
}
|
||||
} else {
|
||||
|
@ -57,7 +57,7 @@ fn main() -> i32 {
|
||||
|
||||
if args.len() == 1 {
|
||||
if let Err(e) = list_directory(".") {
|
||||
eprintln!("{}: {:?}", ".", e);
|
||||
eprintln!(".: {:?}", e);
|
||||
res = -1;
|
||||
}
|
||||
} else {
|
||||
|
@ -22,13 +22,11 @@ fn cmd_cd(args: &[&str]) -> ExitCode {
|
||||
if args.len() != 2 {
|
||||
eprintln!("Usage: cd DIR");
|
||||
ExitCode::from(-1)
|
||||
} else if let Err(err) = sys_chdir(args[1]) {
|
||||
eprintln!("{}: {:?}", args[1], err);
|
||||
ExitCode::from(-1)
|
||||
} else {
|
||||
if let Err(err) = sys_chdir(args[1]) {
|
||||
eprintln!("{}: {:?}", args[1], err);
|
||||
ExitCode::from(-1)
|
||||
} else {
|
||||
ExitCode::from(0)
|
||||
}
|
||||
ExitCode::from(0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,6 @@ fn main() -> i32 {
|
||||
}
|
||||
} else {
|
||||
sys_execve("/sbin/login", &["/sbin/login", "/dev/ttyS0"]).unwrap();
|
||||
loop {}
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user