Преглед изворни кода

refactor: rename structs and funcs

liujingx пре 11 месеци
родитељ
комит
808eaaa357

+ 10 - 10
src/ext4/alloc.rs

@@ -7,7 +7,7 @@ impl Ext4 {
     /// Allocate a new data block for an inode, return the physical block number
     pub(super) fn alloc_block(
         &mut self,
-        inode_ref: &mut Ext4InodeRef,
+        inode_ref: &mut InodeRef,
         goal: PBlockId,
     ) -> Result<PBlockId> {
         let bgid = goal / self.super_block.blocks_per_group() as u64;
@@ -15,7 +15,7 @@ impl Ext4 {
 
         // Load block group descriptor
         let mut bg =
-            Ext4BlockGroupDesc::load(self.block_device.clone(), &self.super_block, bgid as usize)
+            BlockGroupDesc::load(self.block_device.clone(), &self.super_block, bgid as usize)
                 .unwrap();
         let block_bmap_offset = bg.get_block_bitmap_block(&self.super_block) as usize * BLOCK_SIZE;
         // Load block bitmap
@@ -54,7 +54,7 @@ impl Ext4 {
     /// Append a data block for an inode, return a pair of (logical block id, physical block id)
     pub(super) fn inode_append_block(
         &mut self,
-        inode_ref: &mut Ext4InodeRef,
+        inode_ref: &mut InodeRef,
     ) -> Result<(LBlockId, PBlockId)> {
         let inode_size = inode_ref.inode.size();
         // The new logical block id
@@ -68,14 +68,14 @@ impl Ext4 {
     }
 
     /// Allocate(initialize) the root inode of the file system
-    pub(super) fn alloc_root_inode(&mut self) -> Result<Ext4InodeRef> {
-        let mut inode = Ext4Inode::default();
+    pub(super) fn alloc_root_inode(&mut self) -> Result<InodeRef> {
+        let mut inode = Inode::default();
         inode.set_mode(0o777 | EXT4_INODE_MODE_DIRECTORY);
         inode.extent_init();
         if self.super_block.inode_size() > EXT4_GOOD_OLD_INODE_SIZE {
             inode.set_extra_isize(self.super_block.extra_size());
         }
-        let mut root = Ext4InodeRef::new(EXT4_ROOT_INO, inode);
+        let mut root = InodeRef::new(EXT4_ROOT_INO, inode);
         let root_self = root.clone();
 
         // Add `.` and `..` entries
@@ -88,13 +88,13 @@ impl Ext4 {
     }
 
     /// Allocate a new inode in the file system, returning the inode and its number
-    pub(super) fn alloc_inode(&mut self, filetype: FileType) -> Result<Ext4InodeRef> {
+    pub(super) fn alloc_inode(&mut self, filetype: FileType) -> Result<InodeRef> {
         // Allocate an inode
         let is_dir = filetype == FileType::Directory;
         let id = self.do_alloc_inode(is_dir)?;
 
         // Initialize the inode
-        let mut inode = Ext4Inode::default();
+        let mut inode = Inode::default();
         let mode = if filetype == FileType::Directory {
             0o777 | EXT4_INODE_MODE_DIRECTORY
         } else if filetype == FileType::SymLink {
@@ -107,7 +107,7 @@ impl Ext4 {
         if self.super_block.inode_size() > EXT4_GOOD_OLD_INODE_SIZE {
             inode.set_extra_isize(self.super_block.extra_size());
         }
-        let mut inode_ref = Ext4InodeRef::new(id, inode);
+        let mut inode_ref = InodeRef::new(id, inode);
 
         // Sync the inode to disk
         self.write_back_inode_with_csum(&mut inode_ref);
@@ -123,7 +123,7 @@ impl Ext4 {
 
         while bgid <= bg_count {
             // Load block group descriptor
-            let mut bg = Ext4BlockGroupDesc::load(
+            let mut bg = BlockGroupDesc::load(
                 self.block_device.clone(),
                 &self.super_block,
                 bgid as usize,

+ 22 - 24
src/ext4/dir.rs

@@ -5,7 +5,7 @@ use crate::prelude::*;
 
 impl Ext4 {
     /// Find a directory entry that matches a given name under a parent directory
-    pub(super) fn dir_find_entry(&self, parent: &Ext4InodeRef, name: &str) -> Result<Ext4DirEntry> {
+    pub(super) fn dir_find_entry(&self, parent: &InodeRef, name: &str) -> Result<DirEntry> {
         info!("Dir find entry: {} under parent {}", name, parent.inode_id);
         let inode_size: u32 = parent.inode.size;
         let total_blocks: u32 = inode_size / BLOCK_SIZE as u32;
@@ -28,12 +28,10 @@ impl Ext4 {
     }
 
     /// Find a directory entry that matches a given name in a given block
-    ///
-    /// Save the result in `Ext4DirSearchResult`
-    fn find_entry_in_block(block_data: &[u8], name: &str) -> Result<Ext4DirEntry> {
+    fn find_entry_in_block(block_data: &[u8], name: &str) -> Result<DirEntry> {
         let mut offset = 0;
         while offset < block_data.len() {
-            let de = Ext4DirEntry::from_bytes(&block_data[offset..]);
+            let de = DirEntry::from_bytes(&block_data[offset..]);
             offset += de.rec_len() as usize;
             // Unused dir entry
             if de.unused() {
@@ -50,8 +48,8 @@ impl Ext4 {
     /// Add an entry to a directory
     pub(super) fn dir_add_entry(
         &mut self,
-        parent: &mut Ext4InodeRef,
-        child: &Ext4InodeRef,
+        parent: &mut InodeRef,
+        child: &InodeRef,
         path: &str,
     ) -> Result<()> {
         info!(
@@ -68,7 +66,7 @@ impl Ext4 {
             let fblock = self.extent_get_pblock_create(parent, iblock, 1)?;
             // Load the parent block from disk
             let mut data = self.block_device.read_offset(fblock as usize * BLOCK_SIZE);
-            let mut ext4_block = Ext4Block {
+            let mut ext4_block = Block {
                 pblock_id: fblock,
                 block_data: &mut data,
             };
@@ -84,7 +82,7 @@ impl Ext4 {
         // Load new block
         let block_device = self.block_device.clone();
         let mut data = block_device.read_offset(fblock as usize * BLOCK_SIZE);
-        let mut new_block = Ext4Block {
+        let mut new_block = Block {
             pblock_id: fblock,
             block_data: &mut data,
         };
@@ -96,13 +94,13 @@ impl Ext4 {
     /// A new block must have enough space
     fn insert_entry_to_new_block(
         &self,
-        dst_blk: &mut Ext4Block,
-        child: &Ext4InodeRef,
+        dst_blk: &mut Block,
+        child: &InodeRef,
         name: &str,
     ) -> Result<()> {
         // Set the entry
-        let rec_len = BLOCK_SIZE - size_of::<Ext4DirEntryTail>();
-        let new_entry = Ext4DirEntry::new(
+        let rec_len = BLOCK_SIZE - size_of::<DirEntryTail>();
+        let new_entry = DirEntry::new(
             child.inode_id,
             rec_len as u16,
             name,
@@ -113,12 +111,12 @@ impl Ext4 {
         new_entry.copy_to_byte_slice(&mut dst_blk.block_data, 0);
 
         // Set tail
-        let mut tail = Ext4DirEntryTail::default();
-        tail.rec_len = size_of::<Ext4DirEntryTail>() as u16;
+        let mut tail = DirEntryTail::default();
+        tail.rec_len = size_of::<DirEntryTail>() as u16;
         tail.reserved_ft = 0xDE;
         tail.set_csum(&self.super_block, &new_entry, &dst_blk.block_data[..]);
         // Copy tail to block
-        let tail_offset = BLOCK_SIZE - size_of::<Ext4DirEntryTail>();
+        let tail_offset = BLOCK_SIZE - size_of::<DirEntryTail>();
         tail.copy_to_byte_slice(&mut dst_blk.block_data, tail_offset);
 
         // Sync block to disk
@@ -130,15 +128,15 @@ impl Ext4 {
     /// Return `ENOSPC` if parent block has no enough space.
     fn insert_entry_to_old_block(
         &self,
-        dst_blk: &mut Ext4Block,
-        child: &Ext4InodeRef,
+        dst_blk: &mut Block,
+        child: &InodeRef,
         name: &str,
     ) -> Result<()> {
-        let required_size = Ext4DirEntry::required_size(name.len());
+        let required_size = DirEntry::required_size(name.len());
         let mut offset = 0;
 
         while offset < dst_blk.block_data.len() {
-            let mut de = Ext4DirEntry::from_bytes(&dst_blk.block_data[offset..]);
+            let mut de = DirEntry::from_bytes(&dst_blk.block_data[offset..]);
             let rec_len = de.rec_len() as usize;
 
             // Try splitting dir entry
@@ -158,7 +156,7 @@ impl Ext4 {
             de.set_rec_len(used_size as u16);
             de.copy_to_byte_slice(&mut dst_blk.block_data, offset);
             // Insert the new entry
-            let new_entry = Ext4DirEntry::new(
+            let new_entry = DirEntry::new(
                 child.inode_id,
                 free_size as u16,
                 name,
@@ -168,10 +166,10 @@ impl Ext4 {
 
             // Set tail csum
             let mut tail =
-                Ext4DirEntryTail::from_bytes(&mut dst_blk.block_data, BLOCK_SIZE).unwrap();
+                DirEntryTail::from_bytes(&mut dst_blk.block_data, BLOCK_SIZE).unwrap();
             tail.set_csum(&self.super_block, &de, &dst_blk.block_data[offset..]);
             // Write tail to blk_data
-            let tail_offset = BLOCK_SIZE - size_of::<Ext4DirEntryTail>();
+            let tail_offset = BLOCK_SIZE - size_of::<DirEntryTail>();
             tail.copy_to_byte_slice(&mut dst_blk.block_data, tail_offset);
 
             // Sync to disk
@@ -182,7 +180,7 @@ impl Ext4 {
     }
 
     /// Create a new directory. `path` is the absolute path of the new directory.
-    pub fn ext4_dir_mk(&mut self, path: &str) -> Result<()> {
+    pub fn mkdir(&mut self, path: &str) -> Result<()> {
         // get open flags
         let iflags = OpenFlags::from_str("w").unwrap();
         self.generic_open(

+ 4 - 4
src/ext4/extent.rs

@@ -6,7 +6,7 @@ use core::cmp::min;
 
 impl Ext4 {
     /// Find the given logic block id in the extent tree, return the search path
-    fn find_extent(&self, inode_ref: &Ext4InodeRef, iblock: LBlockId) -> Vec<ExtentSearchPath> {
+    fn find_extent(&self, inode_ref: &InodeRef, iblock: LBlockId) -> Vec<ExtentSearchPath> {
         let mut path: Vec<ExtentSearchPath> = Vec::new();
         let mut ex_node = inode_ref.inode.extent();
         ex_node.print();
@@ -44,7 +44,7 @@ impl Ext4 {
     /// Return 0 if not found.
     pub(super) fn extent_get_pblock(
         &self,
-        inode_ref: &Ext4InodeRef,
+        inode_ref: &InodeRef,
         iblock: LBlockId,
     ) -> Result<PBlockId> {
         let path = self.find_extent(inode_ref, iblock);
@@ -75,7 +75,7 @@ impl Ext4 {
     /// Create a new extent if not found.
     pub(super) fn extent_get_pblock_create(
         &mut self,
-        inode_ref: &mut Ext4InodeRef,
+        inode_ref: &mut InodeRef,
         iblock: LBlockId,
         block_count: u32,
     ) -> Result<PBlockId> {
@@ -119,7 +119,7 @@ impl Ext4 {
     /// the node needs to be split.
     pub(super) fn insert_extent(
         &self,
-        inode_ref: &mut Ext4InodeRef,
+        inode_ref: &mut InodeRef,
         leaf: &ExtentSearchPath,
         new_ext: &Ext4Extent,
     ) -> bool {

+ 11 - 13
src/ext4/file.rs

@@ -16,8 +16,8 @@ impl Ext4 {
         path: &str,
         flag: OpenFlags,
         ftype: FileType,
-        parent_inode: &Ext4InodeRef,
-    ) -> Result<Ext4File> {
+        parent_inode: &InodeRef,
+    ) -> Result<File> {
         info!("generic open: {}", path);
         // Search from the given parent inode
         let mut parent = parent_inode.clone();
@@ -44,7 +44,7 @@ impl Ext4 {
                         self.alloc_inode(FileType::Directory)
                     }?;
                     // Link the new inode
-                    self.ext4_link(&mut parent, &mut child, path)
+                    self.link(&mut parent, &mut child, path)
                         .map_err(|_| Ext4Error::with_message(ErrCode::ELINKFIAL, "link fail"))?;
                     // Write back parent and child
                     self.write_back_inode_with_csum(&mut parent);
@@ -53,13 +53,12 @@ impl Ext4 {
             }
         }
         // Reach the target
-        let mut file = Ext4File::default();
+        let mut file = File::default();
         file.inode = parent.inode_id;
         Ok(file)
     }
 
-    #[allow(unused)]
-    pub fn ext4_open(&mut self, path: &str, flags: &str, file_expect: bool) -> Result<Ext4File> {
+    pub fn open(&mut self, path: &str, flags: &str, file_expect: bool) -> Result<File> {
         // open flags
         let iflags = OpenFlags::from_str(flags).unwrap();
         // file type
@@ -70,22 +69,21 @@ impl Ext4 {
         };
         // TODO:journal
         if iflags.contains(OpenFlags::O_CREAT) {
-            self.ext4_trans_start();
+            self.trans_start();
         }
         // open file
         let res = self.generic_open(path, iflags, file_type, &self.get_root_inode_ref());
         res.map(|mut file| {
             // set mount point
             let mut ptr = Box::new(self.mount_point.clone());
-            file.mp = Box::as_mut(&mut ptr) as *mut Ext4MountPoint;
+            file.mp = Box::as_mut(&mut ptr) as *mut MountPoint;
             file
         })
     }
 
-    #[allow(unused)]
-    pub fn ext4_file_read(
+    pub fn read(
         &self,
-        file: &mut Ext4File,
+        file: &mut File,
         read_buf: &mut [u8],
         read_size: usize,
     ) -> Result<usize> {
@@ -109,7 +107,7 @@ impl Ext4 {
         // Calc the start block of reading
         let start_iblock = (file.fpos / BLOCK_SIZE) as LBlockId;
         // Calc the length that is not aligned to the block size
-        let mut misaligned = file.fpos % BLOCK_SIZE;
+        let misaligned = file.fpos % BLOCK_SIZE;
 
         let mut cursor = 0;
         let mut iblock = start_iblock;
@@ -151,7 +149,7 @@ impl Ext4 {
         Ok(cursor)
     }
 
-    pub fn ext4_file_write(&mut self, file: &mut Ext4File, data: &[u8]) -> Result<()> {
+    pub fn write(&mut self, file: &mut File, data: &[u8]) -> Result<()> {
         let size = data.len();
         let mut inode_ref = self.get_inode_ref(file.inode);
         // Sync ext file

+ 2 - 2
src/ext4/journal.rs

@@ -2,9 +2,9 @@ use super::Ext4;
 
 impl Ext4 {
     /// start transaction
-    pub(super) fn ext4_trans_start(&self) {}
+    pub(super) fn trans_start(&self) {}
 
     /// stop transaction
     #[allow(unused)]
-    pub(super) fn ext4_trans_abort(&self) {}
+    pub(super) fn trans_abort(&self) {}
 }

+ 3 - 3
src/ext4/link.rs

@@ -3,10 +3,10 @@ use crate::prelude::*;
 use crate::ext4_defs::*;
 
 impl Ext4 {
-    pub fn ext4_link(
+    pub fn link(
         &mut self,
-        parent: &mut Ext4InodeRef,
-        child: &mut Ext4InodeRef,
+        parent: &mut InodeRef,
+        child: &mut InodeRef,
         name: &str,
     ) -> Result<()> {
         // Add entry to parent directory

+ 10 - 10
src/ext4/mod.rs

@@ -12,8 +12,8 @@ mod link;
 #[derive(Debug)]
 pub struct Ext4 {
     pub block_device: Arc<dyn BlockDevice>,
-    pub super_block: Ext4Superblock,
-    pub mount_point: Ext4MountPoint,
+    pub super_block: Superblock,
+    pub mount_point: MountPoint,
 }
 
 impl Ext4 {
@@ -25,9 +25,9 @@ impl Ext4 {
         // Load the superblock
         // TODO: if the main superblock is corrupted, should we load the backup?
         let raw_data = block_device.read_offset(BASE_OFFSET);
-        let super_block = Ext4Superblock::try_from(raw_data).unwrap();
+        let super_block = Superblock::try_from(raw_data).unwrap();
         // Root mount point
-        let mount_point = Ext4MountPoint::new("/");
+        let mount_point = MountPoint::new("/");
         // Create Ext4 instance
         let mut ext4 = Self {
             super_block,
@@ -39,26 +39,26 @@ impl Ext4 {
         Ok(ext4)
     }
 
-    /// Read an inode from block device, return an`Ext4InodeRef` that combines
+    /// Read an inode from block device, return an `InodeRef` that combines
     /// the inode and its id.
-    fn get_inode_ref(&self, inode_id: InodeId) -> Ext4InodeRef {
-        Ext4InodeRef::read_from_disk(self.block_device.clone(), &self.super_block, inode_id)
+    fn get_inode_ref(&self, inode_id: InodeId) -> InodeRef {
+        InodeRef::read_from_disk(self.block_device.clone(), &self.super_block, inode_id)
     }
 
     /// Read the root inode from block device
-    fn get_root_inode_ref(&self) -> Ext4InodeRef {
+    fn get_root_inode_ref(&self) -> InodeRef {
         self.get_inode_ref(EXT4_ROOT_INO)
     }
 
     /// Write back an inode to block device with checksum
-    fn write_back_inode_with_csum(&self, inode_ref: &mut Ext4InodeRef) {
+    fn write_back_inode_with_csum(&self, inode_ref: &mut InodeRef) {
         inode_ref
             .sync_to_disk_with_csum(self.block_device.clone(), &self.super_block)
             .unwrap()
     }
 
     /// Write back an inode to block device without checksum
-    fn write_back_inode_without_csum(&self, inode_ref: &mut Ext4InodeRef) {
+    fn write_back_inode_without_csum(&self, inode_ref: &mut InodeRef) {
         inode_ref
             .sync_to_disk_without_csum(self.block_device.clone(), &self.super_block)
             .unwrap()

+ 2 - 2
src/ext4_defs/block.rs

@@ -4,14 +4,14 @@ use super::BlockDevice;
 
 #[derive(Debug)]
 // A single block descriptor
-pub struct Ext4Block<'a> {
+pub struct Block<'a> {
     /// Physical block id
     pub pblock_id: PBlockId,
     /// Raw block data
     pub block_data: &'a mut [u8],
 }
 
-impl<'a> Ext4Block<'a> {
+impl<'a> Block<'a> {
     pub fn sync_to_disk(&self, block_device: Arc<dyn BlockDevice>) {
         let block_id = self.pblock_id as usize;
         block_device.write_offset(block_id * BLOCK_SIZE, &self.block_data);

+ 24 - 24
src/ext4_defs/block_group.rs

@@ -10,13 +10,13 @@
 use super::crc::*;
 use super::Bitmap;
 use super::BlockDevice;
-use super::Ext4Superblock;
+use super::Superblock;
 use crate::constants::*;
 use crate::prelude::*;
 
 #[derive(Debug, Default, Clone, Copy)]
 #[repr(C, packed)]
-pub struct Ext4BlockGroupDesc {
+pub struct BlockGroupDesc {
     block_bitmap_lo: u32,            // 块位图块
     inode_bitmap_lo: u32,            // 节点位图块
     inode_table_first_block_lo: u32, // 节点表块
@@ -43,18 +43,18 @@ pub struct Ext4BlockGroupDesc {
     reserved: u32,                   // 填充
 }
 
-impl TryFrom<&[u8]> for Ext4BlockGroupDesc {
+impl TryFrom<&[u8]> for BlockGroupDesc {
     type Error = u64;
     fn try_from(data: &[u8]) -> core::result::Result<Self, u64> {
-        let data = &data[..size_of::<Ext4BlockGroupDesc>()];
+        let data = &data[..size_of::<BlockGroupDesc>()];
         Ok(unsafe { core::ptr::read(data.as_ptr() as *const _) })
     }
 }
 
-impl Ext4BlockGroupDesc {
+impl BlockGroupDesc {
     pub fn load(
         block_device: Arc<dyn BlockDevice>,
-        super_block: &Ext4Superblock,
+        super_block: &Superblock,
         block_group_id: usize,
     ) -> core::result::Result<Self, u64> {
         let dsc_cnt = BLOCK_SIZE / super_block.desc_size() as usize;
@@ -67,14 +67,14 @@ impl Ext4BlockGroupDesc {
         let data = block_device.read_offset(block_id * BLOCK_SIZE);
 
         let block_group_data =
-            &data[offset as usize..offset as usize + size_of::<Ext4BlockGroupDesc>()];
+            &data[offset as usize..offset as usize + size_of::<BlockGroupDesc>()];
 
-        let bg = Ext4BlockGroupDesc::try_from(block_group_data);
+        let bg = BlockGroupDesc::try_from(block_group_data);
 
         bg
     }
 
-    pub fn get_block_bitmap_block(&self, s: &Ext4Superblock) -> u64 {
+    pub fn get_block_bitmap_block(&self, s: &Superblock) -> u64 {
         let mut v = self.block_bitmap_lo as u64;
         let desc_size = s.desc_size();
         if desc_size > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE {
@@ -83,7 +83,7 @@ impl Ext4BlockGroupDesc {
         v
     }
 
-    pub fn get_inode_bitmap_block(&self, s: &Ext4Superblock) -> u64 {
+    pub fn get_inode_bitmap_block(&self, s: &Superblock) -> u64 {
         let mut v = self.inode_bitmap_lo as u64;
         let desc_size = s.desc_size();
         if desc_size > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE {
@@ -92,7 +92,7 @@ impl Ext4BlockGroupDesc {
         v
     }
 
-    pub fn get_itable_unused(&mut self, s: &Ext4Superblock) -> u32 {
+    pub fn get_itable_unused(&mut self, s: &Superblock) -> u32 {
         let mut v = self.itable_unused_lo as u32;
         if s.desc_size() > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE {
             v |= ((self.itable_unused_hi as u64) << 32) as u32;
@@ -100,7 +100,7 @@ impl Ext4BlockGroupDesc {
         v
     }
 
-    pub fn get_used_dirs_count(&self, s: &Ext4Superblock) -> u32 {
+    pub fn get_used_dirs_count(&self, s: &Superblock) -> u32 {
         let mut v = self.used_dirs_count_lo as u32;
         if s.desc_size() > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE {
             v |= ((self.used_dirs_count_hi as u64) << 32) as u32;
@@ -108,21 +108,21 @@ impl Ext4BlockGroupDesc {
         v
     }
 
-    pub fn set_used_dirs_count(&mut self, s: &Ext4Superblock, cnt: u32) {
+    pub fn set_used_dirs_count(&mut self, s: &Superblock, cnt: u32) {
         self.itable_unused_lo = ((cnt << 16) >> 16) as u16;
         if s.desc_size() > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE {
             self.itable_unused_hi = (cnt >> 16) as u16;
         }
     }
 
-    pub fn set_itable_unused(&mut self, s: &Ext4Superblock, cnt: u32) {
+    pub fn set_itable_unused(&mut self, s: &Superblock, cnt: u32) {
         self.itable_unused_lo = ((cnt << 16) >> 16) as u16;
         if s.desc_size() > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE {
             self.itable_unused_hi = (cnt >> 16) as u16;
         }
     }
 
-    pub fn set_free_inodes_count(&mut self, s: &Ext4Superblock, cnt: u32) {
+    pub fn set_free_inodes_count(&mut self, s: &Superblock, cnt: u32) {
         self.free_inodes_count_lo = ((cnt << 16) >> 16) as u16;
         if s.desc_size() > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE {
             self.free_inodes_count_hi = (cnt >> 16) as u16;
@@ -141,7 +141,7 @@ impl Ext4BlockGroupDesc {
         &self,
         block_device: Arc<dyn BlockDevice>,
         bgid: usize,
-        super_block: &Ext4Superblock,
+        super_block: &Superblock,
     ) {
         let dsc_cnt = BLOCK_SIZE / super_block.desc_size() as usize;
         // let dsc_per_block = dsc_cnt;
@@ -154,13 +154,13 @@ impl Ext4BlockGroupDesc {
         let data = unsafe {
             core::slice::from_raw_parts(
                 self as *const _ as *const u8,
-                size_of::<Ext4BlockGroupDesc>(),
+                size_of::<BlockGroupDesc>(),
             )
         };
         block_device.write_offset(block_id * BLOCK_SIZE + offset, data);
     }
 
-    pub fn calc_checksum(&mut self, bgid: u32, super_block: &Ext4Superblock) -> u16 {
+    pub fn calc_checksum(&mut self, bgid: u32, super_block: &Superblock) -> u16 {
         let desc_size = super_block.desc_size();
 
         let orig_checksum = self.checksum;
@@ -192,7 +192,7 @@ impl Ext4BlockGroupDesc {
         crc
     }
 
-    pub fn set_block_group_checksum(&mut self, bgid: u32, super_block: &Ext4Superblock) {
+    pub fn set_block_group_checksum(&mut self, bgid: u32, super_block: &Superblock) {
         let csum = self.calc_checksum(bgid, super_block);
         self.checksum = csum;
     }
@@ -201,13 +201,13 @@ impl Ext4BlockGroupDesc {
         &mut self,
         block_device: Arc<dyn BlockDevice>,
         bgid: usize,
-        super_block: &Ext4Superblock,
+        super_block: &Superblock,
     ) {
         self.set_block_group_checksum(bgid as u32, super_block);
         self.sync_to_disk(block_device, bgid, super_block)
     }
 
-    pub fn set_inode_bitmap_csum(&mut self, s: &Ext4Superblock, bitmap: &Bitmap) {
+    pub fn set_inode_bitmap_csum(&mut self, s: &Superblock, bitmap: &Bitmap) {
         let desc_size = s.desc_size();
 
         let csum = Self::calc_inode_bitmap_csum(&bitmap, s);
@@ -223,7 +223,7 @@ impl Ext4BlockGroupDesc {
         }
     }
 
-    pub fn set_block_bitmap_csum(&mut self, s: &Ext4Superblock, bitmap: &Bitmap) {
+    pub fn set_block_bitmap_csum(&mut self, s: &Superblock, bitmap: &Bitmap) {
         let desc_size = s.desc_size();
 
         let csum = Self::calc_block_bitmap_csum(&bitmap, s);
@@ -252,7 +252,7 @@ impl Ext4BlockGroupDesc {
         self.free_blocks_count_hi = (cnt >> 32) as u16;
     }
 
-    pub fn calc_inode_bitmap_csum(bitmap: &Bitmap, s: &Ext4Superblock) -> u32 {
+    pub fn calc_inode_bitmap_csum(bitmap: &Bitmap, s: &Superblock) -> u32 {
         let inodes_per_group = s.inodes_per_group();
         let uuid = s.uuid();
         let mut csum = ext4_crc32c(EXT4_CRC32_INIT, &uuid, uuid.len() as u32);
@@ -260,7 +260,7 @@ impl Ext4BlockGroupDesc {
         csum
     }
 
-    pub fn calc_block_bitmap_csum(bitmap: &Bitmap, s: &Ext4Superblock) -> u32 {
+    pub fn calc_block_bitmap_csum(bitmap: &Bitmap, s: &Superblock) -> u32 {
         let blocks_per_group = s.blocks_per_group();
         let uuid = s.uuid();
         let mut csum = ext4_crc32c(EXT4_CRC32_INIT, &uuid, uuid.len() as u32);

+ 23 - 23
src/ext4_defs/dir_entry.rs

@@ -4,18 +4,18 @@
 //! linear array of directory entries.
 
 use super::crc::*;
-use super::Ext4Superblock;
+use super::Superblock;
 use crate::constants::*;
 use crate::prelude::*;
 use alloc::string::FromUtf8Error;
 
 #[repr(C)]
-pub union Ext4DirEnInner {
+pub union DirEnInner {
     pub name_length_high: u8, // 高8位的文件名长度
     pub inode_type: FileType, // 引用的inode的类型(在rev >= 0.5中)
 }
 
-impl Debug for Ext4DirEnInner {
+impl Debug for DirEnInner {
     fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
         unsafe {
             write!(
@@ -27,7 +27,7 @@ impl Debug for Ext4DirEnInner {
     }
 }
 
-impl Default for Ext4DirEnInner {
+impl Default for DirEnInner {
     fn default() -> Self {
         Self {
             name_length_high: 0,
@@ -37,27 +37,27 @@ impl Default for Ext4DirEnInner {
 
 #[repr(C)]
 #[derive(Debug)]
-pub struct Ext4DirEntry {
+pub struct DirEntry {
     inode: InodeId,        // 该目录项指向的inode的编号
     rec_len: u16,          // 到下一个目录项的距离
     name_len: u8,          // 低8位的文件名长度
-    inner: Ext4DirEnInner, // 联合体成员
+    inner: DirEnInner, // 联合体成员
     name: [u8; 255],       // 文件名
 }
 
-impl Default for Ext4DirEntry {
+impl Default for DirEntry {
     fn default() -> Self {
         Self {
             inode: 0,
             rec_len: 0,
             name_len: 0,
-            inner: Ext4DirEnInner::default(),
+            inner: DirEnInner::default(),
             name: [0; 255],
         }
     }
 }
 
-impl Ext4DirEntry {
+impl DirEntry {
     /// Create a new directory entry
     pub fn new(inode: InodeId, rec_len: u16, name: &str, dirent_type: FileType) -> Self {
         let mut name_bytes = [0u8; 255];
@@ -67,7 +67,7 @@ impl Ext4DirEntry {
             inode,
             rec_len,
             name_len: name_len as u8,
-            inner: Ext4DirEnInner {
+            inner: DirEnInner {
                 inode_type: dirent_type,
             },
             name: name_bytes,
@@ -124,7 +124,7 @@ impl Ext4DirEntry {
     /// Get the required size to save this directory entry, 4-byte aligned
     pub fn required_size(name_len: usize) -> usize {
         // u32 + u16 + u8 + Ext4DirEnInner + name -> align to 4
-        (core::mem::size_of::<Ext4FakeDirEntry>() + name_len + 3) / 4 * 4
+        (core::mem::size_of::<FakeDirEntry>() + name_len + 3) / 4 * 4
     }
 
     /// Get the used size of this directory entry, 4-bytes alighed
@@ -132,7 +132,7 @@ impl Ext4DirEntry {
         Self::required_size(self.name_len as usize)
     }
 
-    pub fn calc_csum(&self, s: &Ext4Superblock, blk_data: &[u8]) -> u32 {
+    pub fn calc_csum(&self, s: &Superblock, blk_data: &[u8]) -> u32 {
         let ino_index = self.inode;
         let ino_gen = 0 as u32;
 
@@ -150,9 +150,9 @@ impl Ext4DirEntry {
     }
 
     pub fn copy_to_byte_slice(&self, slice: &mut [u8], offset: usize) {
-        let de_ptr = self as *const Ext4DirEntry as *const u8;
+        let de_ptr = self as *const DirEntry as *const u8;
         let slice_ptr = slice as *mut [u8] as *mut u8;
-        let count = core::mem::size_of::<Ext4DirEntry>();
+        let count = core::mem::size_of::<DirEntry>();
         unsafe {
             core::ptr::copy_nonoverlapping(de_ptr, slice_ptr.add(offset), count);
         }
@@ -161,7 +161,7 @@ impl Ext4DirEntry {
 
 #[repr(C)]
 #[derive(Debug, Clone, Copy, Default)]
-pub struct Ext4DirEntryTail {
+pub struct DirEntryTail {
     pub reserved_zero1: u32,
     pub rec_len: u16,
     pub reserved_zero2: u8,
@@ -169,17 +169,17 @@ pub struct Ext4DirEntryTail {
     pub checksum: u32, // crc32c(uuid+inum+dirblock)
 }
 
-impl Ext4DirEntryTail {
+impl DirEntryTail {
     pub fn from_bytes(data: &mut [u8], blocksize: usize) -> Option<Self> {
         unsafe {
             let ptr = data as *mut [u8] as *mut u8;
-            let t = *(ptr.add(blocksize - core::mem::size_of::<Ext4DirEntryTail>())
-                as *mut Ext4DirEntryTail);
+            let t = *(ptr.add(blocksize - core::mem::size_of::<DirEntryTail>())
+                as *mut DirEntryTail);
             if t.reserved_zero1 != 0 || t.reserved_zero2 != 0 {
                 log::info!("t.reserved_zero1");
                 return None;
             }
-            if t.rec_len.to_le() != core::mem::size_of::<Ext4DirEntryTail>() as u16 {
+            if t.rec_len.to_le() != core::mem::size_of::<DirEntryTail>() as u16 {
                 log::info!("t.rec_len");
                 return None;
             }
@@ -191,14 +191,14 @@ impl Ext4DirEntryTail {
         }
     }
 
-    pub fn set_csum(&mut self, s: &Ext4Superblock, diren: &Ext4DirEntry, blk_data: &[u8]) {
+    pub fn set_csum(&mut self, s: &Superblock, diren: &DirEntry, blk_data: &[u8]) {
         self.checksum = diren.calc_csum(s, blk_data);
     }
 
     pub fn copy_to_byte_slice(&self, slice: &mut [u8], offset: usize) {
-        let de_ptr = self as *const Ext4DirEntryTail as *const u8;
+        let de_ptr = self as *const DirEntryTail as *const u8;
         let slice_ptr = slice as *mut [u8] as *mut u8;
-        let count = core::mem::size_of::<Ext4DirEntryTail>();
+        let count = core::mem::size_of::<DirEntryTail>();
         unsafe {
             core::ptr::copy_nonoverlapping(de_ptr, slice_ptr.add(offset), count);
         }
@@ -207,7 +207,7 @@ impl Ext4DirEntryTail {
 
 /// Fake dir entry. A normal entry without `name` field`
 #[repr(C)]
-pub struct Ext4FakeDirEntry {
+pub struct FakeDirEntry {
     inode: u32,
     entry_length: u16,
     name_length: u8,

+ 23 - 23
src/ext4_defs/extent.rs

@@ -1,14 +1,14 @@
 //! The Defination of Ext4 Extent (Header, Index)
 //!
 //! Extents are arranged as a tree. Each node of the tree begins with a struct
-//! [`Ext4ExtentHeader`].
+//! [`ExtentHeader`].
 //!
 //! If the node is an interior node (eh.depth > 0), the header is followed by
-//! eh.entries_count instances of struct [`Ext4ExtentIndex`]; each of these index
+//! eh.entries_count instances of struct [`ExtentIndex`]; each of these index
 //! entries points to a block containing more nodes in the extent tree.
 //!
 //! If the node is a leaf node (eh.depth == 0), then the header is followed by
-//! eh.entries_count instances of struct [`Ext4Extent`]; these instances point
+//! eh.entries_count instances of struct [`Extent`]; these instances point
 //! to the file's data blocks. The root node of the extent tree is stored in
 //! inode.i_block, which allows for the first four extents to be recorded without
 //! the use of extra metadata blocks.
@@ -18,7 +18,7 @@ use crate::prelude::*;
 
 #[derive(Debug, Default, Clone, Copy)]
 #[repr(C)]
-pub struct Ext4ExtentHeader {
+pub struct ExtentHeader {
     /// Magic number, 0xF30A.
     magic: u16,
 
@@ -40,7 +40,7 @@ pub struct Ext4ExtentHeader {
     generation: u32,
 }
 
-impl Ext4ExtentHeader {
+impl ExtentHeader {
     pub fn new(entries_count: u16, max_entries_count: u16, depth: u16, generation: u32) -> Self {
         Self {
             magic: EXT4_EXTENT_MAGIC,
@@ -53,7 +53,7 @@ impl Ext4ExtentHeader {
 
     /// Loads an extent header from a data block.
     pub fn load_from_block(block_data: &[u8]) -> &Self {
-        unsafe { &*(block_data.as_ptr() as *const Ext4ExtentHeader) }
+        unsafe { &*(block_data.as_ptr() as *const ExtentHeader) }
     }
 
     // 获取extent header的魔数
@@ -109,7 +109,7 @@ impl Ext4ExtentHeader {
 
 #[derive(Debug, Default, Clone, Copy)]
 #[repr(C)]
-pub struct Ext4ExtentIndex {
+pub struct ExtentIndex {
     /// This index node covers file blocks from ‘block’ onward.
     pub first_block: u32,
 
@@ -124,7 +124,7 @@ pub struct Ext4ExtentIndex {
     pub padding: u16,
 }
 
-impl Ext4ExtentIndex {
+impl ExtentIndex {
     /// The physical block number of the extent node that is the next level lower in the tree
     pub fn leaf(&self) -> PBlockId {
         (self.leaf_hi as PBlockId) << 32 | self.leaf_lo as PBlockId
@@ -244,21 +244,21 @@ impl<'a> ExtentNode<'a> {
     }
 
     /// Get a immutable reference to the extent header
-    pub fn header(&self) -> &Ext4ExtentHeader {
-        unsafe { &*(self.raw_data.as_ptr() as *const Ext4ExtentHeader) }
+    pub fn header(&self) -> &ExtentHeader {
+        unsafe { &*(self.raw_data.as_ptr() as *const ExtentHeader) }
     }
 
     /// Get a immutable reference to the extent at a given index
     pub fn extent_at(&self, index: usize) -> &Ext4Extent {
         unsafe {
-            &*((self.header() as *const Ext4ExtentHeader).add(1) as *const Ext4Extent).add(index)
+            &*((self.header() as *const ExtentHeader).add(1) as *const Ext4Extent).add(index)
         }
     }
 
     /// Get a immmutable reference to the extent indexat a given index
-    pub fn extent_index_at(&self, index: usize) -> &Ext4ExtentIndex {
+    pub fn extent_index_at(&self, index: usize) -> &ExtentIndex {
         unsafe {
-            &*((self.header() as *const Ext4ExtentHeader).add(1) as *const Ext4ExtentIndex)
+            &*((self.header() as *const ExtentHeader).add(1) as *const ExtentIndex)
                 .add(index)
         }
     }
@@ -337,42 +337,42 @@ impl<'a> ExtentNodeMut<'a> {
     }
 
     /// Get a immutable reference to the extent header
-    pub fn header(&self) -> &Ext4ExtentHeader {
-        unsafe { &*(self.raw_data.as_ptr() as *const Ext4ExtentHeader) }
+    pub fn header(&self) -> &ExtentHeader {
+        unsafe { &*(self.raw_data.as_ptr() as *const ExtentHeader) }
     }
 
     /// Get a mutable reference to the extent header
-    pub fn header_mut(&mut self) -> &mut Ext4ExtentHeader {
-        unsafe { &mut *(self.raw_data.as_mut_ptr() as *mut Ext4ExtentHeader) }
+    pub fn header_mut(&mut self) -> &mut ExtentHeader {
+        unsafe { &mut *(self.raw_data.as_mut_ptr() as *mut ExtentHeader) }
     }
 
     /// Get a immutable reference to the extent at a given index
     pub fn extent_at(&self, index: usize) -> &'static Ext4Extent {
         unsafe {
-            &*((self.header() as *const Ext4ExtentHeader).add(1) as *const Ext4Extent).add(index)
+            &*((self.header() as *const ExtentHeader).add(1) as *const Ext4Extent).add(index)
         }
     }
 
     /// Get a mutable reference to the extent at a given index
     pub fn extent_mut_at(&mut self, index: usize) -> &'static mut Ext4Extent {
         unsafe {
-            &mut *((self.header_mut() as *mut Ext4ExtentHeader).add(1) as *mut Ext4Extent)
+            &mut *((self.header_mut() as *mut ExtentHeader).add(1) as *mut Ext4Extent)
                 .add(index)
         }
     }
 
     /// Get a immutable reference to the extent index at a given index
-    pub fn extent_index_at(&self, index: usize) -> &'static Ext4ExtentIndex {
+    pub fn extent_index_at(&self, index: usize) -> &'static ExtentIndex {
         unsafe {
-            &*((self.header() as *const Ext4ExtentHeader).add(1) as *const Ext4ExtentIndex)
+            &*((self.header() as *const ExtentHeader).add(1) as *const ExtentIndex)
                 .add(index)
         }
     }
 
     /// Get a mutable reference to the extent index at a given index
-    pub fn extent_index_mut_at(&mut self, index: usize) -> &'static mut Ext4ExtentIndex {
+    pub fn extent_index_mut_at(&mut self, index: usize) -> &'static mut ExtentIndex {
         unsafe {
-            &mut *((self.header_mut() as *mut Ext4ExtentHeader).add(1) as *mut Ext4ExtentIndex)
+            &mut *((self.header_mut() as *mut ExtentHeader).add(1) as *mut ExtentIndex)
                 .add(index)
         }
     }

+ 4 - 4
src/ext4_defs/file.rs

@@ -1,10 +1,10 @@
-use super::Ext4MountPoint;
+use super::MountPoint;
 use crate::prelude::*;
 
 /// 文件描述符
-pub struct Ext4File {
+pub struct File {
     /// 挂载点句柄
-    pub mp: *mut Ext4MountPoint,
+    pub mp: *mut MountPoint,
     /// 文件 inode id
     pub inode: InodeId,
     /// 打开标志
@@ -15,7 +15,7 @@ pub struct Ext4File {
     pub fpos: usize,
 }
 
-impl Default for Ext4File {
+impl Default for File {
     fn default() -> Self {
         Self {
             mp: ptr::null_mut(),

+ 31 - 31
src/ext4_defs/inode.rs

@@ -1,6 +1,6 @@
 //! # The Defination of Ext4 Inode Table Entry
 //!
-//! The inode table is a linear array of struct `Ext4Inode`. The table is sized to have
+//! The inode table is a linear array of struct `Inode`. The table is sized to have
 //! enough blocks to store at least `sb.inode_size * sb.inodes_per_group` bytes.
 //!
 //! The number of the block group containing an inode can be calculated as
@@ -9,9 +9,9 @@
 
 use super::crc::*;
 use super::BlockDevice;
-use super::Ext4BlockGroupDesc;
-use super::Ext4ExtentHeader;
-use super::Ext4Superblock;
+use super::BlockGroupDesc;
+use super::ExtentHeader;
+use super::Superblock;
 use super::{ExtentNode, ExtentNodeMut};
 use crate::constants::*;
 use crate::prelude::*;
@@ -29,7 +29,7 @@ pub struct Linux2 {
 
 #[repr(C)]
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub struct Ext4Inode {
+pub struct Inode {
     pub mode: u16,
     pub uid: u16,
     pub size: u32,
@@ -60,15 +60,15 @@ pub struct Ext4Inode {
 }
 
 /// Because `[u8; 60]` cannot derive `Default`, we implement it manually.
-impl Default for Ext4Inode {
+impl Default for Inode {
     fn default() -> Self {
         unsafe { mem::zeroed() }
     }
 }
 
-impl Ext4Inode {
+impl Inode {
     pub fn from_bytes(bytes: &[u8]) -> Self {
-        unsafe { *(bytes.as_ptr() as *const Ext4Inode) }
+        unsafe { *(bytes.as_ptr() as *const Inode) }
     }
 
     pub fn flags(&self) -> u32 {
@@ -87,7 +87,7 @@ impl Ext4Inode {
         self.mode |= mode;
     }
 
-    pub fn inode_type(&self, super_block: &Ext4Superblock) -> u32 {
+    pub fn inode_type(&self, super_block: &Superblock) -> u32 {
         let mut v = self.mode;
 
         if super_block.creator_os() == EXT4_SUPERBLOCK_OS_HURD {
@@ -97,11 +97,11 @@ impl Ext4Inode {
         (v & EXT4_INODE_MODE_TYPE_MASK) as u32
     }
 
-    pub fn is_dir(&self, super_block: &Ext4Superblock) -> bool {
+    pub fn is_dir(&self, super_block: &Superblock) -> bool {
         self.inode_type(super_block) == EXT4_INODE_MODE_DIRECTORY as u32
     }
 
-    pub fn is_softlink(&self, super_block: &Ext4Superblock) -> bool {
+    pub fn is_softlink(&self, super_block: &Superblock) -> bool {
         self.inode_type(super_block) == EXT4_INODE_MODE_SOFTLINK as u32
     }
 
@@ -158,7 +158,7 @@ impl Ext4Inode {
         self.i_extra_isize = extra_isize;
     }
 
-    pub fn set_inode_checksum_value(&mut self, super_block: &Ext4Superblock, checksum: u32) {
+    pub fn set_inode_checksum_value(&mut self, super_block: &Superblock, checksum: u32) {
         let inode_size = super_block.inode_size();
 
         self.osd2.l_i_checksum_lo = ((checksum << 16) >> 16) as u16;
@@ -177,13 +177,13 @@ impl Ext4Inode {
 
     fn copy_to_byte_slice(&self, slice: &mut [u8]) {
         unsafe {
-            let inode_ptr = self as *const Ext4Inode as *const u8;
+            let inode_ptr = self as *const Inode as *const u8;
             let array_ptr = slice.as_ptr() as *mut u8;
             core::ptr::copy_nonoverlapping(inode_ptr, array_ptr, 0x9c);
         }
     }
 
-    fn calc_checksum(&mut self, inode_id: u32, super_block: &Ext4Superblock) -> u32 {
+    fn calc_checksum(&mut self, inode_id: u32, super_block: &Superblock) -> u32 {
         let inode_size = super_block.inode_size();
 
         let ino_index = inode_id as u32;
@@ -216,7 +216,7 @@ impl Ext4Inode {
         checksum
     }
 
-    fn set_checksum(&mut self, super_block: &Ext4Superblock, inode_id: u32) {
+    fn set_checksum(&mut self, super_block: &Superblock, inode_id: u32) {
         let inode_size = super_block.inode_size();
         let checksum = self.calc_checksum(inode_id, super_block);
 
@@ -247,38 +247,38 @@ impl Ext4Inode {
     /// node of the extent tree
     pub fn extent_init(&mut self) {
         self.set_flags(EXT4_INODE_FLAG_EXTENTS);
-        let header = Ext4ExtentHeader::new(0, 4, 0, 0);
-        let header_ptr = &header as *const Ext4ExtentHeader as *const u8;
+        let header = ExtentHeader::new(0, 4, 0, 0);
+        let header_ptr = &header as *const ExtentHeader as *const u8;
         let array_ptr = &mut self.block as *mut u8;
         unsafe {
-            core::ptr::copy_nonoverlapping(header_ptr, array_ptr, size_of::<Ext4ExtentHeader>());
+            core::ptr::copy_nonoverlapping(header_ptr, array_ptr, size_of::<ExtentHeader>());
         }
     }
 }
 
-/// A combination of an `Ext4Inode` and its id
+/// A combination of an `Inode` and its id
 #[derive(Clone)]
-pub struct Ext4InodeRef {
+pub struct InodeRef {
     pub inode_id: InodeId,
-    pub inode: Ext4Inode,
+    pub inode: Inode,
 }
 
-impl Ext4InodeRef {
-    pub fn new(inode_id: InodeId, inode: Ext4Inode) -> Self {
+impl InodeRef {
+    pub fn new(inode_id: InodeId, inode: Inode) -> Self {
         Self { inode_id, inode }
     }
 
     pub fn read_from_disk(
         block_device: Arc<dyn BlockDevice>,
-        super_block: &Ext4Superblock,
+        super_block: &Superblock,
         inode_id: InodeId,
     ) -> Self {
         let pos = Self::inode_disk_pos(super_block, block_device.clone(), inode_id);
         let data = block_device.read_offset(pos);
-        let inode_data = &data[..core::mem::size_of::<Ext4Inode>()];
+        let inode_data = &data[..core::mem::size_of::<Inode>()];
         Self {
             inode_id,
-            inode: Ext4Inode::from_bytes(inode_data),
+            inode: Inode::from_bytes(inode_data),
         }
     }
 
@@ -294,7 +294,7 @@ impl Ext4InodeRef {
     /// To get the byte address within the inode table, use
     /// `offset = index * sb.inode_size`.
     fn inode_disk_pos(
-        super_block: &Ext4Superblock,
+        super_block: &Superblock,
         block_device: Arc<dyn BlockDevice>,
         inode_id: InodeId,
     ) -> usize {
@@ -303,18 +303,18 @@ impl Ext4InodeRef {
         let group = (inode_id - 1) / inodes_per_group;
         let index = (inode_id - 1) % inodes_per_group;
 
-        let bg = Ext4BlockGroupDesc::load(block_device, super_block, group as usize).unwrap();
+        let bg = BlockGroupDesc::load(block_device, super_block, group as usize).unwrap();
         bg.inode_table_first_block() as usize * BLOCK_SIZE + (index * inode_size as u32) as usize
     }
 
     pub fn sync_to_disk_without_csum(
         &self,
         block_device: Arc<dyn BlockDevice>,
-        super_block: &Ext4Superblock,
+        super_block: &Superblock,
     ) -> Result<()> {
         let disk_pos = Self::inode_disk_pos(super_block, block_device.clone(), self.inode_id);
         let data = unsafe {
-            core::slice::from_raw_parts(&self.inode as *const _ as *const u8, size_of::<Ext4Inode>())
+            core::slice::from_raw_parts(&self.inode as *const _ as *const u8, size_of::<Inode>())
         };
         block_device.write_offset(disk_pos, data);
         Ok(())
@@ -323,7 +323,7 @@ impl Ext4InodeRef {
     pub fn sync_to_disk_with_csum(
         &mut self,
         block_device: Arc<dyn BlockDevice>,
-        super_block: &Ext4Superblock,
+        super_block: &Superblock,
     ) -> Result<()> {
         self.inode.set_checksum(super_block, self.inode_id);
         self.sync_to_disk_without_csum(block_device, super_block)

+ 3 - 3
src/ext4_defs/mount_point.rs

@@ -2,14 +2,14 @@ use crate::prelude::*;
 
 /// Mount point descriptor
 #[derive(Clone)]
-pub struct Ext4MountPoint {
+pub struct MountPoint {
     /// Mount done flag
     pub mounted: bool,
     ///  Mount point name
     pub mount_name: String,
 }
 
-impl Ext4MountPoint {
+impl MountPoint {
     pub fn new(name: &str) -> Self {
         Self {
             mounted: false,
@@ -18,7 +18,7 @@ impl Ext4MountPoint {
     }
 }
 
-impl Debug for Ext4MountPoint {
+impl Debug for MountPoint {
     fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
         write!(f, "Ext4MountPoint {{ mount_name: {:?} }}", self.mount_name)
     }

+ 7 - 7
src/ext4_defs/super_block.rs

@@ -5,14 +5,14 @@
 //! See [`super::block_group`] for details.
 
 use super::BlockDevice;
-use super::Ext4Inode;
+use super::Inode;
 use crate::constants::*;
 use crate::prelude::*;
 
 // 结构体表示超级块
 #[repr(C)]
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub struct Ext4Superblock {
+pub struct Superblock {
     inodes_count: u32,             // 节点数
     blocks_count_lo: u32,          // 块数
     reserved_blocks_count_lo: u32, // 保留块数
@@ -112,15 +112,15 @@ pub struct Ext4Superblock {
     checksum: u32,             // crc32c(superblock)
 }
 
-impl TryFrom<Vec<u8>> for Ext4Superblock {
+impl TryFrom<Vec<u8>> for Superblock {
     type Error = u64;
     fn try_from(value: Vec<u8>) -> core::result::Result<Self, u64> {
-        let data = &value[..size_of::<Ext4Superblock>()];
+        let data = &value[..size_of::<Superblock>()];
         Ok(unsafe { core::ptr::read(data.as_ptr() as *const _) })
     }
 }
 
-impl Ext4Superblock {
+impl Superblock {
     pub fn first_data_block(&self) -> u32 {
         self.first_data_block
     }
@@ -170,7 +170,7 @@ impl Ext4Superblock {
     }
 
     /// Returns the size of inode structure.
-    pub fn inode_size_file(&self, inode: &Ext4Inode) -> u64 {
+    pub fn inode_size_file(&self, inode: &Inode) -> u64 {
         let mode = inode.mode;
 
         // 获取inode的低32位大小
@@ -231,7 +231,7 @@ impl Ext4Superblock {
     
     pub fn sync_to_disk(&self, block_device: Arc<dyn BlockDevice>) {
         let data = unsafe {
-            core::slice::from_raw_parts(self as *const _ as *const u8, size_of::<Ext4Superblock>())
+            core::slice::from_raw_parts(self as *const _ as *const u8, size_of::<Superblock>())
         };
         block_device.write_offset(BASE_OFFSET, data);
     }