Whamcloud - gitweb
libext2fs: add pseudo bitmap backend type EXT2FS_BMAP64_AUTODIR
[tools/e2fsprogs.git] / lib / ext2fs / alloc_sb.c
index d9080b6..0d1c000 100644 (file)
@@ -5,11 +5,12 @@
  * Copyright (C) 1994, 1995, 1996, 2003 Theodore Ts'o.
  *
  * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
  * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #if HAVE_UNISTD_H
@@ -59,27 +60,22 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
 
        if (super_blk || (group == 0))
                ext2fs_mark_block_bitmap2(bmap, super_blk);
+       if ((group == 0) && (fs->blocksize == 1024) &&
+           EXT2FS_CLUSTER_RATIO(fs) > 1)
+               ext2fs_mark_block_bitmap2(bmap, 0);
 
        if (old_desc_blk) {
                if (fs->super->s_reserved_gdt_blocks && fs->block_map == bmap)
-                       fs->group_desc[group].bg_flags &= ~EXT2_BG_BLOCK_UNINIT;
+                       ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
                for (j=0; j < old_desc_blocks; j++)
-                       if (old_desc_blk + j < fs->super->s_blocks_count)
+                       if (old_desc_blk + j < ext2fs_blocks_count(fs->super))
                                ext2fs_mark_block_bitmap2(bmap,
                                                         old_desc_blk + j);
        }
        if (new_desc_blk)
                ext2fs_mark_block_bitmap2(bmap, new_desc_blk);
 
-       if (group == fs->group_desc_count-1) {
-               num_blocks = (fs->super->s_blocks_count -
-                            fs->super->s_first_data_block) %
-                       fs->super->s_blocks_per_group;
-               if (!num_blocks)
-                       num_blocks = fs->super->s_blocks_per_group;
-       } else
-               num_blocks = fs->super->s_blocks_per_group;
-
+       num_blocks = ext2fs_group_blocks_count(fs, group);
        num_blocks -= 2 + fs->inode_blocks_per_group + used_blks;
 
        return num_blocks  ;