pub fn allocate_available_block(&mut self, size: u64) -> u64 {
        if size >= EROFS_BLOCK_SIZE {
            return 0;
        }

        let min_idx = div_round_up(size, EROFS_INODE_SLOT_SIZE as u64) as usize;
        let max_idx = div_round_up(EROFS_BLOCK_SIZE, EROFS_INODE_SLOT_SIZE as u64) as usize;

        for idx in min_idx..max_idx {
            let blocks = &mut self.available_blocks[idx];
            if let Some(mut offset) = blocks.pop_front() {
                offset += EROFS_BLOCK_SIZE - (idx * EROFS_INODE_SLOT_SIZE) as u64;
                self.append_available_block(offset + (min_idx * EROFS_INODE_SLOT_SIZE) as u64);
                return offset;
            }
        }

        0
    }
// Only used to allocate space for metadata(inode / inode + inline data).
// Try to find an used block with no less than `size` space left.
// If found it, return the offset where we can store data.
// If not, return 0.
Only used to allocate space for metadata(inode / inode + inline data).
Try to find an used block with no less than `size` space left.
If found it, return the offset where we can store data.
If not, return 0.
Only used to allocate space for metadata ( inode / inode + inline data ) . Try to find an used block with no less than ` size ` space left . If found it return the offset where we can store data . If not return 0 .
pub fn allocate_available_block(&mut self, size: u64) -> u64 {
        if size >= EROFS_BLOCK_SIZE {
            return 0;
        }
        let min_idx = div_round_up(size, EROFS_INODE_SLOT_SIZE as u64) as usize;
        let max_idx = div_round_up(EROFS_BLOCK_SIZE, EROFS_INODE_SLOT_SIZE as u64) as usize;
        for idx in min_idx..max_idx {
            let blocks = &mut self.available_blocks[idx];
            if let Some(mut offset) = blocks.pop_front() {
                offset += EROFS_BLOCK_SIZE - (idx * EROFS_INODE_SLOT_SIZE) as u64;
                self.append_available_block(offset + (min_idx * EROFS_INODE_SLOT_SIZE) as u64);
                return offset;
            }
        }
        0
    }
pub fn allocate_available_block ( & mut self , size : u64 ) -> u64 { if size >= EROFS_BLOCK_SIZE { return 0 ; } let min_idx = div_round_up ( size , EROFS_INODE_SLOT_SIZE as u64 ) as usize ; let max_idx = div_round_up ( EROFS_BLOCK_SIZE , EROFS_INODE_SLOT_SIZE as u64 ) as usize ; for idx in min_idx .. max_idx { let blocks = & mut self . available_blocks [ idx ] ; if let Some ( mut offset ) = blocks . pop_front ( ) { offset += EROFS_BLOCK_SIZE - ( idx * EROFS_INODE_SLOT_SIZE ) as u64 ; self . append_available_block ( offset + ( min_idx * EROFS_INODE_SLOT_SIZE ) as u64 ) ; return offset ; } } 0 }
Only used to allocate space for metadata(inode / inode + inline data).
Only used to allocate space for metadata ( inode / inode + inline data ) .
&mut self
size
u64
&mut self
size
u64