alloc_sb.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * alloc_sb.c --- Allocate the superblock and block group descriptors for a
  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. #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. #include "ext2_fs.h"
  27. #include "ext2fs.h"
  28. int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
  29. dgrp_t group,
  30. ext2fs_block_bitmap bmap)
  31. {
  32. blk_t super_blk, old_desc_blk, new_desc_blk;
  33. int j, old_desc_blocks, num_blocks;
  34. num_blocks = ext2fs_super_and_bgd_loc(fs, group, &super_blk,
  35. &old_desc_blk, &new_desc_blk, 0);
  36. if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
  37. old_desc_blocks = fs->super->s_first_meta_bg;
  38. else
  39. old_desc_blocks =
  40. fs->desc_blocks + fs->super->s_reserved_gdt_blocks;
  41. if (super_blk || (group == 0))
  42. ext2fs_mark_block_bitmap(bmap, super_blk);
  43. if (old_desc_blk) {
  44. for (j=0; j < old_desc_blocks; j++)
  45. ext2fs_mark_block_bitmap(bmap, old_desc_blk + j);
  46. }
  47. if (new_desc_blk)
  48. ext2fs_mark_block_bitmap(bmap, new_desc_blk);
  49. return num_blocks;
  50. }