pub async fn load_data(&mut self, offset: usize, len: usize) -> anyhow::Result<usize> {
        match self.data {
            NodeData::Directory(..) => {
                // let dir_entry_map = self.load_dir_data_helper().await?;
                let dir_entry_map = fs_util::load_dir_data(self.get_fd())
                    .await
                    .context("load_data() failed to load directory entry data")?;
                let entry_count = dir_entry_map.len();
                self.data = NodeData::Directory(dir_entry_map);
                debug!(
                    "load_data() successfully load {} directory entries",
                    entry_count
                );
                Ok(entry_count)
            }
            NodeData::RegFile(ref global_cache) => {
                let aligned_offset = global_cache.round_down(offset);
                let new_len =
                    global_cache.round_up(offset.overflow_sub(aligned_offset).overflow_add(len));

                let new_len = if new_len.overflow_add(aligned_offset) > self.attr.size.cast() {
                    self.attr.size.cast::<usize>().overflow_sub(aligned_offset)
                } else {
                    new_len
                };

                let file_data_vec = fs_util::load_file_data(self.get_fd(), aligned_offset, new_len)
                    .await
                    .context("load_data() failed to load file content data")?;
                let read_size = file_data_vec.len();
                debug!(
                    "load_data() successfully load {} byte file content data",
                    read_size
                );

                if let Err(e) = global_cache.write_or_update(
                    self.full_path.as_bytes(),
                    aligned_offset,
                    read_size,
                    &file_data_vec,
                ) {
                    panic!("writing data error while loading data: {}", e);
                }

                Ok(read_size)
            }
            NodeData::SymLink(..) => {
                panic!("forbidden to load symlink target data");
                // let target_data = self
                //     .load_symlink_target_helper()
                //     .await
                //     .context("load_data() failed to load symlink target node data")?;
                // let data_size = target_data.size();
                // self.data = NodeData::SymLink(Box::new(SymLinkData::from(
                //     self.get_symlink_target().to_owned(),
                //     target_data,
                // )));
                // debug!("load_data() successfully load symlink target node data");
                // Ok(data_size)
            }
        }
    }
// TODO: improve `load_data`, do not load all file content and directory entries at once
/// Load data from directory, file or symlink target.
/// The `offset` and `len` is used for regular file
improve `load_data`, do not load all file content and directory entries at once
Load data from directory, file or symlink target.
The `offset` and `len` is used for regular file
improve ` load_data ` do not load all file content and directory entries at once Load data from directory file or symlink target . The ` offset ` and ` len ` is used for regular file
pub async fn load_data(&mut self, offset: usize, len: usize) -> anyhow::Result<usize> {
        match self.data {
            NodeData::Directory(..) => {
                // let dir_entry_map = self.load_dir_data_helper().await?;
                let dir_entry_map = fs_util::load_dir_data(self.get_fd())
                    .await
                    .context("load_data() failed to load directory entry data")?;
                let entry_count = dir_entry_map.len();
                self.data = NodeData::Directory(dir_entry_map);
                debug!(
                    "load_data() successfully load {} directory entries",
                    entry_count
                );
                Ok(entry_count)
            }
            NodeData::RegFile(ref global_cache) => {
                let aligned_offset = global_cache.round_down(offset);
                let new_len =
                    global_cache.round_up(offset.overflow_sub(aligned_offset).overflow_add(len));
                let new_len = if new_len.overflow_add(aligned_offset) > self.attr.size.cast() {
                    self.attr.size.cast::<usize>().overflow_sub(aligned_offset)
                } else {
                    new_len
                };
                let file_data_vec = fs_util::load_file_data(self.get_fd(), aligned_offset, new_len)
                    .await
                    .context("load_data() failed to load file content data")?;
                let read_size = file_data_vec.len();
                debug!(
                    "load_data() successfully load {} byte file content data",
                    read_size
                );
                if let Err(e) = global_cache.write_or_update(
                    self.full_path.as_bytes(),
                    aligned_offset,
                    read_size,
                    &file_data_vec,
                ) {
                    panic!("writing data error while loading data: {}", e);
                }
                Ok(read_size)
            }
            NodeData::SymLink(..) => {
                panic!("forbidden to load symlink target data");
                // let target_data = self
                //     .load_symlink_target_helper()
                //     .await
                //     .context("load_data() failed to load symlink target node data")?;
                // let data_size = target_data.size();
                // self.data = NodeData::SymLink(Box::new(SymLinkData::from(
                //     self.get_symlink_target().to_owned(),
                //     target_data,
                // )));
                // debug!("load_data() successfully load symlink target node data");
                // Ok(data_size)
            }
        }
    }
pub async fn load_data ( & mut self , offset : usize , len : usize ) -> anyhow :: Result < usize > { match self . data { NodeData :: Directory ( .. ) => { // let dir_entry_map = self.load_dir_data_helper().await?; let dir_entry_map = fs_util :: load_dir_data ( self . get_fd ( ) ) . await . context ( " " ) ? ; let entry_count = dir_entry_map . len ( ) ; self . data = NodeData :: Directory ( dir_entry_map ) ; debug ! ( " " entry_count ) ; Ok ( entry_count ) } NodeData :: RegFile ( ref global_cache ) => { let aligned_offset = global_cache . round_down ( offset ) ; let new_len = global_cache . round_up ( offset . overflow_sub ( aligned_offset ) . overflow_add ( len ) ) ; let new_len = if new_len . overflow_add ( aligned_offset ) > self . attr . size . cast ( ) { self . attr . size . cast :: < usize > ( ) . overflow_sub ( aligned_offset ) } else { new_len } ; let file_data_vec = fs_util :: load_file_data ( self . get_fd ( ) , aligned_offset , new_len ) . await . context ( " " ) ? ; let read_size = file_data_vec . len ( ) ; debug ! ( " " read_size ) ; if let Err ( e ) = global_cache . write_or_update ( self . full_path . as_bytes ( ) , aligned_offset , read_size , & file_data_vec , ) { panic ! ( " " e ) ; } Ok ( read_size ) } NodeData :: SymLink ( .. ) => { panic ! ( " " ) ; // let target_data = self //     .load_symlink_target_helper() //     .await //     .context("load_data() failed to load symlink target node data")?; // let data_size = target_data.size(); // self.data = NodeData::SymLink(Box::new(SymLinkData::from( //     self.get_symlink_target().to_owned(), //     target_data, // ))); // debug!("load_data() successfully load symlink target node data"); // Ok(data_size) } } }
TODO: improve `load_data`, do not load all file content and directory entries at once
Load data from directory, file or symlink target.
TODO : improve ` load_data ` do not load all file content and directory entries at once Load data from directory file or symlink target .
&mut self
offset
usize
len
usize
&mut self
offset
usize
len
usize