.. | .. |
---|
36 | 36 | unsigned long bitmap_nr) |
---|
37 | 37 | { |
---|
38 | 38 | struct buffer_head *bh = NULL; |
---|
39 | | - int retval = 0; |
---|
| 39 | + int i; |
---|
| 40 | + int max_bits, off, count; |
---|
40 | 41 | struct kernel_lb_addr loc; |
---|
41 | 42 | |
---|
42 | 43 | loc.logicalBlockNum = bitmap->s_extPosition; |
---|
43 | 44 | loc.partitionReferenceNum = UDF_SB(sb)->s_partition; |
---|
44 | 45 | |
---|
45 | 46 | bh = udf_tread(sb, udf_get_lb_pblock(sb, &loc, block)); |
---|
46 | | - if (!bh) |
---|
47 | | - retval = -EIO; |
---|
48 | | - |
---|
49 | 47 | bitmap->s_block_bitmap[bitmap_nr] = bh; |
---|
50 | | - return retval; |
---|
| 48 | + if (!bh) |
---|
| 49 | + return -EIO; |
---|
| 50 | + |
---|
| 51 | + /* Check consistency of Space Bitmap buffer. */ |
---|
| 52 | + max_bits = sb->s_blocksize * 8; |
---|
| 53 | + if (!bitmap_nr) { |
---|
| 54 | + off = sizeof(struct spaceBitmapDesc) << 3; |
---|
| 55 | + count = min(max_bits - off, bitmap->s_nr_groups); |
---|
| 56 | + } else { |
---|
| 57 | + /* |
---|
| 58 | + * Rough check if bitmap number is too big to have any bitmap |
---|
| 59 | + * blocks reserved. |
---|
| 60 | + */ |
---|
| 61 | + if (bitmap_nr > |
---|
| 62 | + (bitmap->s_nr_groups >> (sb->s_blocksize_bits + 3)) + 2) |
---|
| 63 | + return 0; |
---|
| 64 | + off = 0; |
---|
| 65 | + count = bitmap->s_nr_groups - bitmap_nr * max_bits + |
---|
| 66 | + (sizeof(struct spaceBitmapDesc) << 3); |
---|
| 67 | + count = min(count, max_bits); |
---|
| 68 | + } |
---|
| 69 | + |
---|
| 70 | + for (i = 0; i < count; i++) |
---|
| 71 | + if (udf_test_bit(i + off, bh->b_data)) |
---|
| 72 | + return -EFSCORRUPTED; |
---|
| 73 | + return 0; |
---|
51 | 74 | } |
---|
52 | 75 | |
---|
53 | 76 | static int __load_block_bitmap(struct super_block *sb, |
---|