liujingx 11 месяцев назад
Родитель
Сommit
c757a1da44
12 измененных файлов с 166 добавлено и 169 удалено
  1. 0 9
      src/constants.rs
  2. 23 12
      src/error.rs
  3. 21 18
      src/ext4/alloc.rs
  4. 8 14
      src/ext4/dir.rs
  5. 10 9
      src/ext4/file.rs
  6. 1 1
      src/ext4/link.rs
  7. 8 53
      src/ext4_defs/dir_entry.rs
  8. 78 15
      src/ext4_defs/inode.rs
  9. 14 0
      src/ext4_defs/mod.rs
  10. 0 19
      src/ext4_defs/super_block.rs
  11. 2 18
      src/lib.rs
  12. 1 1
      src/prelude.rs

+ 0 - 9
src/constants.rs

@@ -12,15 +12,6 @@ pub const EXT_UNWRITTEN_MAX_LEN: u16 = 65535;
 
 pub const EXT4_GOOD_OLD_INODE_SIZE: u16 = 128;
 
-pub const EXT4_INODE_MODE_FIFO: u16 = 0x1000;
-pub const EXT4_INODE_MODE_CHARDEV: u16 = 0x2000;
-pub const EXT4_INODE_MODE_DIRECTORY: u16 = 0x4000;
-pub const EXT4_INODE_MODE_BLOCKDEV: u16 = 0x6000;
-pub const EXT4_INODE_MODE_FILE: u16 = 0x8000;
-pub const EXT4_INODE_MODE_SOFTLINK: u16 = 0xA000;
-pub const EXT4_INODE_MODE_SOCKET: u16 = 0xC000;
-pub const EXT4_INODE_MODE_TYPE_MASK: u16 = 0xF000;
-
 pub const EXT_MAX_BLOCKS: LBlockId = core::u32::MAX;
 
 pub const EXT4_SUPERBLOCK_OS_HURD: u32 = 1;

+ 23 - 12
src/ext4_error.rs → src/error.rs

@@ -1,4 +1,7 @@
 // SPDX-License-Identifier: MPL-2.0
+extern crate alloc;
+
+use crate::prelude::*;
 
 /// Ext4Error number.
 #[repr(i32)]
@@ -30,11 +33,19 @@ pub enum ErrCode {
 }
 
 /// error used in this crate
-#[derive(Debug, Clone, Copy)]
 pub struct Ext4Error {
     errno: ErrCode,
-    #[allow(unused)]
-    msg: Option<&'static str>,
+    msg: Option<String>,
+}
+
+impl Debug for Ext4Error {
+    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        if let Some(msg) = &self.msg {
+            write!(f, "Ext4Error {{ errno: {:?}, msg: {:?} }}", self.errno, msg)
+        } else {
+            write!(f, "Ext4Error {{ errno: {:?} }}", self.errno)
+        }
+    }
 }
 
 impl Ext4Error {
@@ -42,7 +53,7 @@ impl Ext4Error {
         Ext4Error { errno, msg: None }
     }
 
-    pub const fn with_message(errno: ErrCode, msg: &'static str) -> Self {
+    pub const fn with_message(errno: ErrCode, msg: String) -> Self {
         Ext4Error {
             errno,
             msg: Some(msg),
@@ -62,43 +73,43 @@ impl From<ErrCode> for Ext4Error {
 
 impl From<core::str::Utf8Error> for Ext4Error {
     fn from(_: core::str::Utf8Error) -> Self {
-        Ext4Error::with_message(ErrCode::EINVAL, "Invalid utf-8 string")
+        Ext4Error::with_message(ErrCode::EINVAL, "Invalid utf-8 string".to_owned())
     }
 }
 
 impl From<alloc::string::FromUtf8Error> for Ext4Error {
     fn from(_: alloc::string::FromUtf8Error) -> Self {
-        Ext4Error::with_message(ErrCode::EINVAL, "Invalid utf-8 string")
+        Ext4Error::with_message(ErrCode::EINVAL, "Invalid utf-8 string".to_owned())
     }
 }
 
 impl From<core::ffi::FromBytesUntilNulError> for Ext4Error {
     fn from(_: core::ffi::FromBytesUntilNulError) -> Self {
-        Ext4Error::with_message(ErrCode::E2BIG, "Cannot find null in cstring")
+        Ext4Error::with_message(ErrCode::E2BIG, "Cannot find null in cstring".to_owned())
     }
 }
 
 impl From<core::ffi::FromBytesWithNulError> for Ext4Error {
     fn from(_: core::ffi::FromBytesWithNulError) -> Self {
-        Ext4Error::with_message(ErrCode::E2BIG, "Cannot find null in cstring")
+        Ext4Error::with_message(ErrCode::E2BIG, "Cannot find null in cstring".to_owned())
     }
 }
 
 impl From<alloc::ffi::NulError> for Ext4Error {
     fn from(_: alloc::ffi::NulError) -> Self {
-        Ext4Error::with_message(ErrCode::E2BIG, "Cannot find null in cstring")
+        Ext4Error::with_message(ErrCode::E2BIG, "Cannot find null in cstring".to_owned())
     }
 }
 
 #[macro_export]
-macro_rules! return_errno {
+macro_rules! return_err {
     ($errno: expr) => {
-        return Err($crate::error::Ext4Error::new($errno))
+        return Err(Ext4Error::new($errno))
     };
 }
 
 #[macro_export]
-macro_rules! return_errno_with_message {
+macro_rules! return_err_with_msg {
     ($errno: expr, $message: expr) => {
         return Err(Ext4Error::with_message($errno, $message))
     };

+ 21 - 18
src/ext4/alloc.rs

@@ -5,19 +5,18 @@ use crate::prelude::*;
 
 impl Ext4 {
     /// Create a new inode, returning the inode and its number
-    pub(super) fn create_inode(&mut self, filetype: FileType) -> Result<InodeRef> {
+    pub(super) fn create_inode(&mut self, file_type: FileType) -> Result<InodeRef> {
         // Allocate an inode
-        let is_dir = filetype == FileType::Directory;
+        let is_dir = file_type == FileType::Directory;
         let id = self.alloc_inode(is_dir)?;
 
         // Initialize the inode
         let mut inode = Inode::default();
-        let mode = if filetype == FileType::Directory {
-            0o777 | EXT4_INODE_MODE_DIRECTORY
-        } else if filetype == FileType::SymLink {
-            0o777 | EXT4_INODE_MODE_SOFTLINK
-        } else {
-            0o666 | file_type2inode_mode(filetype)
+        let mode = match file_type {
+            FileType::SymLink | FileType::Directory => {
+                InodeMode::from_type_and_perm(file_type, InodeMode::ALL_RWX)
+            }
+            _ => InodeMode::from_type_and_perm(file_type, InodeMode::ALL_RW),
         };
         inode.set_mode(mode);
         inode.extent_init();
@@ -36,7 +35,10 @@ impl Ext4 {
     /// Create(initialize) the root inode of the file system
     pub(super) fn create_root_inode(&mut self) -> Result<InodeRef> {
         let mut inode = Inode::default();
-        inode.set_mode(0o777 | EXT4_INODE_MODE_DIRECTORY);
+        inode.set_mode(InodeMode::from_type_and_perm(
+            FileType::Directory,
+            InodeMode::ALL_RWX,
+        ));
         inode.extent_init();
         if self.super_block.inode_size() > EXT4_GOOD_OLD_INODE_SIZE {
             inode.set_extra_isize(self.super_block.extra_size());
@@ -108,8 +110,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_message(ErrCode::ENOSPC, "No free block"))?
-            as PBlockId;
+            .ok_or(Ext4Error::with_message(
+                ErrCode::ENOSPC,
+                "No free block".to_owned(),
+            ))? as PBlockId;
 
         // Set block group checksum
         bg.desc.set_block_bitmap_csum(&self.super_block, &bitmap);
@@ -157,7 +161,7 @@ impl Ext4 {
         if bitmap.is_bit_clear(pblock as usize) {
             return Err(Ext4Error::with_message(
                 ErrCode::EINVAL,
-                "Block double free",
+                "Block double free".to_owned(),
             ));
         }
         bitmap.clear_bit(pblock as usize);
@@ -207,10 +211,9 @@ impl Ext4 {
             let mut bitmap = Bitmap::new(&mut bitmap_block.data[..inode_count / 8]);
 
             // Find a free inode
-            let idx_in_bg = bitmap
-                .find_and_set_first_clear_bit(0, inode_count)
-                .ok_or(Ext4Error::with_message(ErrCode::ENOSPC, "No free inode"))?
-                as u32;
+            let idx_in_bg = bitmap.find_and_set_first_clear_bit(0, inode_count).ok_or(
+                Ext4Error::with_message(ErrCode::ENOSPC, "No free inode".to_owned()),
+            )? as u32;
 
             // Update bitmap in disk
             bg.desc.set_inode_bitmap_csum(&self.super_block, &bitmap);
@@ -271,7 +274,7 @@ impl Ext4 {
         if bitmap.is_bit_clear(idx_in_bg as usize) {
             return Err(Ext4Error::with_message(
                 ErrCode::EINVAL,
-                "Inode double free",
+                "Inode double free".to_owned(),
             ));
         }
         bitmap.clear_bit(idx_in_bg as usize);
@@ -286,7 +289,7 @@ impl Ext4 {
             .set_free_inodes_count(&self.super_block, free_inodes);
 
         // Increase used directories counter
-        if inode_ref.inode.is_dir(&self.super_block) {
+        if inode_ref.inode.is_dir() {
             let used_dirs = bg.desc.used_dirs_count(&self.super_block) - 1;
             bg.desc.set_used_dirs_count(&self.super_block, used_dirs);
         }

+ 8 - 14
src/ext4/dir.rs

@@ -187,12 +187,7 @@ impl Ext4 {
     fn insert_entry_to_new_block(&self, dst_blk: &mut Block, child: &InodeRef, name: &str) {
         // Set the entry
         let rec_len = BLOCK_SIZE - size_of::<DirEntryTail>();
-        let new_entry = DirEntry::new(
-            child.id,
-            rec_len as u16,
-            name,
-            inode_mode2file_type(child.inode.mode()),
-        );
+        let new_entry = DirEntry::new(child.id, rec_len as u16, name, child.inode.file_type());
         // Write entry to block
         dst_blk.write_offset_as(0, &new_entry);
 
@@ -236,12 +231,8 @@ impl Ext4 {
             de.set_rec_len(used_size as u16);
             dst_blk.write_offset_as(offset, &de);
             // Insert the new entry
-            let new_entry = DirEntry::new(
-                child.id,
-                free_size as u16,
-                name,
-                inode_mode2file_type(child.inode.mode()),
-            );
+            let new_entry =
+                DirEntry::new(child.id, free_size as u16, name, child.inode.file_type());
             dst_blk.write_offset_as(offset + used_size, &new_entry);
 
             // Set tail csum
@@ -266,7 +257,7 @@ impl Ext4 {
                 continue;
             }
             let mut child = self.read_inode(entry.inode());
-            if child.inode.is_dir(&self.super_block) {
+            if child.inode.is_dir() {
                 // Remove child dir recursively
                 self.remove_dir_recursive(&mut child)?;
             } else {
@@ -274,7 +265,10 @@ impl Ext4 {
                 self.generic_remove(
                     dir.id,
                     &entry.name().map_err(|_| {
-                        Ext4Error::with_message(ErrCode::EINVAL, "Invalid dir entry name")
+                        Ext4Error::with_message(
+                            ErrCode::EINVAL,
+                            "Invalid dir entry name".to_owned(),
+                        )
                     })?,
                     Some(FileType::RegularFile),
                 )?;

+ 10 - 9
src/ext4/file.rs

@@ -2,7 +2,7 @@ use super::Ext4;
 use crate::constants::*;
 use crate::ext4_defs::*;
 use crate::prelude::*;
-use crate::return_errno_with_message;
+use crate::return_err_with_msg;
 use core::cmp::min;
 
 impl Ext4 {
@@ -39,7 +39,7 @@ impl Ext4 {
         file.fsize = inode_ref.inode.size();
 
         // Check if the file is a softlink
-        if inode_ref.inode.is_softlink(&self.super_block) {
+        if inode_ref.inode.is_softlink() {
             // TODO: read softlink
             log::debug!("ext4_read unsupported softlink");
         }
@@ -131,7 +131,7 @@ impl Ext4 {
     /// * `expect_type` - The expect type of object to open, optional. If this
     ///    parameter is provided, the function will check the type of the object
     ///    to open.
-    pub(super) fn generic_open(
+    pub fn generic_open(
         &mut self,
         root: InodeId,
         path: &str,
@@ -152,12 +152,12 @@ impl Ext4 {
                 Err(e) => {
                     if e.code() != ErrCode::ENOENT {
                         // dir search failed with error other than ENOENT
-                        return_errno_with_message!(ErrCode::ENOTSUP, "dir search failed");
+                        return_err_with_msg!(ErrCode::ENOTSUP, "dir search failed".to_owned());
                     }
                     if !flags.contains(OpenFlags::O_CREAT) || expect_type.is_none() {
                         // `O_CREAT` and `expect_type` must be provided together to
                         // create a new object
-                        return_errno_with_message!(ErrCode::ENOENT, "file not found");
+                        return_err_with_msg!(ErrCode::ENOENT, "file not found".to_owned());
                     }
                     // Create file/directory
                     let mut child = if i == search_path.len() - 1 {
@@ -166,8 +166,9 @@ impl Ext4 {
                         self.create_inode(FileType::Directory)
                     }?;
                     // Link the new inode
-                    self.link(&mut cur, &mut child, path)
-                        .map_err(|_| Ext4Error::with_message(ErrCode::ELINKFAIL, "link fail"))?;
+                    self.link(&mut cur, &mut child, path).map_err(|_| {
+                        Ext4Error::with_message(ErrCode::ELINKFAIL, "link fail".to_owned())
+                    })?;
                     // Write back parent and child
                     self.write_inode_with_csum(&mut cur);
                     self.write_inode_with_csum(&mut child);
@@ -178,8 +179,8 @@ impl Ext4 {
         }
         // `cur` is the target inode, check type if `expect_type` os provided
         if let Some(expect_type) = expect_type {
-            if inode_mode2file_type(cur.inode.mode()) != expect_type {
-                return_errno_with_message!(ErrCode::EISDIR, "inode type mismatch");
+            if cur.inode.file_type() != expect_type {
+                return_err_with_msg!(ErrCode::EISDIR, "inode type mismatch".to_owned());
             }
         }
         Ok(cur)

+ 1 - 1
src/ext4/link.rs

@@ -13,7 +13,7 @@ impl Ext4 {
         let _r = self.dir_add_entry(parent, child, name);
         child.inode.links_count += 1;
 
-        if child.inode.is_dir(&self.super_block) {
+        if child.inode.is_dir() {
             // add '.' and '..' entries
             let child_self = child.clone();
             self.dir_add_entry(child, &child_self, ".")?;

+ 8 - 53
src/ext4_defs/dir_entry.rs

@@ -4,11 +4,11 @@
 //! linear array of directory entries.
 
 use super::crc::*;
+use super::FileType;
 use super::SuperBlock;
 use crate::constants::*;
 use crate::prelude::*;
 use crate::AsBytes;
-use alloc::string::FromUtf8Error;
 
 #[repr(C)]
 pub union DirEnInner {
@@ -18,13 +18,7 @@ pub union DirEnInner {
 
 impl Debug for DirEnInner {
     fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
-        unsafe {
-            write!(
-                f,
-                "Ext4DirEnInternal {{ name_length_high: {:?} }}",
-                self.name_length_high
-            )
-        }
+        unsafe { write!(f, "inode_type: {:?}", self.inode_type) }
     }
 }
 
@@ -105,10 +99,10 @@ impl DirEntry {
         }
     }
 
-    pub fn name(&self) -> core::result::Result<String, FromUtf8Error> {
+    pub fn name(&self) -> Result<String> {
         let name_len = self.name_len as usize;
         let name = &self.name[..name_len];
-        String::from_utf8(name.to_vec())
+        String::from_utf8(name.to_vec()).map_err(|e| e.into())
     }
 
     pub fn compare_name(&self, name: &str) -> bool {
@@ -147,9 +141,9 @@ impl DirEntry {
         self.inode = 0
     }
 
-    /// Set the dir entry's inode type given the corresponding inode mode
-    pub fn set_entry_type(&mut self, inode_mode: u16) {
-        self.inner.inode_type = inode_mode2file_type(inode_mode);
+    /// Set the dir entry's file type
+    pub fn set_type(&mut self, file_type: FileType) {
+        self.inner.inode_type = file_type;
     }
 
     /// Get the required size to save a directory entry, 4-byte aligned
@@ -181,8 +175,8 @@ impl DirEntry {
     }
 }
 
-#[repr(C)]
 #[derive(Debug, Clone, Copy, Default)]
+#[repr(C)]
 pub struct DirEntryTail {
     pub reserved_zero1: u32,
     pub rec_len: u16,
@@ -209,42 +203,3 @@ pub struct FakeDirEntry {
 }
 
 impl AsBytes for FakeDirEntry {}
-
-#[derive(PartialEq, Eq, Clone, Copy, Debug)]
-#[repr(u8)]
-pub enum FileType {
-    Unknown,
-    RegularFile,
-    Directory,
-    CharacterDev,
-    BlockDev,
-    Fifo,
-    Socket,
-    SymLink,
-}
-
-pub fn inode_mode2file_type(inode_mode: u16) -> FileType {
-    match inode_mode & EXT4_INODE_MODE_TYPE_MASK {
-        EXT4_INODE_MODE_FILE => FileType::RegularFile,
-        EXT4_INODE_MODE_DIRECTORY => FileType::Directory,
-        EXT4_INODE_MODE_CHARDEV => FileType::CharacterDev,
-        EXT4_INODE_MODE_BLOCKDEV => FileType::BlockDev,
-        EXT4_INODE_MODE_FIFO => FileType::Fifo,
-        EXT4_INODE_MODE_SOCKET => FileType::Socket,
-        EXT4_INODE_MODE_SOFTLINK => FileType::SymLink,
-        _ => FileType::Unknown,
-    }
-}
-
-pub fn file_type2inode_mode(dirent_type: FileType) -> u16 {
-    match dirent_type {
-        FileType::RegularFile => EXT4_INODE_MODE_FILE,
-        FileType::Directory => EXT4_INODE_MODE_DIRECTORY,
-        FileType::SymLink => EXT4_INODE_MODE_SOFTLINK,
-        FileType::CharacterDev => EXT4_INODE_MODE_CHARDEV,
-        FileType::BlockDev => EXT4_INODE_MODE_BLOCKDEV,
-        FileType::Fifo => EXT4_INODE_MODE_FIFO,
-        FileType::Socket => EXT4_INODE_MODE_SOCKET,
-        _ => EXT4_INODE_MODE_FILE,
-    }
-}

+ 78 - 15
src/ext4_defs/inode.rs

@@ -15,6 +15,71 @@ use super::SuperBlock;
 use super::{ExtentNode, ExtentNodeMut};
 use crate::constants::*;
 use crate::prelude::*;
+use crate::FileType;
+
+bitflags! {
+    #[derive(PartialEq, Debug, Clone, Copy)]
+    pub struct InodeMode: u16 {
+        // Premission
+        const PERM_MASK = 0xFFF;
+        const USER_READ = 0x100;
+        const USER_WRITE = 0x80;
+        const USER_EXEC = 0x40;
+        const GROUP_READ = 0x20;
+        const GROUP_WRITE = 0x10;
+        const GROUP_EXEC = 0x8;
+        const OTHER_READ = 0x4;
+        const OTHER_WRITE = 0x2;
+        const OTHER_EXEC = 0x1;
+        // File type
+        const TYPE_MASK = 0xF000;
+        const FIFO = 0x1000;
+        const CHARDEV = 0x2000;
+        const DIRECTORY = 0x4000;
+        const BLOCKDEV = 0x6000;
+        const FILE = 0x8000;
+        const SOFTLINK = 0xA000;
+        const SOCKET = 0xC000;
+    }
+}
+
+impl InodeMode {
+    /// Enable read, write, and execute for all users.
+    pub const ALL_RWX: InodeMode = InodeMode::from_bits_retain(0o777);
+    /// Enable read and write for all users.
+    pub const ALL_RW: InodeMode = InodeMode::from_bits_retain(0o666);
+
+    /// Set an inode mode from a file type and permission bits.
+    pub fn from_type_and_perm(file_type: FileType, perm: InodeMode) -> Self {
+        (match file_type {
+            FileType::RegularFile => InodeMode::FILE,
+            FileType::Directory => InodeMode::DIRECTORY,
+            FileType::CharacterDev => InodeMode::CHARDEV,
+            FileType::BlockDev => InodeMode::BLOCKDEV,
+            FileType::Fifo => InodeMode::FIFO,
+            FileType::Socket => InodeMode::SOCKET,
+            FileType::SymLink => InodeMode::SOFTLINK,
+            _ => InodeMode::FILE,
+        }) | (perm & InodeMode::PERM_MASK)
+    }
+    /// Get permission bits of an inode mode.
+    pub fn perm(&self) -> u16 {
+        (*self & InodeMode::PERM_MASK).bits() as u16
+    }
+    /// Get the file type of an inode mode.
+    pub fn file_type(&self) -> FileType {
+        match *self & InodeMode::TYPE_MASK {
+            InodeMode::CHARDEV => FileType::CharacterDev,
+            InodeMode::DIRECTORY => FileType::Directory,
+            InodeMode::BLOCKDEV => FileType::BlockDev,
+            InodeMode::FILE => FileType::RegularFile,
+            InodeMode::FIFO => FileType::Fifo,
+            InodeMode::SOCKET => FileType::Socket,
+            InodeMode::SOFTLINK => FileType::SymLink,
+            _ => FileType::Unknown,
+        }
+    }
+}
 
 #[repr(C)]
 #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
@@ -81,30 +146,28 @@ impl Inode {
         self.flags |= f;
     }
 
-    pub fn mode(&self) -> u16 {
-        self.mode
+    pub fn mode(&self) -> InodeMode {
+        InodeMode::from_bits_truncate(self.mode)
     }
 
-    pub fn set_mode(&mut self, mode: u16) {
-        self.mode |= mode;
+    pub fn set_mode(&mut self, mode: InodeMode) {
+        self.mode = mode.bits();
     }
 
-    pub fn inode_type(&self, super_block: &SuperBlock) -> u32 {
-        let mut v = self.mode;
-
-        if super_block.creator_os() == EXT4_SUPERBLOCK_OS_HURD {
-            v |= ((self.osd2.l_i_file_acl_high as u32) << 16) as u16;
-        }
+    pub fn file_type(&self) -> FileType {
+        self.mode().file_type()
+    }
 
-        (v & EXT4_INODE_MODE_TYPE_MASK) as u32
+    pub fn is_file(&self) -> bool {
+        self.file_type() == FileType::RegularFile
     }
 
-    pub fn is_dir(&self, super_block: &SuperBlock) -> bool {
-        self.inode_type(super_block) == EXT4_INODE_MODE_DIRECTORY as u32
+    pub fn is_dir(&self) -> bool {
+        self.file_type() == FileType::Directory
     }
 
-    pub fn is_softlink(&self, super_block: &SuperBlock) -> bool {
-        self.inode_type(super_block) == EXT4_INODE_MODE_SOFTLINK as u32
+    pub fn is_softlink(&self) -> bool {
+        self.file_type() == FileType::SymLink
     }
 
     pub fn links_cnt(&self) -> u16 {

+ 14 - 0
src/ext4_defs/mod.rs

@@ -34,3 +34,17 @@ pub use file::*;
 pub use inode::*;
 pub use mount_point::*;
 pub use super_block::*;
+
+/// All file types. Also matches the defination in directory entries.
+#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+#[repr(u8)]
+pub enum FileType {
+    Unknown,
+    RegularFile,
+    Directory,
+    CharacterDev,
+    BlockDev,
+    Fifo,
+    Socket,
+    SymLink,
+}

+ 0 - 19
src/ext4_defs/super_block.rs

@@ -5,7 +5,6 @@
 //! See [`super::block_group`] for details.
 
 use super::BlockDevice;
-use super::Inode;
 use crate::constants::*;
 use crate::prelude::*;
 use crate::AsBytes;
@@ -175,24 +174,6 @@ impl SuperBlock {
         self.inode_size
     }
 
-    /// Returns the size of inode structure.
-    pub fn inode_size_file(&self, inode: &Inode) -> u64 {
-        let mode = inode.mode;
-
-        // 获取inode的低32位大小
-        let mut v = inode.size as u64;
-        // 如果文件系统的版本号大于0,并且inode的类型是文件
-        if self.rev_level > 0 && (mode & EXT4_INODE_MODE_TYPE_MASK) == EXT4_INODE_MODE_FILE as u16 {
-            // 获取inode的高32位大小,并左移32位
-            let hi = (inode.size_hi as u64) << 32;
-            // 用或运算符将低32位和高32位拼接为一个u64值
-            v |= hi;
-        }
-
-        // 返回inode的大小
-        v
-    }
-
     pub fn uuid(&self) -> [u8; 16] {
         self.uuid
     }

+ 2 - 18
src/lib.rs

@@ -1,29 +1,13 @@
 //! The Ext4 filesystem implementation in Rust.
-
-#![feature(error_in_core)]
 #![no_std]
 
-extern crate alloc;
-
 mod constants;
 mod ext4;
 mod ext4_defs;
-mod ext4_error;
+mod error;
 mod jbd2;
 mod prelude;
 
 pub use ext4::*;
 pub use ext4_defs::*;
-pub use ext4_error::*;
-
-pub const BLOCK_SIZE: usize = 4096;
-
-#[cfg(test)]
-mod unit_test {
-    // use crate::Ext4;
-
-    #[test]
-    fn create_fs() {
-        // let ext4 = Ext4::new();
-    }
-}
+pub use error::*;

+ 1 - 1
src/prelude.rs

@@ -26,7 +26,7 @@ pub(crate) use core::ptr;
 
 pub(crate) use log::{debug, info, trace, warn};
 
-pub(crate) use crate::ext4_error::*;
+pub(crate) use crate::error::*;
 pub(crate) type Result<T> = core::result::Result<T, Ext4Error>;
 
 pub(crate) type LBlockId = u32;