|  |  |  | @ -72,7 +72,6 @@ type IndirectBlock = [u32; BLOCK_SZ / 4]; | 
			
		
	
		
			
				
					|  |  |  |  | type DataBlock = [u8; BLOCK_SZ]; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | #[repr(C)] | 
			
		
	
		
			
				
					|  |  |  |  | /// Only support level-1 indirect now, **indirect2** field is always 0.
 | 
			
		
	
		
			
				
					|  |  |  |  | pub struct DiskInode { | 
			
		
	
		
			
				
					|  |  |  |  |     pub size: u32, | 
			
		
	
		
			
				
					|  |  |  |  |     pub direct: [u32; INODE_DIRECT_COUNT], | 
			
		
	
	
		
			
				
					|  |  |  | @ -235,32 +234,6 @@ impl DiskInode { | 
			
		
	
		
			
				
					|  |  |  |  |             } 
 | 
			
		
	
		
			
				
					|  |  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     
 | 
			
		
	
		
			
				
					|  |  |  |  |     /* | 
			
		
	
		
			
				
					|  |  |  |  |     pub fn clear_size(&mut self, block_device: &Arc<dyn BlockDevice>) -> Vec<u32> { | 
			
		
	
		
			
				
					|  |  |  |  |         let mut v: Vec<u32> = Vec::new(); | 
			
		
	
		
			
				
					|  |  |  |  |         let blocks = self.blocks() as usize; | 
			
		
	
		
			
				
					|  |  |  |  |         self.size = 0; | 
			
		
	
		
			
				
					|  |  |  |  |         for i in 0..blocks.min(INODE_DIRECT_COUNT) { | 
			
		
	
		
			
				
					|  |  |  |  |             v.push(self.direct[i]); | 
			
		
	
		
			
				
					|  |  |  |  |             self.direct[i] = 0; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         if blocks > INODE_DIRECT_COUNT { | 
			
		
	
		
			
				
					|  |  |  |  |             get_block_cache( | 
			
		
	
		
			
				
					|  |  |  |  |                 self.indirect1 as usize, | 
			
		
	
		
			
				
					|  |  |  |  |                 Arc::clone(block_device), | 
			
		
	
		
			
				
					|  |  |  |  |             ) | 
			
		
	
		
			
				
					|  |  |  |  |             .lock() | 
			
		
	
		
			
				
					|  |  |  |  |             .modify(0, |indirect_block: &mut IndirectBlock| { | 
			
		
	
		
			
				
					|  |  |  |  |                 for i in 0..blocks - INODE_DIRECT_COUNT { | 
			
		
	
		
			
				
					|  |  |  |  |                     v.push(indirect_block[i]); | 
			
		
	
		
			
				
					|  |  |  |  |                     indirect_block[i] = 0; | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         v | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     */ | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /// Clear size to zero and return blocks that should be deallocated.
 | 
			
		
	
		
			
				
					|  |  |  |  |     ///
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -434,10 +407,13 @@ pub struct DirEntry { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | pub const DIRENT_SZ: usize = 32; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //pub type DirentBlock = [DirEntry; BLOCK_SZ / DIRENT_SZ];
 | 
			
		
	
		
			
				
					|  |  |  |  | pub type DirentBytes = [u8; DIRENT_SZ]; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | impl DirEntry { | 
			
		
	
		
			
				
					|  |  |  |  |     pub fn empty() -> Self { | 
			
		
	
		
			
				
					|  |  |  |  |         Self { | 
			
		
	
		
			
				
					|  |  |  |  |             name: [0u8; NAME_LENGTH_LIMIT + 1], | 
			
		
	
		
			
				
					|  |  |  |  |             inode_number: 0, | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     pub fn new(name: &str, inode_number: u32) -> Self { | 
			
		
	
		
			
				
					|  |  |  |  |         let mut bytes = [0u8; NAME_LENGTH_LIMIT + 1]; | 
			
		
	
		
			
				
					|  |  |  |  |         &mut bytes[..name.len()].copy_from_slice(name.as_bytes()); | 
			
		
	
	
		
			
				
					|  |  |  | @ -446,18 +422,20 @@ impl DirEntry { | 
			
		
	
		
			
				
					|  |  |  |  |             inode_number, | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     pub fn into_bytes(&self) -> &DirentBytes { | 
			
		
	
		
			
				
					|  |  |  |  |     pub fn as_bytes(&self) -> &[u8] { | 
			
		
	
		
			
				
					|  |  |  |  |         unsafe { | 
			
		
	
		
			
				
					|  |  |  |  |             &*(self as *const Self as usize as *const DirentBytes) | 
			
		
	
		
			
				
					|  |  |  |  |             core::slice::from_raw_parts( | 
			
		
	
		
			
				
					|  |  |  |  |                 self as *const _ as usize as *const u8, | 
			
		
	
		
			
				
					|  |  |  |  |                 DIRENT_SZ, | 
			
		
	
		
			
				
					|  |  |  |  |             ) | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     pub fn from_bytes(bytes: &DirentBytes) -> &Self { | 
			
		
	
		
			
				
					|  |  |  |  |         unsafe { &*(bytes.as_ptr() as usize as *const Self) } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     #[allow(unused)] | 
			
		
	
		
			
				
					|  |  |  |  |     pub fn from_bytes_mut(bytes: &mut DirentBytes) -> &mut Self { | 
			
		
	
		
			
				
					|  |  |  |  |     pub fn as_bytes_mut(&mut self) -> &mut [u8] { | 
			
		
	
		
			
				
					|  |  |  |  |         unsafe { | 
			
		
	
		
			
				
					|  |  |  |  |             &mut *(bytes.as_mut_ptr() as usize as *mut Self) | 
			
		
	
		
			
				
					|  |  |  |  |             core::slice::from_raw_parts_mut( | 
			
		
	
		
			
				
					|  |  |  |  |                 self as *mut _ as usize as *mut u8, | 
			
		
	
		
			
				
					|  |  |  |  |                 DIRENT_SZ, | 
			
		
	
		
			
				
					|  |  |  |  |             ) | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     pub fn name(&self) -> &str { | 
			
		
	
	
		
			
				
					|  |  |  | 
 |