Whamcloud - gitweb
e4733c99b1d2f225947529afab02a47d63f98b16
[tools/e2fsprogs.git] / lib / ext2fs / alloc_sb.c
1 /*
2  * alloc_sb.c --- Allocate the superblock and block group descriptors for a 
3  * 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
30 int ext2fs_reserve_super_and_bgd(ext2_filsys fs, 
31                                  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
37         num_blocks = ext2fs_super_and_bgd_loc(fs, group, &super_blk, 
38                                               &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
43                 old_desc_blocks = fs->desc_blocks;
44
45         if (super_blk || (group == 0))
46                 ext2fs_mark_block_bitmap(bmap, super_blk);
47
48         if (old_desc_blk) {
49                 for (j=0; j < old_desc_blocks; j++)
50                         ext2fs_mark_block_bitmap(bmap, old_desc_blk + j);
51         }
52         if (new_desc_blk)
53                 ext2fs_mark_block_bitmap(bmap, new_desc_blk);
54
55         return num_blocks;
56 }