3
0

alloc_stats.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * alloc_stats.c --- Update allocation statistics for ext2fs
  4. *
  5. * Copyright (C) 2001 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 "ext2_fs.h"
  15. #include "ext2fs.h"
  16. void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
  17. int inuse, int isdir)
  18. {
  19. int group = ext2fs_group_of_ino(fs, ino);
  20. if (inuse > 0)
  21. ext2fs_mark_inode_bitmap(fs->inode_map, ino);
  22. else
  23. ext2fs_unmark_inode_bitmap(fs->inode_map, ino);
  24. fs->group_desc[group].bg_free_inodes_count -= inuse;
  25. if (isdir)
  26. fs->group_desc[group].bg_used_dirs_count += inuse;
  27. fs->super->s_free_inodes_count -= inuse;
  28. ext2fs_mark_super_dirty(fs);
  29. ext2fs_mark_ib_dirty(fs);
  30. }
  31. void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse)
  32. {
  33. ext2fs_inode_alloc_stats2(fs, ino, inuse, 0);
  34. }
  35. void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse)
  36. {
  37. int group = ext2fs_group_of_blk(fs, blk);
  38. if (inuse > 0)
  39. ext2fs_mark_block_bitmap(fs->block_map, blk);
  40. else
  41. ext2fs_unmark_block_bitmap(fs->block_map, blk);
  42. fs->group_desc[group].bg_free_blocks_count -= inuse;
  43. fs->super->s_free_blocks_count -= inuse;
  44. ext2fs_mark_super_dirty(fs);
  45. ext2fs_mark_bb_dirty(fs);
  46. }