"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 2 | /* |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 3 | * alloc_sb.c --- Allocate the superblock and block group descriptors for a |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 4 | * newly initialized filesystem. Used by mke2fs when initializing a filesystem |
| 5 | * |
| 6 | * Copyright (C) 1994, 1995, 1996, 2003 Theodore Ts'o. |
| 7 | * |
| 8 | * %Begin-Header% |
| 9 | * This file may be redistributed under the terms of the GNU Public |
| 10 | * License. |
| 11 | * %End-Header% |
| 12 | */ |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | #include <string.h> |
| 16 | #if HAVE_UNISTD_H |
| 17 | #include <unistd.h> |
| 18 | #endif |
| 19 | #include <fcntl.h> |
| 20 | #include <time.h> |
| 21 | #if HAVE_SYS_STAT_H |
| 22 | #include <sys/stat.h> |
| 23 | #endif |
| 24 | #if HAVE_SYS_TYPES_H |
| 25 | #include <sys/types.h> |
| 26 | #endif |
| 27 | |
| 28 | #include "ext2_fs.h" |
| 29 | #include "ext2fs.h" |
| 30 | |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 31 | int ext2fs_reserve_super_and_bgd(ext2_filsys fs, |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 32 | dgrp_t group, |
| 33 | ext2fs_block_bitmap bmap) |
| 34 | { |
| 35 | blk_t super_blk, old_desc_blk, new_desc_blk; |
| 36 | int j, old_desc_blocks, num_blocks; |
| 37 | |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 38 | num_blocks = ext2fs_super_and_bgd_loc(fs, group, &super_blk, |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 39 | &old_desc_blk, &new_desc_blk, 0); |
| 40 | |
| 41 | if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) |
| 42 | old_desc_blocks = fs->super->s_first_meta_bg; |
| 43 | else |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 44 | old_desc_blocks = |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 45 | fs->desc_blocks + fs->super->s_reserved_gdt_blocks; |
| 46 | |
| 47 | if (super_blk || (group == 0)) |
| 48 | ext2fs_mark_block_bitmap(bmap, super_blk); |
| 49 | |
| 50 | if (old_desc_blk) { |
| 51 | for (j=0; j < old_desc_blocks; j++) |
| 52 | ext2fs_mark_block_bitmap(bmap, old_desc_blk + j); |
| 53 | } |
| 54 | if (new_desc_blk) |
| 55 | ext2fs_mark_block_bitmap(bmap, new_desc_blk); |
| 56 | |
| 57 | return num_blocks; |
| 58 | } |