cmp_bitmaps.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * cmp_bitmaps.c --- routines to compare inode and block bitmaps.
  3. *
  4. * Copyright (C) 1995 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. #include <stdio.h>
  12. #include <string.h>
  13. #if HAVE_UNISTD_H
  14. #include <unistd.h>
  15. #endif
  16. #include <fcntl.h>
  17. #include <time.h>
  18. #if HAVE_SYS_STAT_H
  19. #include <sys/stat.h>
  20. #endif
  21. #if HAVE_SYS_TYPES_H
  22. #include <sys/types.h>
  23. #endif
  24. #include "ext2_fs.h"
  25. #include "ext2fs.h"
  26. errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
  27. ext2fs_block_bitmap bm2)
  28. {
  29. blk_t i;
  30. EXT2_CHECK_MAGIC(bm1, EXT2_ET_MAGIC_BLOCK_BITMAP);
  31. EXT2_CHECK_MAGIC(bm2, EXT2_ET_MAGIC_BLOCK_BITMAP);
  32. if ((bm1->start != bm2->start) ||
  33. (bm1->end != bm2->end) ||
  34. (memcmp(bm1->bitmap, bm2->bitmap,
  35. (size_t) (bm1->end - bm1->start)/8)))
  36. return EXT2_ET_NEQ_BLOCK_BITMAP;
  37. for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++)
  38. if (ext2fs_fast_test_block_bitmap(bm1, i) !=
  39. ext2fs_fast_test_block_bitmap(bm2, i))
  40. return EXT2_ET_NEQ_BLOCK_BITMAP;
  41. return 0;
  42. }
  43. errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
  44. ext2fs_inode_bitmap bm2)
  45. {
  46. ext2_ino_t i;
  47. EXT2_CHECK_MAGIC(bm1, EXT2_ET_MAGIC_INODE_BITMAP);
  48. EXT2_CHECK_MAGIC(bm2, EXT2_ET_MAGIC_INODE_BITMAP);
  49. if ((bm1->start != bm2->start) ||
  50. (bm1->end != bm2->end) ||
  51. (memcmp(bm1->bitmap, bm2->bitmap,
  52. (size_t) (bm1->end - bm1->start)/8)))
  53. return EXT2_ET_NEQ_INODE_BITMAP;
  54. for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++)
  55. if (ext2fs_fast_test_inode_bitmap(bm1, i) !=
  56. ext2fs_fast_test_inode_bitmap(bm2, i))
  57. return EXT2_ET_NEQ_INODE_BITMAP;
  58. return 0;
  59. }