liujingx 1 рік тому
батько
коміт
9bcdd78208
3 змінених файлів з 6 додано та 10 видалено
  1. 1 5
      ext4_test/src/main.rs
  2. 3 3
      src/ext4/extent.rs
  3. 2 2
      src/ext4_defs/extent.rs

+ 1 - 5
ext4_test/src/main.rs

@@ -1,5 +1,4 @@
 use ext4_rs::{Block, BlockDevice, Ext4, BLOCK_SIZE};
-use log::warn;
 use simple_logger::SimpleLogger;
 use std::fs::{File, OpenOptions};
 use std::io::{Read, Seek, SeekFrom, Write};
@@ -29,9 +28,6 @@ impl BlockDevice for BlockFile {
     }
 
     fn write_block(&self, block: &Block) {
-        if block.block_id == 2135 {
-            warn!("!!!!! 2135");
-        }
         let mut file = &self.0;
         let _r = file.seek(SeekFrom::Start(block.block_id * BLOCK_SIZE as u64));
         let _r = file.write_all(&block.data);
@@ -95,7 +91,7 @@ fn read_write_test(ext4: &mut Ext4) {
 }
 
 fn large_read_write_test(ext4: &mut Ext4) {
-    let wbuffer = vec![99u8; 1024 * 1024];
+    let wbuffer = vec![99u8; 1024 * 1024 * 2];
     let mut wfile = ext4.open("d3/f2", "w+", true).expect("open failed");
     ext4.write(&mut wfile, &wbuffer).expect("write failed");
 

+ 3 - 3
src/ext4/extent.rs

@@ -173,7 +173,7 @@ impl Ext4 {
     }
 
     /// Split an extent node. Given the block id where the parent node is
-    /// stored, and the child position where `parent_node.extent_at(child_pos)`
+    /// stored, and the child position that `parent_node.extent_at(child_pos)`
     /// points to the child.
     ///
     /// The child node has already been split by calling `insert_extent` or
@@ -207,13 +207,13 @@ impl Ext4 {
         if parent_pblock == 0 {
             // Parent is root
             let mut parent_node = inode_ref.inode.extent_node_mut();
-            res = parent_node.insert_extent_index(&extent_index, child_pos);
+            res = parent_node.insert_extent_index(&extent_index, child_pos + 1);
             self.write_inode_without_csum(inode_ref);
         } else {
             // Parent is not root
             let mut parent_block = self.block_device.read_block(parent_pblock);
             let mut parent_node = ExtentNodeMut::from_bytes(&mut parent_block.data);
-            res = parent_node.insert_extent_index(&extent_index, child_pos);
+            res = parent_node.insert_extent_index(&extent_index, child_pos + 1);
             parent_block.sync_to_disk(self.block_device.clone());
         }
         res

+ 2 - 2
src/ext4_defs/extent.rs

@@ -497,7 +497,7 @@ impl<'a> ExtentNodeMut<'a> {
         // The extent node is full and all extents are valid
         // Split the node, return the extents in the right half
         let mut split = Vec::new();
-        let mid = self.header().entries_count() as usize / 2;
+        let mid = self.header().entries_count() as usize * 2 / 3;
         // If `pos` is on the right side, insert it to `split`
         for i in mid..self.header().entries_count() as usize {
             if i == pos {
@@ -545,7 +545,7 @@ impl<'a> ExtentNodeMut<'a> {
         // The extent node is full
         // Split the node, return the extent indexs in the right half
         let mut split = Vec::<FakeExtent>::new();
-        let mid = self.header().entries_count() as usize / 2;
+        let mid = self.header().entries_count() as usize * 2 / 3;
         // If `pos` is on the right side, insert it to `split`
         for i in mid..self.header().entries_count() as usize {
             if i == pos {