From c798b2bdb2c9ed9cbf0a4115a69d886c4e938b7d Mon Sep 17 00:00:00 2001 From: Szymon Walter Date: Mon, 19 Mar 2018 20:38:32 +0100 Subject: [PATCH] add Debug `impl`s --- src/sys/block_group.rs | 14 ++++++++++++ src/sys/inode.rs | 29 +++++++++++++++++++++++++ src/sys/superblock.rs | 49 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/src/sys/block_group.rs b/src/sys/block_group.rs index 4e5e65d..a856fbf 100644 --- a/src/sys/block_group.rs +++ b/src/sys/block_group.rs @@ -1,4 +1,5 @@ use core::mem; +use core::fmt::{self, Debug}; use alloc::Vec; @@ -36,6 +37,19 @@ pub struct BlockGroupDescriptor { _reserved: [u8; 14], } +impl Debug for BlockGroupDescriptor { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("BlockGroupDescriptor") + .field("block_usage_addr", unsafe { &self.block_usage_addr }) + .field("inode_usage_addr", unsafe { &self.inode_usage_addr }) + .field("inode_table_block", unsafe { &self.inode_table_block }) + .field("free_blocks_count", unsafe { &self.free_blocks_count }) + .field("free_inodes_count", unsafe { &self.free_inodes_count }) + .field("dirs_count", unsafe { &self.dirs_count }) + .finish() + } +} + impl BlockGroupDescriptor { pub unsafe fn find_descriptor<'a, E>( haystack: &'a Buffer, diff --git a/src/sys/inode.rs b/src/sys/inode.rs index d391227..f40015f 100644 --- a/src/sys/inode.rs +++ b/src/sys/inode.rs @@ -1,4 +1,5 @@ use core::mem; +use core::fmt::{self, Debug}; use error::Error; use buffer::Buffer; @@ -66,6 +67,34 @@ pub struct Inode { pub _os_specific_2: [u8; 12], } +impl Debug for Inode { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Inode") + .field("type_perm", unsafe { &self.type_perm }) + .field("uid", unsafe { &self.uid }) + .field("size_low", unsafe { &self.size_low }) + .field("atime", unsafe { &self.atime }) + .field("ctime", unsafe { &self.ctime }) + .field("mtime", unsafe { &self.mtime }) + .field("dtime", unsafe { &self.dtime }) + .field("gid", unsafe { &self.gid }) + .field("hard_links", unsafe { &self.hard_links }) + .field("sectors_count", unsafe { &self.sectors_count }) + .field("flags", unsafe { &self.flags }) + .field("os_specific_1", &self._os_specific_1) + .field("direct_pointer", unsafe { &self.direct_pointer }) + .field("indirect_pointer", unsafe { &self.indirect_pointer }) + .field("doubly_indirect", unsafe { &self.doubly_indirect }) + .field("triply_indirect", unsafe { &self.triply_indirect }) + .field("gen_number", unsafe { &self.gen_number }) + .field("ext_attribute_block", unsafe { &self.ext_attribute_block }) + .field("size_high", unsafe { &self.size_high }) + .field("frag_block_addr", unsafe { &self.frag_block_addr }) + .field("os_specific_2", &self._os_specific_2) + .finish() + } +} + impl Inode { pub unsafe fn find_inode<'a, E>( haystack: &'a Buffer, diff --git a/src/sys/superblock.rs b/src/sys/superblock.rs index 3d16b05..e1ab61d 100644 --- a/src/sys/superblock.rs +++ b/src/sys/superblock.rs @@ -1,4 +1,5 @@ use core::mem; +use core::fmt::{self, Debug}; use error::Error; use buffer::Buffer; @@ -144,6 +145,54 @@ pub struct Superblock { _reserved: [u8; 788], } +impl Debug for Superblock { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Superblock") + .field("inodes_count", unsafe { &self.inodes_count }) + .field("blocks_count", unsafe { &self.blocks_count }) + .field("r_blocks_count", unsafe { &self.r_blocks_count }) + .field("free_blocks_count", unsafe { &self.free_blocks_count }) + .field("free_inodes_count", unsafe { &self.free_inodes_count }) + .field("first_data_block", unsafe { &self.first_data_block }) + .field("log_block_size", unsafe { &self.log_block_size }) + .field("log_frag_size", unsafe { &self.log_frag_size }) + .field("blocks_per_group", unsafe { &self.blocks_per_group }) + .field("frags_per_group", unsafe { &self.frags_per_group }) + .field("inodes_per_group", unsafe { &self.inodes_per_group }) + .field("mtime", unsafe { &self.mtime }) + .field("wtime", unsafe { &self.wtime }) + .field("mnt_count", unsafe { &self.mnt_count }) + .field("max_mnt_count", unsafe { &self.max_mnt_count }) + .field("magic", unsafe { &self.magic }) + .field("state", unsafe { &self.state }) + .field("errors", unsafe { &self.errors }) + .field("rev_minor", unsafe { &self.rev_minor }) + .field("lastcheck", unsafe { &self.lastcheck }) + .field("checkinterval", unsafe { &self.checkinterval }) + .field("creator_os", unsafe { &self.creator_os }) + .field("rev_major", unsafe { &self.rev_major }) + .field("block_uid", unsafe { &self.block_uid }) + .field("block_gid", unsafe { &self.block_gid }) + .field("first_inode", unsafe { &self.first_inode }) + .field("inode_size", unsafe { &self.inode_size }) + .field("block_group", unsafe { &self.block_group }) + .field("features_opt", unsafe { &self.features_opt }) + .field("features_req", unsafe { &self.features_req }) + .field("features_ronly", unsafe { &self.features_ronly }) + .field("fs_id", &self.fs_id) + .field("volume_name", &self.volume_name) + .field("last_mnt_path", &self.last_mnt_path.as_ref()) + .field("compression", unsafe { &self.compression }) + .field("prealloc_blocks_files", &self.prealloc_blocks_files) + .field("prealloc_blocks_dirs", &self.prealloc_blocks_dirs) + .field("journal_id", &self.journal_id) + .field("journal_inode", unsafe { &self.journal_inode }) + .field("journal_dev", unsafe { &self.journal_dev }) + .field("journal_orphan_head", unsafe { &self.journal_orphan_head }) + .finish() + } +} + impl Superblock { pub unsafe fn find<'a, E>( haystack: &'a Buffer,