2 * alloc_tables.c --- Allocate tables for a newly initialized
3 * filesystem. Used by mke2fs when initializing a filesystem
5 * Copyright (C) 1996 Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Public
24 #include <sys/types.h>
30 errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
31 ext2fs_block_bitmap bmap)
34 blk_t group_blk, start_blk, last_blk, new_blk, blk;
37 group_blk = ext2fs_group_first_block(fs, group);
38 last_blk = ext2fs_group_last_block(fs, group);
44 * Allocate the block and inode bitmaps, if necessary
47 retval = ext2fs_get_free_blocks(fs, group_blk, last_blk,
51 start_blk += fs->inode_blocks_per_group;
52 start_blk += ((fs->stride * group) %
53 (last_blk - start_blk + 1));
54 if (start_blk >= last_blk)
55 start_blk = group_blk;
57 start_blk = group_blk;
59 if (!fs->group_desc[group].bg_block_bitmap) {
60 retval = ext2fs_get_free_blocks(fs, start_blk, last_blk,
62 if (retval == EXT2_ET_BLOCK_ALLOC_FAIL)
63 retval = ext2fs_get_free_blocks(fs, group_blk,
64 last_blk, 1, bmap, &new_blk);
67 ext2fs_mark_block_bitmap(bmap, new_blk);
68 fs->group_desc[group].bg_block_bitmap = new_blk;
71 if (!fs->group_desc[group].bg_inode_bitmap) {
72 retval = ext2fs_get_free_blocks(fs, start_blk, last_blk,
74 if (retval == EXT2_ET_BLOCK_ALLOC_FAIL)
75 retval = ext2fs_get_free_blocks(fs, group_blk,
76 last_blk, 1, bmap, &new_blk);
79 ext2fs_mark_block_bitmap(bmap, new_blk);
80 fs->group_desc[group].bg_inode_bitmap = new_blk;
84 * Allocate the inode table
86 if (!fs->group_desc[group].bg_inode_table) {
87 retval = ext2fs_get_free_blocks(fs, group_blk, last_blk,
88 fs->inode_blocks_per_group,
92 for (j=0, blk = new_blk;
93 j < fs->inode_blocks_per_group;
95 ext2fs_mark_block_bitmap(bmap, blk);
96 fs->group_desc[group].bg_inode_table = new_blk;
105 errcode_t ext2fs_allocate_tables(ext2_filsys fs)
110 for (i = 0; i < fs->group_desc_count; i++) {
111 retval = ext2fs_allocate_group_table(fs, i, fs->block_map);