mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 09:53:24 +00:00
Add Debug support for some fs components
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
acfbc7efdc
commit
55267f0d81
@ -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
|
||||
pub enum DeviceType {
|
||||
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 {
|
||||
fn into(self) -> u64 {
|
||||
self.0
|
||||
|
@ -13,6 +13,7 @@ lazy_static! {
|
||||
static ref ROOT_MOUNT: Arc<MountNode> = MountNode::new_root(RamFS::new(true)).unwrap();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FsResolver {
|
||||
root: Arc<Dentry>,
|
||||
cwd: Arc<Dentry>,
|
||||
|
@ -13,6 +13,7 @@ use crate::fs::utils::{
|
||||
use crate::prelude::*;
|
||||
use jinux_rights::Rights;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InodeHandle<R = Rights>(Arc<InodeHandle_>, R);
|
||||
|
||||
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
|
||||
impl<R> InodeHandle<R> {
|
||||
pub fn dentry(&self) -> &Arc<Dentry> {
|
||||
|
@ -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.
|
||||
///
|
||||
/// 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.
|
||||
#[derive(Clone, Hash, PartialOrd, Ord, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Hash, PartialOrd, Ord, Eq, PartialEq)]
|
||||
pub struct DentryKey {
|
||||
name: String,
|
||||
parent_ptr: usize,
|
||||
|
@ -62,3 +62,12 @@ impl dyn FileSystem {
|
||||
(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()
|
||||
}
|
||||
}
|
||||
|
@ -324,3 +324,12 @@ impl dyn Inode {
|
||||
(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()
|
||||
}
|
||||
}
|
||||
|
@ -119,3 +119,13 @@ impl MountNode {
|
||||
&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()
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
pages: Mutex<LruCache<usize, Page>>,
|
||||
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 {
|
||||
fn commit_page(&self, offset: usize) -> Result<VmFrame> {
|
||||
let page_idx = offset / PAGE_SIZE;
|
||||
@ -104,6 +121,7 @@ impl Pager for PageCacheManager {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Page {
|
||||
frame: VmFrame,
|
||||
state: PageState,
|
||||
@ -148,6 +166,7 @@ impl Page {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum PageState {
|
||||
/// `Uninit` indicates a new allocated page which content has not been initialized.
|
||||
/// The page is available to write, not available to read.
|
||||
|
@ -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> {
|
||||
inner: &'a Vnode,
|
||||
offset: usize,
|
||||
|
Reference in New Issue
Block a user