Lines Matching refs:bg

41 	int bg;
115 reg->bg * info.blocks_per_group + reg->block,
116 reg->bg * info.blocks_per_group + reg->block + reg->len - 1,
138 reg->bg = bg_num;
144 static void allocate_bg_inode_table(struct block_group_info *bg)
146 if (bg->inode_table != NULL)
149 u32 block = bg->first_block + 2;
151 if (bg->has_superblock)
154 bg->inode_table = calloc(aux_info.inode_table_blocks, info.block_size);
155 if (bg->inode_table == NULL)
158 sparse_file_add_data(info.sparse_file, bg->inode_table,
166 struct block_group_info *bg;
170 bg = &aux_info.bgs[i];
171 block = bg->first_block + 2;
172 if (bg->has_superblock)
198 static int reserve_blocks(struct block_group_info *bg, u32 start, u32 num)
203 if (num > bg->free_blocks)
207 if (bitmap_set_bit(bg->block_bitmap, block)) {
214 if (bitmap_set_8_bits(bg->block_bitmap, block)) {
221 if (bitmap_set_bit(bg->block_bitmap, block)) {
227 bg->free_blocks -= num;
228 if (start == bg->first_free_block)
229 bg->first_free_block = start + num;
234 static void free_blocks(struct block_group_info *bg, u32 num_blocks)
237 u32 block = bg->first_free_block - 1;
239 bg->block_bitmap[block / 8] &= ~(1 << (block % 8));
240 bg->free_blocks += num_blocks;
241 bg->first_free_block -= num_blocks;
253 free_blocks(&aux_info.bgs[last_reg->bg], len);
258 free_blocks(&aux_info.bgs[last_reg->bg], last_reg->len);
273 static void init_bg(struct block_group_info *bg, unsigned int i)
277 bg->has_superblock = ext4_bg_has_super_block(i);
279 if (bg->has_superblock)
282 bg->bitmaps = calloc(info.block_size, 2);
283 bg->block_bitmap = bg->bitmaps;
284 bg->inode_bitmap = bg->bitmaps + info.block_size;
286 bg->header_blocks = header_blocks;
287 bg->first_block = aux_info.first_data_block + i * info.blocks_per_group;
289 u32 block = bg->first_block;
290 if (bg->has_superblock)
292 sparse_file_add_data(info.sparse_file, bg->bitmaps, 2 * info.block_size,
295 bg->data_blocks_used = 0;
296 bg->free_blocks = info.blocks_per_group;
297 bg->first_free_block = 0;
298 bg->free_inodes = info.inodes_per_group;
299 bg->first_free_inode = 1;
301 if (reserve_blocks(bg, bg->first_free_block, bg->header_blocks) < 0)
302 error("failed to reserve %u blocks in block group %u\n", bg->header_blocks, i);
304 u32 overrun = bg->first_block + info.blocks_per_group - aux_info.len_blocks;
306 reserve_blocks(bg, info.blocks_per_group - overrun, overrun);
338 struct block_group_info *bg = &aux_info.bgs[bg_num];
339 if (reserve_blocks(bg, bg->first_free_block, len) < 0) {
346 return bg->first_block + block;
363 reg->bg = i;
414 reg->bg = i;
548 u32 get_free_blocks(u32 bg)
550 return aux_info.bgs[bg].free_blocks;
581 new->bg = reg->bg;
682 int bg = inode / info.inodes_per_group;
685 allocate_bg_inode_table(&aux_info.bgs[bg]);
686 return (struct ext4_inode *)(aux_info.bgs[bg].inode_table + inode *
691 u32 reserve_inodes(int bg, u32 num)
696 if (get_free_inodes(bg) < num)
700 inode = aux_info.bgs[bg].first_free_inode + i - 1;
701 aux_info.bgs[bg].inode_bitmap[inode / 8] |= 1 << (inode % 8);
704 inode = aux_info.bgs[bg].first_free_inode;
706 aux_info.bgs[bg].first_free_inode += num;
707 aux_info.bgs[bg].free_inodes -= num;
716 unsigned int bg;
719 for (bg = 0; bg < aux_info.groups; bg++) {
720 inode = reserve_inodes(bg, 1);
722 return bg * info.inodes_per_group + inode;
729 u32 get_free_inodes(u32 bg)
731 return aux_info.bgs[bg].free_inodes;
737 int bg = (inode - 1) / info.inodes_per_group;
738 aux_info.bgs[bg].used_dirs += 1;
742 u16 get_directories(int bg)
744 return aux_info.bgs[bg].used_dirs;