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 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 27#include "ext2_fs.h" 28#include "ext2fs.h" 29 30errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1, 31 ext2fs_block_bitmap bm2) 32{ 33 blk_t i; 34 35 EXT2_CHECK_MAGIC(bm1, EXT2_ET_MAGIC_BLOCK_BITMAP); 36 EXT2_CHECK_MAGIC(bm2, EXT2_ET_MAGIC_BLOCK_BITMAP); 37 38 if ((bm1->start != bm2->start) || 39 (bm1->end != bm2->end) || 40 (memcmp(bm1->bitmap, bm2->bitmap, 41 (size_t) (bm1->end - bm1->start)/8))) 42 return EXT2_ET_NEQ_BLOCK_BITMAP; 43 44 for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++) 45 if (ext2fs_fast_test_block_bitmap(bm1, i) != 46 ext2fs_fast_test_block_bitmap(bm2, i)) 47 return EXT2_ET_NEQ_BLOCK_BITMAP; 48 49 return 0; 50} 51 52errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, 53 ext2fs_inode_bitmap bm2) 54{ 55 ext2_ino_t i; 56 57 EXT2_CHECK_MAGIC(bm1, EXT2_ET_MAGIC_INODE_BITMAP); 58 EXT2_CHECK_MAGIC(bm2, EXT2_ET_MAGIC_INODE_BITMAP); 59 60 if ((bm1->start != bm2->start) || 61 (bm1->end != bm2->end) || 62 (memcmp(bm1->bitmap, bm2->bitmap, 63 (size_t) (bm1->end - bm1->start)/8))) 64 return EXT2_ET_NEQ_INODE_BITMAP; 65 66 for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++) 67 if (ext2fs_fast_test_inode_bitmap(bm1, i) != 68 ext2fs_fast_test_inode_bitmap(bm2, i)) 69 return EXT2_ET_NEQ_INODE_BITMAP; 70 71 return 0; 72} 73