Mirror of git://git.busybox.net/busybox with our patches on top
Source
/* vi: set sw=4 ts=4: */
/*
* alloc_tables.c --- Allocate tables for a newly initialized
* filesystem. Used by mke2fs when initializing a filesystem
*
* Copyright (C) 1996 Theodore Ts'o.
*
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
* License.
* %End-Header%
*/
errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
ext2fs_block_bitmap bmap)
{
errcode_t retval;
blk_t group_blk, start_blk, last_blk, new_blk, blk;
int j;
group_blk = fs->super->s_first_data_block +
(group * fs->super->s_blocks_per_group);
last_blk = group_blk + fs->super->s_blocks_per_group;
if (last_blk >= fs->super->s_blocks_count)
last_blk = fs->super->s_blocks_count - 1;
if (!bmap)
bmap = fs->block_map;
/*
* Allocate the block and inode bitmaps, if necessary
*/
if (fs->stride) {
start_blk = group_blk + fs->inode_blocks_per_group;
start_blk += ((fs->stride * group) %
(last_blk - start_blk));
if (start_blk > last_blk)
start_blk = group_blk;
} else
start_blk = group_blk;
if (!fs->group_desc[group].bg_block_bitmap) {
retval = ext2fs_get_free_blocks(fs, start_blk, last_blk,
1, bmap, &new_blk);
if (retval == EXT2_ET_BLOCK_ALLOC_FAIL)