Add Debug support for some fs components

This commit is contained in:
LI Qing
2023-08-04 12:00:22 +08:00
committed by Tate, Hongliang Tian
parent acfbc7efdc
commit 55267f0d81
10 changed files with 100 additions and 1 deletions

View File

@ -29,6 +29,16 @@ pub trait Device: Sync + Send {
} }
} }
impl Debug for dyn Device {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Device")
.field("type", &self.type_())
.field("id", &self.id())
.finish()
}
}
#[derive(Debug)]
/// Device type /// Device type
pub enum DeviceType { pub enum DeviceType {
CharDevice, CharDevice,
@ -59,6 +69,15 @@ impl DeviceId {
} }
} }
impl Debug for DeviceId {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("DeviceId")
.field("major", &self.major())
.field("minor", &self.minor())
.finish()
}
}
impl Into<u64> for DeviceId { impl Into<u64> for DeviceId {
fn into(self) -> u64 { fn into(self) -> u64 {
self.0 self.0

View File

@ -13,6 +13,7 @@ lazy_static! {
static ref ROOT_MOUNT: Arc<MountNode> = MountNode::new_root(RamFS::new(true)).unwrap(); static ref ROOT_MOUNT: Arc<MountNode> = MountNode::new_root(RamFS::new(true)).unwrap();
} }
#[derive(Debug)]
pub struct FsResolver { pub struct FsResolver {
root: Arc<Dentry>, root: Arc<Dentry>,
cwd: Arc<Dentry>, cwd: Arc<Dentry>,

View File

@ -13,6 +13,7 @@ use crate::fs::utils::{
use crate::prelude::*; use crate::prelude::*;
use jinux_rights::Rights; use jinux_rights::Rights;
#[derive(Debug)]
pub struct InodeHandle<R = Rights>(Arc<InodeHandle_>, R); pub struct InodeHandle<R = Rights>(Arc<InodeHandle_>, R);
struct InodeHandle_ { struct InodeHandle_ {
@ -119,6 +120,17 @@ impl InodeHandle_ {
} }
} }
impl Debug for InodeHandle_ {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("InodeHandle_")
.field("dentry", &self.dentry)
.field("offset", &self.offset())
.field("access_mode", &self.access_mode())
.field("status_flags", &self.status_flags())
.finish()
}
}
/// Methods for both dyn and static /// Methods for both dyn and static
impl<R> InodeHandle<R> { impl<R> InodeHandle<R> {
pub fn dentry(&self) -> &Arc<Dentry> { pub fn dentry(&self) -> &Arc<Dentry> {

View File

@ -474,11 +474,21 @@ impl Dentry {
} }
} }
impl Debug for Dentry {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Dentry")
.field("abs_path", &self.abs_path())
.field("vnode", &self.vnode)
.field("flags", &self.flags())
.finish()
}
}
/// DentryKey is the unique identifier for Dentry in DCACHE. /// DentryKey is the unique identifier for Dentry in DCACHE.
/// ///
/// For none-root dentries, it uses self's name and parent's pointer to form the key, /// For none-root dentries, it uses self's name and parent's pointer to form the key,
/// meanwhile, the root dentry uses "/" and self's pointer to form the key. /// meanwhile, the root dentry uses "/" and self's pointer to form the key.
#[derive(Clone, Hash, PartialOrd, Ord, Eq, PartialEq)] #[derive(Debug, Clone, Hash, PartialOrd, Ord, Eq, PartialEq)]
pub struct DentryKey { pub struct DentryKey {
name: String, name: String,
parent_ptr: usize, parent_ptr: usize,

View File

@ -62,3 +62,12 @@ impl dyn FileSystem {
(self as &dyn Any).downcast_ref::<T>() (self as &dyn Any).downcast_ref::<T>()
} }
} }
impl Debug for dyn FileSystem {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("FileSystem")
.field("super_block", &self.sb())
.field("flags", &self.flags())
.finish()
}
}

View File

@ -324,3 +324,12 @@ impl dyn Inode {
(self as &dyn Any).downcast_ref::<T>() (self as &dyn Any).downcast_ref::<T>()
} }
} }
impl Debug for dyn Inode {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Inode")
.field("metadata", &self.metadata())
.field("fs", &self.fs())
.finish()
}
}

View File

@ -119,3 +119,13 @@ impl MountNode {
&self.fs &self.fs
} }
} }
impl Debug for MountNode {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("MountNode")
.field("root", &self.root_dentry)
.field("mountpoint", &self.mountpoint_dentry)
.field("fs", &self.fs)
.finish()
}
}

View File

@ -34,6 +34,15 @@ impl PageCache {
} }
} }
impl Debug for PageCache {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("PageCache")
.field("size", &self.pages.size())
.field("mamager", &self.manager)
.finish()
}
}
struct PageCacheManager { struct PageCacheManager {
pages: Mutex<LruCache<usize, Page>>, pages: Mutex<LruCache<usize, Page>>,
backed_inode: Weak<dyn Inode>, backed_inode: Weak<dyn Inode>,
@ -48,6 +57,14 @@ impl PageCacheManager {
} }
} }
impl Debug for PageCacheManager {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("PageCacheManager")
.field("pages", &self.pages.lock())
.finish()
}
}
impl Pager for PageCacheManager { impl Pager for PageCacheManager {
fn commit_page(&self, offset: usize) -> Result<VmFrame> { fn commit_page(&self, offset: usize) -> Result<VmFrame> {
let page_idx = offset / PAGE_SIZE; let page_idx = offset / PAGE_SIZE;
@ -104,6 +121,7 @@ impl Pager for PageCacheManager {
} }
} }
#[derive(Debug)]
struct Page { struct Page {
frame: VmFrame, frame: VmFrame,
state: PageState, state: PageState,
@ -148,6 +166,7 @@ impl Page {
} }
} }
#[derive(Debug)]
enum PageState { enum PageState {
/// `Uninit` indicates a new allocated page which content has not been initialized. /// `Uninit` indicates a new allocated page which content has not been initialized.
/// The page is available to write, not available to read. /// The page is available to write, not available to read.

View File

@ -255,6 +255,15 @@ impl Vnode {
} }
} }
impl Debug for Vnode {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Vnode")
.field("inode", &self.inner.read().inode)
.field("page_cache", &self.inner.read().page_cache)
.finish()
}
}
pub struct VnodeWriter<'a> { pub struct VnodeWriter<'a> {
inner: &'a Vnode, inner: &'a Vnode,
offset: usize, offset: usize,

View File

@ -15,6 +15,7 @@ pub(crate) use alloc::vec::Vec;
pub(crate) use bitflags::bitflags; pub(crate) use bitflags::bitflags;
pub(crate) use core::any::Any; pub(crate) use core::any::Any;
pub(crate) use core::ffi::CStr; pub(crate) use core::ffi::CStr;
pub(crate) use core::fmt::Debug;
pub(crate) use int_to_c_enum::TryFromInt; pub(crate) use int_to_c_enum::TryFromInt;
pub(crate) use jinux_frame::config::PAGE_SIZE; pub(crate) use jinux_frame::config::PAGE_SIZE;
// pub(crate) use jinux_frame::sync::{Mutex, MutexGuard}; // pub(crate) use jinux_frame::sync::{Mutex, MutexGuard};