3
0

alloc_stats.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * alloc_stats.c --- Update allocation statistics for ext2fs
  3. *
  4. * Copyright (C) 2001 Theodore Ts'o.
  5. *
  6. * %Begin-Header%
  7. * This file may be redistributed under the terms of the GNU Public
  8. * License.
  9. * %End-Header%
  10. *
  11. */
  12. #include <stdio.h>
  13. #include "ext2_fs.h"
  14. #include "ext2fs.h"
  15. void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
  16. int inuse, int isdir)
  17. {
  18. int group = ext2fs_group_of_ino(fs, ino);
  19. if (inuse > 0)
  20. ext2fs_mark_inode_bitmap(fs->inode_map, ino);
  21. else
  22. ext2fs_unmark_inode_bitmap(fs->inode_map, ino);
  23. fs->group_desc[group].bg_free_inodes_count -= inuse;
  24. if (isdir)
  25. fs->group_desc[group].bg_used_dirs_count += inuse;
  26. fs->super->s_free_inodes_count -= inuse;
  27. ext2fs_mark_super_dirty(fs);
  28. ext2fs_mark_ib_dirty(fs);
  29. }
  30. void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse)
  31. {
  32. ext2fs_inode_alloc_stats2(fs, ino, inuse, 0);
  33. }
  34. void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse)
  35. {
  36. int group = ext2fs_group_of_blk(fs, blk);
  37. if (inuse > 0)
  38. ext2fs_mark_block_bitmap(fs->block_map, blk);
  39. else
  40. ext2fs_unmark_block_bitmap(fs->block_map, blk);
  41. fs->group_desc[group].bg_free_blocks_count -= inuse;
  42. fs->super->s_free_blocks_count -= inuse;
  43. ext2fs_mark_super_dirty(fs);
  44. ext2fs_mark_bb_dirty(fs);
  45. }