Lines Matching defs:bg
40 int bg;
114 reg->bg * info.blocks_per_group + reg->block,
115 reg->bg * info.blocks_per_group + reg->block + reg->len - 1,
137 reg->bg = bg_num;
143 static void allocate_bg_inode_table(struct block_group_info *bg)
145 if (bg->inode_table != NULL)
148 u32 block = bg->first_block + 2;
150 if (bg->has_superblock)
153 bg->inode_table = calloc(aux_info.inode_table_blocks, info.block_size);
154 if (bg->inode_table == NULL)
157 queue_data_block(bg->inode_table, aux_info.inode_table_blocks
165 struct block_group_info *bg;
169 bg = &aux_info.bgs[i];
170 block = bg->first_block + 2;
171 if (bg->has_superblock)
196 static int reserve_blocks(struct block_group_info *bg, u32 start, u32 num)
201 if (num > bg->free_blocks)
205 if (bitmap_set_bit(bg->block_bitmap, block)) {
212 if (bitmap_set_8_bits(bg->block_bitmap, block)) {
219 if (bitmap_set_bit(bg->block_bitmap, block)) {
225 bg->free_blocks -= num;
226 if (start == bg->first_free_block)
227 bg->first_free_block = start + num;
232 static void free_blocks(struct block_group_info *bg, u32 num_blocks)
235 u32 block = bg->first_free_block - 1;
237 bg->block_bitmap[block / 8] &= ~(1 << (block % 8));
238 bg->free_blocks += num_blocks;
239 bg->first_free_block -= num_blocks;
251 free_blocks(&aux_info.bgs[last_reg->bg], len);
256 free_blocks(&aux_info.bgs[last_reg->bg], last_reg->len);
271 static void init_bg(struct block_group_info *bg, unsigned int i)
275 bg->has_superblock = ext4_bg_has_super_block(i);
277 if (bg->has_superblock)
280 bg->bitmaps = calloc(info.block_size, 2);
281 bg->block_bitmap = bg->bitmaps;
282 bg->inode_bitmap = bg->bitmaps + info.block_size;
284 bg->header_blocks = header_blocks;
285 bg->first_block = aux_info.first_data_block + i * info.blocks_per_group;
287 u32 block = bg->first_block;
288 if (bg->has_superblock)
290 queue_data_block(bg->bitmaps, 2 * info.block_size, block);
292 bg->data_blocks_used = 0;
293 bg->free_blocks = info.blocks_per_group;
294 bg->first_free_block = 0;
295 bg->free_inodes = info.inodes_per_group;
296 bg->first_free_inode = 1;
298 if (reserve_blocks(bg, bg->first_free_block, bg->header_blocks) < 0)
299 error("failed to reserve %u blocks in block group %u\n", bg->header_blocks, i);
301 u32 overrun = bg->first_block + info.blocks_per_group - aux_info.len_blocks;
303 reserve_blocks(bg, info.blocks_per_group - overrun, overrun);
335 struct block_group_info *bg = &aux_info.bgs[bg_num];
336 if (reserve_blocks(bg, bg->first_free_block, len) < 0) {
343 return bg->first_block + block;
360 reg->bg = i;
411 reg->bg = i;
545 u32 get_free_blocks(u32 bg)
547 return aux_info.bgs[bg].free_blocks;
578 new->bg = reg->bg;
679 int bg = inode / info.inodes_per_group;
682 allocate_bg_inode_table(&aux_info.bgs[bg]);
683 return (struct ext4_inode *)(aux_info.bgs[bg].inode_table + inode *
688 u32 reserve_inodes(int bg, u32 num)
693 if (get_free_inodes(bg) < num)
697 bg].first_free_inode + i - 1;
698 aux_info.bgs[bg].inode_bitmap[inode / 8] |= 1 << (inode % 8);
701 inode = aux_info.bgs[bg].first_free_inode;
703 aux_info.bgs[bg].first_free_inode += num;
704 aux_info.bgs[bg].free_inodes -= num;
713 unsigned int bg;
716 for (bg = 0; bg < aux_info.groups; bg++) {
717 inode = reserve_inodes(bg, 1);
719 return bg * info.inodes_per_group + inode;
726 u32 get_free_inodes(u32 bg)
728 return aux_info.bgs[bg].free_inodes;
734 int bg = (inode - 1) / info.inodes_per_group;
735 aux_info.bgs[bg].used_dirs += 1;
739 u16 get_directories(int bg)
741 return aux_info.bgs[bg].used_dirs;