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