From ec2f349a648e4d87fba12d20e338b1cd6d8ef29a Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Mon, 27 Nov 2023 00:11:55 -0800 Subject: Fix directory stuff --- src/tests/block_cache.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'src/tests/block_cache.rs') diff --git a/src/tests/block_cache.rs b/src/tests/block_cache.rs index 90875ae..52117b9 100644 --- a/src/tests/block_cache.rs +++ b/src/tests/block_cache.rs @@ -26,8 +26,8 @@ fn test_basic_lru() { fn test_inode_allocation() { let mut fs = common::setup(); - let inode_index = fs.create_inode(0o755, InodeMode::IFDIR, 0, 0, 0).unwrap(); - let mut inode = fs.get_inode(inode_index).unwrap().clone(); + let (inode_index, inode) = fs.create_directory(0o755, 0, 0, 0, None).unwrap(); + let mut inode = inode.clone(); const DIRECT_NUMBER: u32 = 15; const INDIRECT_NUMBER: u32 = 1024; @@ -76,20 +76,20 @@ fn test_inode_allocation() { fn test_inode_deallocation() { let mut fs = common::setup(); - let inode_index = fs.create_inode(0o755, InodeMode::IFDIR, 0, 0, 0).unwrap(); - let mut inode = fs.get_inode(inode_index).unwrap().clone(); + let (inode_index, inode) = fs.create_directory(0o755, 0, 0, 0, None).unwrap(); + let mut inode = inode.clone(); const DIRECT_NUMBER: u32 = 15; const INDIRECT_NUMBER: u32 = 1024; // const DOUBLE_INDIRECT_NUMBER: u32 = 1024 * 1024; for i in 0..DIRECT_NUMBER { - println!("Allocated {}", fs.allocate_block_for(&mut inode).unwrap()); + println!("Allocated {:?}", fs.allocate_block_for(&mut inode).unwrap()); assert!(fs.data_bitmap.query(inode.direct[i as usize] as usize)) } for _i in 0..2 * INDIRECT_NUMBER { - println!("Allocated {}", fs.allocate_block_for(&mut inode).unwrap()); + println!("Allocated {:?}", fs.allocate_block_for(&mut inode).unwrap()); } println!("single indirect is {}", inode.single_indirect); @@ -118,30 +118,33 @@ fn test_inode_deallocation() { fn test_multiple_inode_allocation() { let mut fs = common::setup(); - let inode_index_1 = fs.create_inode(0o755, InodeMode::IFDIR, 0, 0, 0).unwrap(); - let inode_index_2 = fs.create_inode(0o755, InodeMode::IFREG, 0, 0, 0).unwrap(); + let (inode_index_1, inode_1) = fs.create_directory(0o755, 0, 0, 0, None).unwrap(); + let mut inode_1 = inode_1.clone(); - let mut inode_1 = fs.get_inode(inode_index_1).unwrap().clone(); - let mut inode_2 = fs.get_inode(inode_index_2).unwrap().clone(); + let (inode_index_2, inode_2) = fs.create_file(0o755, 0, 0, 0).unwrap(); + let mut inode_2 = inode_2.clone(); + // let mut inode_1 = fs.get_inode(inode_index_1).unwrap().clone(); + // let mut inode_2 = fs.get_inode(inode_index_2).unwrap().clone(); const DIRECT_NUMBER: u32 = 15; const INDIRECT_NUMBER: u32 = 1024; for i in 0..DIRECT_NUMBER + INDIRECT_NUMBER { println!( - "Allocated {} in inode {}", + "Allocated {:?} in inode {}", fs.allocate_block_for(&mut inode_1).unwrap(), inode_index_1 ); println!( - "Allocated {} in inode {}", + "Allocated {:?} in inode {}", fs.allocate_block_for(&mut inode_2).unwrap(), inode_index_2 ); } - let inode_index_3 = fs.create_inode(0o755, InodeMode::IFDIR, 0, 0, 0).unwrap(); - let mut inode_3 = fs.get_inode(inode_index_3).unwrap().clone(); + let (inode_index_3, inode_3) = fs.create_directory(0o755, 0, 0, 0, None).unwrap(); + let mut inode_3 = inode_3.clone(); + // let mut inode_3 = fs.get_inode(inode_index_3).unwrap().clone(); for _i in 0..INDIRECT_NUMBER { println!( @@ -150,7 +153,7 @@ fn test_multiple_inode_allocation() { inode_index_1 ); println!( - "Allocated {} in inode {}", + "Allocated {:?} in inode {}", fs.allocate_block_for(&mut inode_3).unwrap(), inode_index_3 ); -- cgit v1.2.3-70-g09d2