blob: aa2cd0568b04dc9762cbef6f313dde10ad29cd02 [file] [log] [blame]
Mike Frysinger1fd98e02005-05-09 22:10:42 +00001/*
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00002 * alloc_sb.c --- Allocate the superblock and block group descriptors for a
Mike Frysinger1fd98e02005-05-09 22:10:42 +00003 * newly initialized filesystem. Used by mke2fs when initializing a filesystem
4 *
5 * Copyright (C) 1994, 1995, 1996, 2003 Theodore Ts'o.
6 *
7 * %Begin-Header%
8 * This file may be redistributed under the terms of the GNU Public
9 * License.
10 * %End-Header%
11 */
12
13#include <stdio.h>
14#include <string.h>
15#if HAVE_UNISTD_H
16#include <unistd.h>
17#endif
18#include <fcntl.h>
19#include <time.h>
20#if HAVE_SYS_STAT_H
21#include <sys/stat.h>
22#endif
23#if HAVE_SYS_TYPES_H
24#include <sys/types.h>
25#endif
26
27#include "ext2_fs.h"
28#include "ext2fs.h"
29
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000030int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
Mike Frysinger1fd98e02005-05-09 22:10:42 +000031 dgrp_t group,
32 ext2fs_block_bitmap bmap)
33{
34 blk_t super_blk, old_desc_blk, new_desc_blk;
35 int j, old_desc_blocks, num_blocks;
36
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000037 num_blocks = ext2fs_super_and_bgd_loc(fs, group, &super_blk,
Mike Frysinger1fd98e02005-05-09 22:10:42 +000038 &old_desc_blk, &new_desc_blk, 0);
39
40 if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
41 old_desc_blocks = fs->super->s_first_meta_bg;
42 else
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000043 old_desc_blocks =
Mike Frysinger1fd98e02005-05-09 22:10:42 +000044 fs->desc_blocks + fs->super->s_reserved_gdt_blocks;
45
46 if (super_blk || (group == 0))
47 ext2fs_mark_block_bitmap(bmap, super_blk);
48
49 if (old_desc_blk) {
50 for (j=0; j < old_desc_blocks; j++)
51 ext2fs_mark_block_bitmap(bmap, old_desc_blk + j);
52 }
53 if (new_desc_blk)
54 ext2fs_mark_block_bitmap(bmap, new_desc_blk);
55
56 return num_blocks;
57}