liujingx 11 mesiacov pred
rodič
commit
a360e452d6

+ 16 - 12
src/ext4/alloc.rs

@@ -1,7 +1,9 @@
 use super::Ext4;
 use crate::constants::*;
 use crate::ext4_defs::*;
+use crate::format_error;
 use crate::prelude::*;
+use crate::return_error;
 
 impl Ext4 {
     /// Create a new inode, returning the inode and its number
@@ -104,9 +106,10 @@ impl Ext4 {
         // Find the first free block
         let fblock = bitmap
             .find_and_set_first_clear_bit(0, 8 * BLOCK_SIZE)
-            .ok_or(Ext4Error::with_msg(
+            .ok_or(format_error!(
                 ErrCode::ENOSPC,
-                "No free block".to_owned(),
+                "No free blocks in block group {}",
+                bgid
             ))? as PBlockId;
 
         // Set block group checksum
@@ -153,10 +156,7 @@ impl Ext4 {
 
         // Free the block
         if bitmap.is_bit_clear(pblock as usize) {
-            return Err(Ext4Error::with_msg(
-                ErrCode::EINVAL,
-                "Block double free".to_owned(),
-            ));
+            return_error!(ErrCode::EINVAL, "Block {} is already free", pblock);
         }
         bitmap.clear_bit(pblock as usize);
 
@@ -208,9 +208,10 @@ impl Ext4 {
             let idx_in_bg =
                 bitmap
                     .find_and_set_first_clear_bit(0, inode_count)
-                    .ok_or(Ext4Error::with_msg(
+                    .ok_or(format_error!(
                         ErrCode::ENOSPC,
-                        "No free inode".to_owned(),
+                        "No free inodes in block group {}",
+                        bgid
                     ))? as u32;
 
             // Update bitmap in disk
@@ -248,8 +249,9 @@ impl Ext4 {
 
             return Ok(inode_id);
         }
+
         log::info!("no free inode");
-        Err(Ext4Error::new(ErrCode::ENOSPC))
+        return_error!(ErrCode::ENOSPC, "No free inodes in block group {}", bgid);
     }
 
     /// Free an inode
@@ -270,10 +272,12 @@ impl Ext4 {
 
         // Free the inode
         if bitmap.is_bit_clear(idx_in_bg as usize) {
-            return Err(Ext4Error::with_msg(
+            return_error!(
                 ErrCode::EINVAL,
-                "Inode double free".to_owned(),
-            ));
+                "Inode {} is already free in block group {}",
+                inode_ref.id,
+                bgid
+            );
         }
         bitmap.clear_bit(idx_in_bg as usize);
 

+ 3 - 3
src/ext4/mod.rs

@@ -5,11 +5,11 @@ use crate::prelude::*;
 mod alloc;
 mod dir;
 mod extent;
-mod link;
+mod high_level;
 mod journal;
-mod rw;
+mod link;
 mod low_level;
-mod high_level;
+mod rw;
 
 #[derive(Debug)]
 pub struct Ext4 {

+ 2 - 2
src/ext4_defs/block_group.rs

@@ -8,12 +8,12 @@
 //! See [`super`] for more information.
 
 use super::crc::*;
+use super::AsBytes;
 use super::Bitmap;
 use super::BlockDevice;
 use super::SuperBlock;
 use crate::constants::*;
 use crate::prelude::*;
-use super::AsBytes;
 
 #[derive(Debug, Default, Clone, Copy)]
 #[repr(C, packed)]
@@ -194,7 +194,7 @@ impl BlockGroupRef {
             desc,
         }
     }
-    
+
     pub fn sync_to_disk_without_csum(
         &self,
         block_device: &dyn BlockDevice,

+ 1 - 1
src/ext4_defs/crc.rs

@@ -72,4 +72,4 @@ fn crc32(crc: u32, buf: &[u8], size: u32, tab: &[u32]) -> u32 {
 
 pub fn ext4_crc32c(crc: u32, buf: &[u8], size: u32) -> u32 {
     crc32(crc, buf, size, &CRC32C_TAB)
-}
+}

+ 1 - 1
src/ext4_defs/mount_point.rs

@@ -24,4 +24,4 @@ impl Debug for MountPoint {
     fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
         write!(f, "Ext4MountPoint {{ mount_name: {:?} }}", self.mount_name)
     }
-}
+}

+ 1 - 1
src/ext4_defs/super_block.rs

@@ -4,10 +4,10 @@
 //!
 //! See [`super::block_group`] for details.
 
+use super::AsBytes;
 use super::BlockDevice;
 use crate::constants::*;
 use crate::prelude::*;
-use super::AsBytes;
 
 // 结构体表示超级块
 #[repr(C)]

+ 1 - 1
src/jbd2.rs

@@ -9,4 +9,4 @@ pub trait Jbd2: Send + Sync + Any + Debug {
     fn transaction_stop(&mut self);
     fn journal_stop(&mut self);
     fn recover(&mut self);
-}
+}

+ 3 - 3
src/prelude.rs

@@ -3,20 +3,20 @@
 
 extern crate alloc;
 
+pub(crate) use alloc::borrow::ToOwned;
 pub(crate) use alloc::boxed::Box;
 pub(crate) use alloc::collections::BTreeMap;
 pub(crate) use alloc::collections::BTreeSet;
 pub(crate) use alloc::collections::LinkedList;
 pub(crate) use alloc::collections::VecDeque;
 pub(crate) use alloc::ffi::CString;
+pub(crate) use alloc::format;
 pub(crate) use alloc::string::String;
 pub(crate) use alloc::string::ToString;
 pub(crate) use alloc::sync::Arc;
 pub(crate) use alloc::sync::Weak;
 pub(crate) use alloc::vec;
 pub(crate) use alloc::vec::Vec;
-pub(crate) use alloc::borrow::ToOwned;
-pub(crate) use alloc::format;
 pub(crate) use bitflags::bitflags;
 pub(crate) use core::any::Any;
 pub(crate) use core::ffi::CStr;
@@ -32,4 +32,4 @@ pub(crate) type Result<T> = core::result::Result<T, Ext4Error>;
 pub(crate) type LBlockId = u32;
 pub(crate) type PBlockId = u64;
 pub(crate) type InodeId = u32;
-pub(crate) type BlockGroupId = u32;
+pub(crate) type BlockGroupId = u32;