refactor: fix warnings

This commit is contained in:
Mark Poliakov 2024-12-04 20:44:17 +02:00
parent cac7306719
commit f9ab1bece3
14 changed files with 211 additions and 146 deletions

View File

@ -1,13 +1,10 @@
use core::{mem::MaybeUninit, time::Duration};
use core::mem::MaybeUninit;
use alloc::{boxed::Box, format};
use async_trait::async_trait;
use kernel_fs::devfs;
use libk::{
task::runtime,
vfs::block::{probe_partitions, NgBlockDevice, NgBlockDeviceWrapper},
};
use libk_mm::{address::AsPhysicalAddress, PageBox, PageSlice};
use libk::vfs::block::{probe_partitions, NgBlockDevice, NgBlockDeviceWrapper};
use libk_mm::{address::AsPhysicalAddress, PageSlice};
use crate::{command::IdentifyNamespaceRequest, IoDirection};
@ -79,7 +76,7 @@ impl NgBlockDevice for NvmeDrive {
.perform_io(self.nsid, lba, lba_count, buffer_address, IoDirection::Read)
.await;
log::info!(target: "io", "read #{lba}, {lba_count} blocks -> {result:?} @ {buffer_address:#x}");
//log::info!(target: "io", "read #{lba}, {lba_count} blocks -> {result:?} @ {buffer_address:#x}");
result
}
@ -100,7 +97,7 @@ impl NgBlockDevice for NvmeDrive {
)
.await;
log::info!(target: "io", "write -> #{lba}, {lba_count} blocks -> {result:?} @ {buffer_address:#x}");
// log::info!(target: "io", "write -> #{lba}, {lba_count} blocks -> {result:?} @ {buffer_address:#x}");
result
}

View File

@ -1,10 +1,4 @@
use core::{
future::poll_fn,
mem::size_of,
pin::Pin,
ptr::null_mut,
task::{Context, Poll},
};
use core::{future::poll_fn, mem::size_of, ptr::null_mut, task::Poll};
use alloc::{
collections::{BTreeMap, BTreeSet},

View File

@ -1,9 +1,7 @@
use core::ops::{Deref, DerefMut};
use alloc::{boxed::Box, vec};
use bytemuck::{Pod, Zeroable};
use libk::vfs::Metadata;
use static_assertions::const_assert_eq;
use yggdrasil_abi::{
bitflags,
io::{FileMode, FileType, GroupId, UserId},

View File

@ -14,12 +14,7 @@ use yggdrasil_abi::{
util::FixedString,
};
use crate::{
data::FsRequiredFeatures,
file::RegularNode,
inode::{InodeAccess, InodeCache},
Dirent, Ext2Fs, Inode,
};
use crate::{data::FsRequiredFeatures, file::RegularNode, inode::InodeAccess, Dirent, Ext2Fs};
pub struct DirectoryNode {
fs: Arc<Ext2Fs>,
@ -44,6 +39,8 @@ impl<'a> DirentIterMut<'a> {
}
pub fn try_fit(&mut self, name: &str, ino: u32) -> bool {
let _ = self.fs;
let name = name.as_bytes();
let new_total_size = size_of::<Dirent>() + name.len();
@ -72,8 +69,9 @@ impl<'a> DirentIterMut<'a> {
dirent.ent_size as usize
};
// TODO if fs has dirent type attr, set it instead of extra name len
let new_dirent = Dirent {
ent_size: new_aligned_size as _,
ent_size: aligned_size as _,
name_length_low: name.len() as _,
type_indicator: 0, // TODO
ino,
@ -125,7 +123,7 @@ impl<'a> Iterator for DirentIter<'a> {
continue;
}
let mut name_len = dirent.name_length_low as usize;
let name_len = dirent.name_length_low as usize;
if !self
.fs
@ -414,7 +412,7 @@ impl DirectoryImpl for DirectoryNode {
Ok(())
}
fn unlink_node(&self, _parent: &NodeRef, name: &str) -> Result<(), Error> {
fn unlink_node(&self, _parent: &NodeRef, _name: &str) -> Result<(), Error> {
if self.fs.force_readonly {
return Err(Error::ReadOnly);
}

View File

@ -1,19 +1,14 @@
use core::{any::Any, cmp::Ordering, ops::Deref};
use core::any::Any;
use alloc::sync::Arc;
use libk::{
block,
error::Error,
task::sync::Mutex,
vfs::{CommonImpl, InstanceData, Metadata, Node, NodeFlags, NodeRef, RegularImpl},
};
use libk_util::sync::LockMethod;
use yggdrasil_abi::io::OpenOptions;
use crate::{
inode::{InodeAccess, InodeCache},
Ext2Fs, Inode,
};
use crate::{inode::InodeAccess, Ext2Fs};
pub struct RegularNode {
fs: Arc<Ext2Fs>,

View File

@ -1,19 +1,10 @@
use core::{
cmp::Ordering,
future::{AsyncDrop, Future},
ops::{Deref, DerefMut},
pin::Pin,
};
use alloc::sync::{Arc, Weak};
use libk::{
block,
error::Error,
task::{
runtime::spawn,
sync::{AsyncMutex, MappedAsyncMutexGuard, Mutex},
},
};
use alloc::sync::Arc;
use libk::{block, error::Error, task::sync::AsyncMutex};
use libk_util::{
lru_hash_table::LruCache,
sync::spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard, IrqSafeRwLockWriteGuard},
@ -43,8 +34,6 @@ pub enum InodeRef {
}
pub struct CachedInodeMut {
ino: u32,
cache: Arc<InodeCache>,
entry: Arc<IrqSafeRwLock<InodeHolder>>,
}
@ -170,11 +159,7 @@ impl InodeCache {
pub async fn get_mut(self: &Arc<Self>, ino: u32) -> Result<InodeMut, Error> {
if self.cache.is_some() {
let entry = self.entry(ino).await?;
let inode = CachedInodeMut {
entry,
cache: self.clone(),
ino,
};
let inode = CachedInodeMut { entry };
Ok(InodeMut::Cached(inode))
} else {
let inode = self.fs.read_inode(ino).await?;

View File

@ -4,23 +4,17 @@
extern crate alloc;
use core::ops::DerefMut;
use alloc::{boxed::Box, sync::Arc};
use async_trait::async_trait;
use bytemuck::Zeroable;
use data::{FsReadonlyFeatures, FsRequiredFeatures, InodeBlockRefs, InodeMode};
use data::{FsReadonlyFeatures, FsRequiredFeatures, InodeMode};
use dir::DirectoryNode;
use file::RegularNode;
use inode::{InodeAccess, InodeCache};
use libk::{
error::Error,
task::sync::Mutex,
vfs::{
block::{
cache::{BlockCache, CachedBlock, DeviceMapper},
BlockDevice,
},
block::{cache::DeviceMapper, BlockDevice},
Filesystem, FilesystemMountOption, NodeRef,
},
};
@ -186,7 +180,7 @@ impl Ext2Fs {
(!unsupported, enabled)
}
async fn create_fs(device: &'static dyn BlockDevice, cached: bool) -> Result<Self, Error> {
async fn create_fs(device: &'static dyn BlockDevice, _cached: bool) -> Result<Self, Error> {
let mut superblock = ExtendedSuperblock::zeroed();
device
.read_exact(
@ -359,6 +353,10 @@ impl Ext2Fs {
) -> Result<T, Error> {
let offset = block_group as usize * size_of::<BlockGroupDescriptor>();
let block = offset / self.block_size;
if block >= self.bgdt.block_count {
log::warn!("ext2: bgdt block out of bounds: {block}");
return Err(Error::InvalidArgument);
}
let offset_in_block = offset % self.block_size;
self.with_block(block as u32 + self.bgdt.base, |block| {
@ -377,6 +375,10 @@ impl Ext2Fs {
) -> Result<T, Error> {
let offset = block_group as usize * size_of::<BlockGroupDescriptor>();
let block = offset / self.block_size;
if block >= self.bgdt.block_count {
log::warn!("ext2: bgdt block out of bounds: {block}");
return Err(Error::InvalidArgument);
}
let offset_in_block = offset % self.block_size;
self.with_block_mut(block as u32 + self.bgdt.base, |block| {

View File

@ -8,10 +8,7 @@ use libk::{
};
use libk_util::sync::spin_rwlock::IrqSafeRwLock;
use crate::{
inode::{InodeAccess, InodeCache},
Ext2Fs, Inode,
};
use crate::{inode::InodeAccess, Ext2Fs, Inode};
pub struct SymlinkNode {
fs: Arc<Ext2Fs>,
@ -32,36 +29,37 @@ impl SymlinkNode {
}
async fn read(&self, buf: &mut [u8]) -> Result<usize, Error> {
todo!()
// let inode = self.inode_cache.get(self.ino).await?;
// let len = inode.size(&self.fs) as usize;
// if len >= self.fs.block_size {
// todo!()
// }
// if buf.len() < len {
// todo!();
// }
let inode = self.inode.get().await?;
let inode = inode.read();
// let mut write = self.cache.write();
// write.clear();
let len = inode.size(&self.fs) as usize;
if len >= self.fs.block_size {
todo!()
}
if buf.len() < len {
todo!();
}
// // If length of symlink is lower than 60, data is stored directly in "block address"
// // section of the inode
// if len < 60 {
// let bytes = unsafe { Self::link_from_inode_blocks(&inode, len) };
// write.extend_from_slice(bytes);
// buf[..len].copy_from_slice(bytes);
// } else {
// self.fs
// .with_inode_block(&inode, 0, |block| {
// write.extend_from_slice(&block[..len]);
// buf[..len].copy_from_slice(&block[..len]);
// Ok(())
// })
// .await?;
// }
let mut write = self.cache.write();
write.clear();
// Ok(len)
// If length of symlink is lower than 60, data is stored directly in "block address"
// section of the inode
if len < 60 {
let bytes = unsafe { Self::link_from_inode_blocks(&inode, len) };
write.extend_from_slice(bytes);
buf[..len].copy_from_slice(bytes);
} else {
self.fs
.with_inode_block(&inode, 0, |block| {
write.extend_from_slice(&block[..len]);
buf[..len].copy_from_slice(&block[..len]);
Ok(())
})
.await?;
}
Ok(len)
}
unsafe fn link_from_inode_blocks(inode: &Inode, len: usize) -> &[u8] {

View File

@ -1,22 +1,12 @@
use core::{
pin::Pin,
task::{Context, Poll, Waker},
};
use core::task::{Context, Poll, Waker};
use alloc::{
boxed::Box,
format,
sync::{Arc, Weak},
};
use futures_util::{pin_mut, task::waker_ref, Future};
use alloc::{boxed::Box, format, sync::Arc};
use futures_util::{task::waker_ref, Future};
use kernel_arch::task::TaskContext;
use libk_util::waker::WakeWeak;
use yggdrasil_abi::error::Error;
use crate::task::{
thread::{CurrentThread, Thread},
TaskContextImpl,
};
use crate::task::{thread::Thread, TaskContextImpl};
use super::{
task::{Task, Termination},

View File

@ -1,24 +1,16 @@
#![allow(clippy::missing_transmute_annotations)]
use core::{
future::Future,
marker::PhantomData,
ops::{Deref, DerefMut},
};
use alloc::sync::Arc;
use kernel_arch::mem::PhysicalMemoryAllocator;
use libk_mm::{
address::{AsPhysicalAddress, PhysicalAddress},
phys::GlobalPhysicalAllocator,
PageBox,
};
use libk_util::{
lru_hash_table::LruCache,
sync::spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard, IrqSafeRwLockWriteGuard},
};
use libk_mm::{address::PhysicalAddress, phys::GlobalPhysicalAllocator, PageBox};
use libk_util::{lru_hash_table::LruCache, sync::spin_rwlock::IrqSafeRwLock};
use yggdrasil_abi::error::Error;
use crate::task::sync::{AsyncMutex, MappedAsyncMutexGuard};
use crate::task::sync::AsyncMutex;
use super::BlockDevice;

View File

@ -14,7 +14,7 @@ use alloc::boxed::Box;
use libk::{
block,
task::thread::Thread,
vfs::{self, File, Filesystem, MessagePayload, Read, Seek, Write},
vfs::{self, File, MessagePayload, Read, Seek, Write},
};
use crate::syscall::{run_with_io, run_with_io_at};
@ -436,7 +436,7 @@ pub(crate) fn receive_message(
})
}
pub(crate) fn file_control(fd: RawFd, control: &mut FileControl) -> Result<(), Error> {
pub(crate) fn file_control(_fd: RawFd, _control: &mut FileControl) -> Result<(), Error> {
todo!()
}

View File

@ -47,3 +47,6 @@ libcolors = { path = "lib/libcolors", default-features = false }
cross.path = "lib/cross"
yggdrasil-rt.path = "../lib/runtime"
yggdrasil-abi = { path = "../lib/abi", features = ["serde", "alloc", "bytemuck"] }
[workspace.lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(rust_analyzer)'] }

View File

@ -107,3 +107,6 @@ path = "src/sync.rs"
[[bin]]
name = "tst"
path = "src/tst.rs"
[lints]
workspace = true

View File

@ -1,5 +1,5 @@
#![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_os))]
#![feature(let_chains)]
#![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_os, rustc_private))]
#![feature(let_chains, decl_macro)]
use std::{
fmt,
@ -49,6 +49,14 @@ trait DisplaySizeBit: Sized {
}
}
trait MetadataImpl {
type Mode: DisplayBit;
fn size(&self) -> u64;
fn inode(&self) -> Option<u32>;
fn mode(&self) -> Self::Mode;
}
impl DisplaySizeBit for u64 {
fn display_size_bit(self, opts: &Args, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if opts.human_readable {
@ -104,49 +112,150 @@ impl DisplayBit for Option<FileType> {
}
}
#[cfg(target_os = "yggdrasil")]
impl DisplayBit for Option<Metadata> {
fn display_bit(&self, opts: &Args, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Some(attrs) = self else {
write!(f, "--------- {:<12}", "???")?;
if opts.inodes {
write!(f, " {:<8}", "---")?;
}
#[cfg(any(target_os = "yggdrasil", rust_analyzer))]
impl DisplayBit for std::os::yggdrasil::io::RawFileMode {
fn display_bit(&self, _opts: &Args, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self}")
}
}
return Ok(());
};
#[cfg(any(target_os = "yggdrasil", rust_analyzer))]
impl MetadataImpl for Metadata {
type Mode = std::os::yggdrasil::io::RawFileMode;
let mode = attrs.mode_ext();
write!(f, "{} {:>12}", mode, attrs.len().display_size_with(opts))?;
if opts.inodes {
if let Some(ino) = attrs.inode() {
write!(f, " {:>8}", ino)?;
fn size(&self) -> u64 {
self.len()
}
fn mode(&self) -> Self::Mode {
self.mode_ext()
}
fn inode(&self) -> Option<u32> {
MetadataExt::inode(self)
}
}
#[cfg(any(unix, rust_analyzer))]
struct UnixFileMode(u32);
#[cfg(any(unix, rust_analyzer))]
impl DisplayBit for UnixFileMode {
fn display_bit(&self, _opts: &Args, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use std::fmt::Write;
macro display_bit($self:expr, $letter:expr, $bit:expr) {
if $self.0 & (1 << $bit) != 0 {
$letter
} else {
write!(f, " {:>8}", "---")?;
'-'
}
}
for i in (0..3).rev() {
let r = i * 3 + 2;
let w = i * 3 + 1;
let x = i * 3;
f.write_char(display_bit!(self, 'r', r))?;
f.write_char(display_bit!(self, 'w', w))?;
f.write_char(display_bit!(self, 'x', x))?;
}
Ok(())
}
}
#[cfg(unix)]
impl DisplayBit for Option<Metadata> {
fn display_bit(&self, opts: &Args, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use sysutils::unix::FileMode;
#[cfg(any(unix, rust_analyzer))]
impl MetadataImpl for Metadata {
type Mode = UnixFileMode;
let Some(attrs) = self else {
return write!(f, "--------- {:<8}", "???");
};
fn size(&self) -> u64 {
self.len()
}
let mode = FileMode::from(attrs.mode());
write!(f, "{} {:>8}", mode, attrs.len().display_size_with(opts))
fn inode(&self) -> Option<u32> {
self.ino().try_into().ok()
}
fn mode(&self) -> Self::Mode {
UnixFileMode(MetadataExt::mode(self))
}
}
impl DisplayBit for Option<Metadata> {
fn display_bit(&self, opts: &Args, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let this = self.as_ref();
let ino = this.and_then(MetadataImpl::inode);
let mode = this.map(MetadataImpl::mode);
let size = this.map(MetadataImpl::size);
if let Some(mode) = mode {
mode.display_bit(opts, f)?;
} else {
write!(f, "---------")?;
}
if let Some(size) = size {
write!(f, " {:>12}", size.display_size_with(opts))?;
} else {
write!(f, " {:<12}", "???")?;
}
if opts.inodes {
if let Some(ino) = ino {
write!(f, " {ino:>8}")?;
} else {
write!(f, " {:<8}", "---")?;
}
}
Ok(())
}
}
// #[cfg(target_os = "yggdrasil")]
// impl DisplayBit for Option<Metadata> {
// fn display_bit(&self, opts: &Args, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// let Some(attrs) = self else {
// write!(f, "--------- {:<12}", "???")?;
// if opts.inodes {
// write!(f, " {:<8}", "---")?;
// }
//
// return Ok(());
// };
//
// let mode = attrs.mode_ext();
// write!(f, "{} {:>12}", mode, attrs.len().display_size_with(opts))?;
// if opts.inodes {
// if let Some(ino) = attrs.inode() {
// write!(f, " {:>8}", ino)?;
// } else {
// write!(f, " {:>8}", "---")?;
// }
// }
//
// Ok(())
// }
// }
//
// #[cfg(unix)]
// impl DisplayBit for Option<Metadata> {
// fn display_bit(&self, opts: &Args, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// use sysutils::unix::FileMode;
//
// let Some(attrs) = self else {
// return write!(f, "--------- {:<8}", "???");
// };
//
// let mode = FileMode::from(attrs.mode());
// write!(f, "{} {:>8}", mode, attrs.len().display_size_with(opts))
// }
// }
impl DisplayBit for Entry {
fn display_bit(&self, opts: &Args, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let ino = self.attrs.as_ref().and_then(MetadataExt::inode);
// let ino = self.attrs.as_ref().and_then(<Metadata as MetadataExt>::inode);
if opts.long {
write!(
@ -163,6 +272,7 @@ impl DisplayBit for Entry {
Ok(())
} else {
let ino = self.attrs.as_ref().and_then(<Metadata as MetadataImpl>::inode);
if opts.inodes {
if let Some(ino) = ino {
write!(f, "{ino:<8} ")?;