Lines Matching refs:bg
41 int bg;
141 reg->bg * info.blocks_per_group + reg->block,
142 reg->bg * info.blocks_per_group + reg->block + reg->len - 1,
164 reg->bg = bg_num;
170 static void allocate_bg_inode_table(struct block_group_info *bg)
172 if (bg->inode_table != NULL)
175 u32 block = bg->first_block + 2;
177 if (bg->has_superblock)
180 bg->inode_table = calloc(aux_info.inode_table_blocks, info.block_size);
181 if (bg->inode_table == NULL)
184 sparse_file_add_data(info.sparse_file, bg->inode_table,
187 bg->flags &= ~EXT4_BG_INODE_UNINIT;
208 static int reserve_blocks(struct block_group_info *bg, u32 start, u32 num)
213 if (num > bg->free_blocks)
217 if (bitmap_set_bit(bg->block_bitmap, block)) {
224 if (bitmap_set_8_bits(bg->block_bitmap, block)) {
231 if (bitmap_set_bit(bg->block_bitmap, block)) {
237 bg->free_blocks -= num;
238 if (start == bg->first_free_block)
239 bg->first_free_block = start + num;
244 static void free_blocks(struct block_group_info *bg, u32 num_blocks)
247 u32 block = bg->first_free_block - 1;
249 bg->block_bitmap[block / 8] &= ~(1 << (block % 8));
250 bg->free_blocks += num_blocks;
251 bg->first_free_block -= num_blocks;
263 free_blocks(&aux_info.bgs[last_reg->bg], len);
268 free_blocks(&aux_info.bgs[last_reg->bg], last_reg->len);
283 static void init_bg(struct block_group_info *bg, unsigned int i)
287 bg->has_superblock = ext4_bg_has_super_block(i);
289 if (bg->has_superblock)
292 bg->bitmaps = calloc(info.block_size, 2);
293 bg->block_bitmap = bg->bitmaps;
294 bg->inode_bitmap = bg->bitmaps + info.block_size;
296 bg->header_blocks = header_blocks;
297 bg->first_block = aux_info.first_data_block + i * info.blocks_per_group;
299 u32 block = bg->first_block;
300 if (bg->has_superblock)
302 sparse_file_add_data(info.sparse_file, bg->bitmaps, 2 * info.block_size,
305 bg->data_blocks_used = 0;
306 bg->free_blocks = info.blocks_per_group;
307 bg->first_free_block = 0;
308 bg->free_inodes = info.inodes_per_group;
309 bg->first_free_inode = 1;
310 bg->flags = EXT4_BG_INODE_UNINIT;
312 if (reserve_blocks(bg, bg->first_free_block, bg->header_blocks) < 0)
313 error("failed to reserve %u blocks in block group %u\n", bg->header_blocks, i);
315 u32 overrun = bg->first_block + info.blocks_per_group - aux_info.len_blocks;
317 reserve_blocks(bg, info.blocks_per_group - overrun, overrun);
349 struct block_group_info *bg = &aux_info.bgs[bg_num];
350 if (reserve_blocks(bg, bg->first_free_block, len) < 0) {
357 return bg->first_block + block;
374 reg->bg = i;
425 reg->bg = i;
559 u32 get_free_blocks(u32 bg)
561 return aux_info.bgs[bg].free_blocks;
592 new->bg = reg->bg;
693 int bg = inode / info.inodes_per_group;
696 allocate_bg_inode_table(&aux_info.bgs[bg]);
697 return (struct ext4_inode *)(aux_info.bgs[bg].inode_table + inode *
731 u32 reserve_inodes(int bg, u32 num)
736 if (get_free_inodes(bg) < num)
740 inode = aux_info.bgs[bg].first_free_inode + i - 1;
741 aux_info.bgs[bg].inode_bitmap[inode / 8] |= 1 << (inode % 8);
744 inode = aux_info.bgs[bg].first_free_inode;
746 aux_info.bgs[bg].first_free_inode += num;
747 aux_info.bgs[bg].free_inodes -= num;
756 unsigned int bg;
759 for (bg = 0; bg < aux_info.groups; bg++) {
760 inode = reserve_inodes(bg, 1);
762 return bg * info.inodes_per_group + inode;
769 u32 get_free_inodes(u32 bg)
771 return aux_info.bgs[bg].free_inodes;
777 int bg = (inode - 1) / info.inodes_per_group;
778 aux_info.bgs[bg].used_dirs += 1;
782 u16 get_directories(int bg)
784 return aux_info.bgs[bg].used_dirs;
788 u16 get_bg_flags(int bg)
790 return aux_info.bgs[bg].flags;