• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
ext2fs_reserve_super_and_bgd(ext2_filsys fs,dgrp_t group,ext2fs_block_bitmap bmap)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 =
44 			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 }
58