"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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 | |
| 30 | errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1, |
| 31 | ext2fs_block_bitmap bm2) |
| 32 | { |
| 33 | blk_t i; |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 34 | |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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 | |
| 52 | errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, |
| 53 | ext2fs_inode_bitmap bm2) |
| 54 | { |
| 55 | ext2_ino_t i; |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 56 | |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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 | |