pub fn lock(&self, ctx: &KernelCtx<'_, '_>) -> InodeGuard<'_, InodeInner> {
        let mut guard = self.inner.lock(ctx);
        if !guard.valid {
            let mut bp = hal().disk().read(
                self.dev,
                ctx.kernel().fs().superblock().iblock(self.inum),
                ctx,
            );

            // SAFETY: dip is inside bp.data.
            let dip = unsafe {
                (bp.deref_inner_mut().data.as_mut_ptr() as *mut Dinode)
                    .add(self.inum as usize % IPB)
            };
            // SAFETY: i16 does not have internal structure.
            let t = unsafe { *(dip as *const i16) };
            // If t >= #(variants of DInodeType), UB will happen when we read dip.typ.
            assert!(t < core::mem::variant_count::<DInodeType>() as i16);
            // SAFETY: dip is aligned properly and t < #(variants of DInodeType).
            let dip = unsafe { &mut *dip };

            match dip.typ {
                DInodeType::None => guard.typ = InodeType::None,
                DInodeType::Dir => guard.typ = InodeType::Dir,
                DInodeType::File => guard.typ = InodeType::File,
                DInodeType::Device => {
                    guard.typ = InodeType::Device {
                        major: dip.major,
                        minor: dip.minor,
                    }
                }
            }
            guard.nlink = dip.nlink;
            guard.size = dip.size;
            guard.addr_direct.copy_from_slice(&dip.addr_direct);
            guard.addr_indirect = dip.addr_indirect;
            bp.free(ctx);
            guard.valid = true;
            assert_ne!(guard.typ, InodeType::None, "Inode::lock: no type");
        };
        mem::forget(guard);
        InodeGuard { inode: self }
    }
/// Lock the given inode.
/// Reads the inode from disk if necessary.
Lock the given inode.
Reads the inode from disk if necessary.
Lock the given inode . Reads the inode from disk if necessary .
pub fn lock(&self, ctx: &KernelCtx<'_, '_>) -> InodeGuard<'_, InodeInner> {
        let mut guard = self.inner.lock(ctx);
        if !guard.valid {
            let mut bp = hal().disk().read(
                self.dev,
                ctx.kernel().fs().superblock().iblock(self.inum),
                ctx,
            );
            // SAFETY: dip is inside bp.data.
            let dip = unsafe {
                (bp.deref_inner_mut().data.as_mut_ptr() as *mut Dinode)
                    .add(self.inum as usize % IPB)
            };
            // SAFETY: i16 does not have internal structure.
            let t = unsafe { *(dip as *const i16) };
            // If t >= #(variants of DInodeType), UB will happen when we read dip.typ.
            assert!(t < core::mem::variant_count::<DInodeType>() as i16);
            // SAFETY: dip is aligned properly and t < #(variants of DInodeType).
            let dip = unsafe { &mut *dip };
            match dip.typ {
                DInodeType::None => guard.typ = InodeType::None,
                DInodeType::Dir => guard.typ = InodeType::Dir,
                DInodeType::File => guard.typ = InodeType::File,
                DInodeType::Device => {
                    guard.typ = InodeType::Device {
                        major: dip.major,
                        minor: dip.minor,
                    }
                }
            }
            guard.nlink = dip.nlink;
            guard.size = dip.size;
            guard.addr_direct.copy_from_slice(&dip.addr_direct);
            guard.addr_indirect = dip.addr_indirect;
            bp.free(ctx);
            guard.valid = true;
            assert_ne!(guard.typ, InodeType::None, "Inode::lock: no type");
        };
        mem::forget(guard);
        InodeGuard { inode: self }
    }
pub fn lock ( & self , ctx : & KernelCtx < ' _ , ' _ > ) -> InodeGuard < ' _ , InodeInner > { let mut guard = self . inner . lock ( ctx ) ; if ! guard . valid { let mut bp = hal ( ) . disk ( ) . read ( self . dev , ctx . kernel ( ) . fs ( ) . superblock ( ) . iblock ( self . inum ) , ctx , ) ; // SAFETY: dip is inside bp.data. let dip = unsafe { ( bp . deref_inner_mut ( ) . data . as_mut_ptr ( ) as * mut Dinode ) . add ( self . inum as usize % IPB ) } ; // SAFETY: i16 does not have internal structure. let t = unsafe { * ( dip as * const i16 ) } ; // If t >= #(variants of DInodeType), UB will happen when we read dip.typ. assert ! ( t core mem variant_count DInodeType ( ) as i16 ) ; // SAFETY: dip is aligned properly and t < #(variants of DInodeType). let dip = unsafe { & mut * dip } ; match dip . typ { DInodeType :: None => guard . typ = InodeType :: None , DInodeType :: Dir => guard . typ = InodeType :: Dir , DInodeType :: File => guard . typ = InodeType :: File , DInodeType :: Device => { guard . typ = InodeType :: Device { major : dip . major , minor : dip . minor , } } } guard . nlink = dip . nlink ; guard . size = dip . size ; guard . addr_direct . copy_from_slice ( & dip . addr_direct ) ; guard . addr_indirect = dip . addr_indirect ; bp . free ( ctx ) ; guard . valid = true ; assert_ne ! ( guard typ InodeType None " " ) ; } ; mem :: forget ( guard ) ; InodeGuard { inode : self } }
Lock the given inode.
Lock the given inode .
&self
ctx
&KernelCtx<'_, '_>
&self
ctx
&KernelCtx<'_, '_>