cmp_bitmaps.c 1.7 KB

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