Prechádzať zdrojové kódy

refactor: edit access privilege

liujingx 11 mesiacov pred
rodič
commit
ed7cb52030
5 zmenil súbory, kde vykonal 15 pridanie a 51 odobranie
  1. 4 4
      src/ext4/alloc.rs
  2. 3 3
      src/ext4/dir.rs
  3. 3 40
      src/ext4/extent.rs
  4. 3 2
      src/ext4/file.rs
  5. 2 2
      src/ext4/journal.rs

+ 4 - 4
src/ext4/alloc.rs

@@ -5,7 +5,7 @@ use crate::prelude::*;
 
 impl Ext4 {
     /// Allocate a new data block for an inode, return the physical block number
-    pub fn alloc_block(&mut self, inode_ref: &mut Ext4InodeRef, goal: PBlockId) -> PBlockId {
+    pub(super) fn alloc_block(&mut self, inode_ref: &mut Ext4InodeRef, goal: PBlockId) -> PBlockId {
         let bgid = goal / self.blocks_per_group as u64;
         let idx_in_bg = goal % self.blocks_per_group as u64;
 
@@ -48,7 +48,7 @@ impl Ext4 {
     }
 
     /// Append a data block for an inode, return a pair of (logical block id, physical block id)
-    pub fn inode_append_block(&mut self, inode_ref: &mut Ext4InodeRef) -> (LBlockId, PBlockId) {
+    pub(super) fn inode_append_block(&mut self, inode_ref: &mut Ext4InodeRef) -> (LBlockId, PBlockId) {
         let inode_size = inode_ref.inode.size();
         // The new logical block id
         let iblock = ((inode_size + BLOCK_SIZE as u64 - 1) / BLOCK_SIZE as u64) as u32;
@@ -60,7 +60,7 @@ impl Ext4 {
         (iblock, fblock)
     }
 
-    pub fn ext4_fs_inode_blocks_init(inode_ref: &mut Ext4InodeRef) {
+    pub(super) fn ext4_fs_inode_blocks_init(inode_ref: &mut Ext4InodeRef) {
         let inode = &mut inode_ref.inode;
         let mode = inode.mode;
         let inode_type = InodeMode::from_bits(mode & EXT4_INODE_MODE_TYPE_MASK as u16).unwrap();
@@ -87,7 +87,7 @@ impl Ext4 {
     }
 
     /// Allocate a new inode in the filesystem, returning the inode and its number
-    pub fn alloc_inode(&mut self, filetype: FileType) -> Ext4InodeRef {
+    pub(super) fn alloc_inode(&mut self, filetype: FileType) -> Ext4InodeRef {
         // Allocate an inode
         let is_dir = filetype == FileType::Directory;
         let id = self.do_alloc_inode(is_dir);

+ 3 - 3
src/ext4/dir.rs

@@ -5,7 +5,7 @@ use crate::prelude::*;
 
 impl Ext4 {
     /// Find a directory entry that matches a given name under a parent directory
-    pub fn dir_find_entry(&self, parent: &mut Ext4InodeRef, name: &str) -> Result<Ext4DirEntry> {
+    pub(super) fn dir_find_entry(&self, parent: &mut Ext4InodeRef, name: &str) -> Result<Ext4DirEntry> {
         let inode_size: u32 = parent.inode.size;
         let total_blocks: u32 = inode_size / BLOCK_SIZE as u32;
         let mut iblock: LBlockId = 0;
@@ -46,7 +46,7 @@ impl Ext4 {
     }
 
     /// Add an entry to a directory
-    pub fn dir_add_entry(
+    pub(super) fn dir_add_entry(
         &mut self,
         parent: &mut Ext4InodeRef,
         child: &Ext4InodeRef,
@@ -192,7 +192,7 @@ impl Ext4 {
     pub fn ext4_dir_mk(&mut self, path: &str) -> Result<()> {
         // get open flags
         let iflags = OpenFlags::from_str("w").unwrap();
-        self.ext4_generic_open(
+        self.generic_open(
             path,
             iflags,
             FileType::Directory,

+ 3 - 40
src/ext4/extent.rs

@@ -38,7 +38,7 @@ impl Ext4 {
 
     /// Given a logic block id, find the corresponding fs block id.
     /// Return 0 if not found.
-    pub fn extent_get_pblock(&self, inode_ref: &mut Ext4InodeRef, iblock: LBlockId) -> PBlockId {
+    pub(super) fn extent_get_pblock(&self, inode_ref: &mut Ext4InodeRef, iblock: LBlockId) -> PBlockId {
         let path = self.find_extent(inode_ref, iblock);
         // Leaf is the last element of the path
         let leaf = path.last().unwrap();
@@ -65,7 +65,7 @@ impl Ext4 {
 
     /// Given a logic block id, find the corresponding fs block id.
     /// Create a new extent if not found.
-    pub fn extent_get_pblock_create(
+    pub(super) fn extent_get_pblock_create(
         &mut self,
         inode_ref: &mut Ext4InodeRef,
         iblock: LBlockId,
@@ -109,7 +109,7 @@ impl Ext4 {
 
     /// Insert a new extent into a leaf node of the extent tree. Return whether
     /// the node needs to be split.
-    pub fn insert_extent(
+    pub(super) fn insert_extent(
         &self,
         inode_ref: &mut Ext4InodeRef,
         leaf: &ExtentSearchPath,
@@ -160,41 +160,4 @@ impl Ext4 {
 
         split
     }
-
-    pub fn ext4_add_extent(
-        &self,
-        inode_ref: &Ext4InodeRef,
-        depth: u16,
-        data: &[u8],
-        extents: &mut Vec<Ext4Extent>,
-        _first_level: bool,
-    ) {
-        let extent_header = Ext4ExtentHeader::load_from_block(data);
-        let extent_entries = extent_header.entries_count();
-        // log::info!("extent_entries {:x?}", extent_entries);
-        if depth == 0 {
-            for en in 0..extent_entries {
-                let idx = (3 + en * 3) as usize;
-                let extent = Ext4Extent::try_from(&data[idx..]).unwrap();
-
-                extents.push(extent)
-            }
-            return;
-        }
-
-        for en in 0..extent_entries {
-            let idx = (3 + en * 3) as usize;
-            if idx == 12 {
-                break;
-            }
-            let extent_index = Ext4ExtentIndex::try_from(&data[idx..]).unwrap();
-            let ei_leaf_lo = extent_index.leaf_lo;
-            let ei_leaf_hi = extent_index.leaf_hi;
-            let mut block = ei_leaf_lo;
-            block |= ((ei_leaf_hi as u32) << 31) << 1;
-            let data = self.block_device.read_offset(block as usize * BLOCK_SIZE);
-            // let data: Vec<u32> = unsafe { core::mem::transmute(data) };
-            self.ext4_add_extent(inode_ref, depth - 1, &data, extents, false);
-        }
-    }
 }

+ 3 - 2
src/ext4/file.rs

@@ -11,7 +11,7 @@ impl Ext4 {
         path.split("/").map(|s| s.to_string()).collect()
     }
 
-    pub fn ext4_generic_open(
+    pub(super) fn generic_open(
         &mut self,
         path: &str,
         flag: OpenFlags,
@@ -62,6 +62,7 @@ impl Ext4 {
         Ok(file)
     }
 
+    #[allow(unused)]
     pub fn ext4_open(&mut self, path: &str, flags: &str, file_expect: bool) -> Result<Ext4File> {
         // open flags
         let iflags = OpenFlags::from_str(flags).unwrap();
@@ -76,7 +77,7 @@ impl Ext4 {
             self.ext4_trans_start();
         }
         // open file
-        let res = self.ext4_generic_open(path, iflags, file_type, &self.get_root_inode_ref());
+        let res = self.generic_open(path, iflags, file_type, &self.get_root_inode_ref());
         res.map(|mut file| {
             // set mount point
             let mut ptr = Box::new(self.mount_point.clone());

+ 2 - 2
src/ext4/journal.rs

@@ -2,8 +2,8 @@ use super::Ext4;
 
 impl Ext4 {
     // start transaction
-    pub fn ext4_trans_start(&self) {}
+    pub(super) fn ext4_trans_start(&self) {}
 
     // stop transaction
-    pub fn ext4_trans_abort(&self) {}
+    pub(super) fn ext4_trans_abort(&self) {}
 }