ソースを参照

doc: explanations of important structs

liujingx 10 ヶ月 前
コミット
b303fbe40d

+ 1 - 3
src/ext4_defs/block_group.rs

@@ -1,6 +1,4 @@
-//!# The Defination of Ext4 Block Group Description
-//!
-//! Block Group Descriptor is the second field of Ext4 Block Group.
+//! The Block Group Descriptor is the second field of Ext4 Block Group.
 //!
 //! | Super Block | Group Descriptor | Reserved GDT Blocks |
 //! | Block Bitmap | Inode Bitmap | Inode Table | Data Blocks |

+ 19 - 28
src/ext4_defs/dir_entry.rs

@@ -1,5 +1,3 @@
-//! # The Defination of Ext4 Directory Entry
-//!
 //! A directory is a series of data blocks and that each block contains a
 //! linear array of directory entries.
 
@@ -32,27 +30,31 @@ impl Default for DirEnInner {
     }
 }
 
+/// Directory entry.
 #[repr(C)]
 #[derive(Debug, Clone)]
 pub struct DirEntry {
-    inode: InodeId,    // 该目录项指向的inode的编号
-    rec_len: u16,      // 到下一个目录项的距离
-    name_len: u8,      // 低8位的文件名长度
-    inner: DirEnInner, // 联合体成员
-    name: [u8; 255],   // 文件名
+    /// 该目录项指向的inode的编号
+    inode: InodeId,
+    /// 到下一个目录项的距离
+    rec_len: u16,
+    /// 低8位的文件名长度
+    name_len: u8,
+    /// 联合体成员
+    inner: DirEnInner,
+    /// 文件名
+    name: [u8; 255],
 }
 
-impl Default for DirEntry {
-    fn default() -> Self {
-        Self {
-            inode: 0,
-            rec_len: 0,
-            name_len: 0,
-            inner: DirEnInner::default(),
-            name: [0; 255],
-        }
-    }
+/// Fake dir entry. A normal entry without `name` field
+#[repr(C)]
+pub struct FakeDirEntry {
+    inode: u32,
+    rec_len: u16,
+    name_len: u8,
+    inode_type: FileType,
 }
+unsafe impl AsBytes for FakeDirEntry {}
 
 /// The actual size of the directory entry is determined by `name_len`.
 /// So we need to implement `AsBytes` methods specifically for `DirEntry`.
@@ -195,14 +197,3 @@ impl DirEntryTail {
         self.checksum = crc32(csum, &block.data[..size_of::<DirEntryTail>()]);
     }
 }
-
-/// Fake dir entry. A normal entry without `name` field`
-#[repr(C)]
-pub struct FakeDirEntry {
-    inode: u32,
-    rec_len: u16,
-    name_len: u8,
-    inode_type: FileType,
-}
-
-unsafe impl AsBytes for FakeDirEntry {}

+ 0 - 5
src/ext4_defs/extent.rs

@@ -52,11 +52,6 @@ impl ExtentHeader {
         }
     }
 
-    /// Loads an extent header from a data block.
-    pub fn load_from_block(block_data: &[u8]) -> &Self {
-        unsafe { &*(block_data.as_ptr() as *const ExtentHeader) }
-    }
-
     /// 获取extent header的条目数
     pub fn entries_count(&self) -> u16 {
         self.entries_count

+ 10 - 3
src/ext4_defs/inode.rs

@@ -1,6 +1,4 @@
-//! # The Defination of Ext4 Inode Table Entry
-//!
-//! The inode table is a linear array of struct `Inode`. 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
@@ -310,6 +308,15 @@ impl Inode {
         self.flags |= f;
     }
 
+    pub fn xattr_block(&self) -> PBlockId {
+        (self.osd2.l_file_acl_hi as u64) << 32 | self.file_acl as u64
+    }
+
+    pub fn set_xattr_block(&mut self, block: PBlockId) {
+        self.file_acl = block as u32;
+        self.osd2.l_file_acl_hi = (block >> 32) as u16;
+    }
+
     /* Extent methods */
 
     /// Get the immutable extent root node

+ 2 - 3
src/ext4_defs/super_block.rs

@@ -1,8 +1,7 @@
-//! # The Defination of Ext4 Super Block
-//!
-//! Super Block is the first field of Ext4 Block Group.
+//! The Super Block is the first field of Ext4 Block Group.
 //!
 //! See [`super::block_group`] for details.
+
 use super::AsBytes;
 use crate::prelude::*;