async fn open_child_dir_helper(
        &mut self,
        child_dir_name: OsString,
        mode: Mode,
        create_dir: bool,
    ) -> anyhow::Result<Self> {
        let ino = self.get_ino();
        let fd = self.fd;
        let dir_data = self.get_dir_data_mut();
        if create_dir {
            debug_assert!(
                !dir_data.contains_key(&child_dir_name),
                "open_child_dir_helper() cannot create duplicated directory name={:?}",
                child_dir_name
            );
            let child_dir_name_clone = child_dir_name.clone();
            smol::unblock(move || stat::mkdirat(fd, child_dir_name_clone.as_os_str(), mode))
                .await
                .context(format!(
                    "open_child_dir_helper() failed to create directory \
                        name={:?} under parent ino={}",
                    child_dir_name, ino,
                ))?;
        }

        let child_dir_name_clone = child_dir_name.clone();
        let child_raw_fd = fs_util::open_dir_at(fd, child_dir_name_clone)
            .await
            .context(format!(
                "open_child_dir_helper() failed to open the new directory name={:?} \
                    under parent ino={}",
                child_dir_name, ino,
            ))?;

        // get new directory attribute
        let child_attr = fs_util::load_attr(child_raw_fd).await.context(format!(
            "open_child_dir_helper() failed to get the attribute of the new child directory={:?}",
            child_dir_name,
        ))?;
        debug_assert_eq!(SFlag::S_IFDIR, child_attr.kind);

        if create_dir {
            // insert new entry to parent directory
            // TODO: support thread-safe
            let previous_value = dir_data.insert(
                child_dir_name.clone(),
                DirEntry::new(child_attr.ino, child_dir_name.clone(), SFlag::S_IFDIR),
            );
            debug_assert!(previous_value.is_none()); // double check creation race
        }

        let mut full_path = OsString::clone(&self.full_path);
        full_path.push(OsString::clone(&child_dir_name));
        full_path.push("/");

        // lookup count and open count are increased to 1 by creation
        let child_node = Self::new(
            self.get_ino(),
            child_dir_name,
            full_path,
            child_attr,
            NodeData::Directory(BTreeMap::new()),
            child_raw_fd,
        );

        // if !create_dir {
        //     // load directory data on open
        //     child_node
        //         .load_data()
        //         .await
        //         .context("open_child_dir_helper() failed to load child directory entry data")?;
        // }
        Ok(child_node)
    }
/// Helper function to create or open sub-directory in a directory
Helper function to create or open sub-directory in a directory
Helper function to create or open sub - directory in a directory
async fn open_child_dir_helper(
        &mut self,
        child_dir_name: OsString,
        mode: Mode,
        create_dir: bool,
    ) -> anyhow::Result<Self> {
        let ino = self.get_ino();
        let fd = self.fd;
        let dir_data = self.get_dir_data_mut();
        if create_dir {
            debug_assert!(
                !dir_data.contains_key(&child_dir_name),
                "open_child_dir_helper() cannot create duplicated directory name={:?}",
                child_dir_name
            );
            let child_dir_name_clone = child_dir_name.clone();
            smol::unblock(move || stat::mkdirat(fd, child_dir_name_clone.as_os_str(), mode))
                .await
                .context(format!(
                    "open_child_dir_helper() failed to create directory \
                        name={:?} under parent ino={}",
                    child_dir_name, ino,
                ))?;
        }
        let child_dir_name_clone = child_dir_name.clone();
        let child_raw_fd = fs_util::open_dir_at(fd, child_dir_name_clone)
            .await
            .context(format!(
                "open_child_dir_helper() failed to open the new directory name={:?} \
                    under parent ino={}",
                child_dir_name, ino,
            ))?;
        // get new directory attribute
        let child_attr = fs_util::load_attr(child_raw_fd).await.context(format!(
            "open_child_dir_helper() failed to get the attribute of the new child directory={:?}",
            child_dir_name,
        ))?;
        debug_assert_eq!(SFlag::S_IFDIR, child_attr.kind);
        if create_dir {
            // insert new entry to parent directory
            // TODO: support thread-safe
            let previous_value = dir_data.insert(
                child_dir_name.clone(),
                DirEntry::new(child_attr.ino, child_dir_name.clone(), SFlag::S_IFDIR),
            );
            debug_assert!(previous_value.is_none()); // double check creation race
        }
        let mut full_path = OsString::clone(&self.full_path);
        full_path.push(OsString::clone(&child_dir_name));
        full_path.push("/");
        // lookup count and open count are increased to 1 by creation
        let child_node = Self::new(
            self.get_ino(),
            child_dir_name,
            full_path,
            child_attr,
            NodeData::Directory(BTreeMap::new()),
            child_raw_fd,
        );
        // if !create_dir {
        //     // load directory data on open
        //     child_node
        //         .load_data()
        //         .await
        //         .context("open_child_dir_helper() failed to load child directory entry data")?;
        // }
        Ok(child_node)
    }
async fn open_child_dir_helper ( & mut self , child_dir_name : OsString , mode : Mode , create_dir : bool , ) -> anyhow :: Result < Self > { let ino = self . get_ino ( ) ; let fd = self . fd ; let dir_data = self . get_dir_data_mut ( ) ; if create_dir { debug_assert ! ( dir_data contains_key ( child_dir_name ) " " child_dir_name ) ; let child_dir_name_clone = child_dir_name . clone ( ) ; smol :: unblock ( move | | stat :: mkdirat ( fd , child_dir_name_clone . as_os_str ( ) , mode ) ) . await . context ( format ! ( " \
 " child_dir_name ino ) ) ? ; } let child_dir_name_clone = child_dir_name . clone ( ) ; let child_raw_fd = fs_util :: open_dir_at ( fd , child_dir_name_clone ) . await . context ( format ! ( " \
 " child_dir_name ino ) ) ? ; // get new directory attribute let child_attr = fs_util :: load_attr ( child_raw_fd ) . await . context ( format ! ( " " child_dir_name ) ) ? ; debug_assert_eq ! ( SFlag S_IFDIR child_attr kind ) ; if create_dir { // insert new entry to parent directory // TODO: support thread-safe let previous_value = dir_data . insert ( child_dir_name . clone ( ) , DirEntry :: new ( child_attr . ino , child_dir_name . clone ( ) , SFlag :: S_IFDIR ) , ) ; debug_assert ! ( previous_value is_none ( ) ) ; // double check creation race } let mut full_path = OsString :: clone ( & self . full_path ) ; full_path . push ( OsString :: clone ( & child_dir_name ) ) ; full_path . push ( " " ) ; // lookup count and open count are increased to 1 by creation let child_node = Self :: new ( self . get_ino ( ) , child_dir_name , full_path , child_attr , NodeData :: Directory ( BTreeMap :: new ( ) ) , child_raw_fd , ) ; // if !create_dir { //     // load directory data on open //     child_node //         .load_data() //         .await //         .context("open_child_dir_helper() failed to load child directory entry data")?; // } Ok ( child_node ) }
Helper function to create or open sub-directory in a directory
Helper function to create or open sub - directory in a directory
&mut self
child_dir_name
OsString
mode
Mode
create_dir
bool
&mut self
child_dir_name
OsString
mode
Mode
create_dir
bool