diff options
Diffstat (limited to 'fs/udf/balloc.c')
-rw-r--r-- | fs/udf/balloc.c | 59 |
1 files changed, 5 insertions, 54 deletions
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c index ccc3ad7242d4..9a9378b4eb5a 100644 --- a/fs/udf/balloc.c +++ b/fs/udf/balloc.c | |||
@@ -31,55 +31,8 @@ | |||
31 | #define udf_clear_bit(nr, addr) ext2_clear_bit(nr, addr) | 31 | #define udf_clear_bit(nr, addr) ext2_clear_bit(nr, addr) |
32 | #define udf_set_bit(nr, addr) ext2_set_bit(nr, addr) | 32 | #define udf_set_bit(nr, addr) ext2_set_bit(nr, addr) |
33 | #define udf_test_bit(nr, addr) ext2_test_bit(nr, addr) | 33 | #define udf_test_bit(nr, addr) ext2_test_bit(nr, addr) |
34 | #define udf_find_first_one_bit(addr, size) find_first_one_bit(addr, size) | ||
35 | #define udf_find_next_one_bit(addr, size, offset) \ | 34 | #define udf_find_next_one_bit(addr, size, offset) \ |
36 | find_next_one_bit(addr, size, offset) | 35 | ext2_find_next_bit(addr, size, offset) |
37 | |||
38 | #define leBPL_to_cpup(x) leNUM_to_cpup(BITS_PER_LONG, x) | ||
39 | #define leNUM_to_cpup(x, y) xleNUM_to_cpup(x, y) | ||
40 | #define xleNUM_to_cpup(x, y) (le ## x ## _to_cpup(y)) | ||
41 | #define uintBPL_t uint(BITS_PER_LONG) | ||
42 | #define uint(x) xuint(x) | ||
43 | #define xuint(x) __le ## x | ||
44 | |||
45 | static inline int find_next_one_bit(void *addr, int size, int offset) | ||
46 | { | ||
47 | uintBPL_t *p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG); | ||
48 | int result = offset & ~(BITS_PER_LONG - 1); | ||
49 | unsigned long tmp; | ||
50 | |||
51 | if (offset >= size) | ||
52 | return size; | ||
53 | size -= result; | ||
54 | offset &= (BITS_PER_LONG - 1); | ||
55 | if (offset) { | ||
56 | tmp = leBPL_to_cpup(p++); | ||
57 | tmp &= ~0UL << offset; | ||
58 | if (size < BITS_PER_LONG) | ||
59 | goto found_first; | ||
60 | if (tmp) | ||
61 | goto found_middle; | ||
62 | size -= BITS_PER_LONG; | ||
63 | result += BITS_PER_LONG; | ||
64 | } | ||
65 | while (size & ~(BITS_PER_LONG - 1)) { | ||
66 | tmp = leBPL_to_cpup(p++); | ||
67 | if (tmp) | ||
68 | goto found_middle; | ||
69 | result += BITS_PER_LONG; | ||
70 | size -= BITS_PER_LONG; | ||
71 | } | ||
72 | if (!size) | ||
73 | return result; | ||
74 | tmp = leBPL_to_cpup(p); | ||
75 | found_first: | ||
76 | tmp &= ~0UL >> (BITS_PER_LONG - size); | ||
77 | found_middle: | ||
78 | return result + ffz(~tmp); | ||
79 | } | ||
80 | |||
81 | #define find_first_one_bit(addr, size)\ | ||
82 | find_next_one_bit((addr), (size), 0) | ||
83 | 36 | ||
84 | static int read_block_bitmap(struct super_block *sb, | 37 | static int read_block_bitmap(struct super_block *sb, |
85 | struct udf_bitmap *bitmap, unsigned int block, | 38 | struct udf_bitmap *bitmap, unsigned int block, |
@@ -172,9 +125,8 @@ static void udf_bitmap_free_blocks(struct super_block *sb, | |||
172 | 125 | ||
173 | mutex_lock(&sbi->s_alloc_mutex); | 126 | mutex_lock(&sbi->s_alloc_mutex); |
174 | partmap = &sbi->s_partmaps[bloc->partitionReferenceNum]; | 127 | partmap = &sbi->s_partmaps[bloc->partitionReferenceNum]; |
175 | if (bloc->logicalBlockNum < 0 || | 128 | if (bloc->logicalBlockNum + count < count || |
176 | (bloc->logicalBlockNum + count) > | 129 | (bloc->logicalBlockNum + count) > partmap->s_partition_len) { |
177 | partmap->s_partition_len) { | ||
178 | udf_debug("%d < %d || %d + %d > %d\n", | 130 | udf_debug("%d < %d || %d + %d > %d\n", |
179 | bloc->logicalBlockNum, 0, bloc->logicalBlockNum, | 131 | bloc->logicalBlockNum, 0, bloc->logicalBlockNum, |
180 | count, partmap->s_partition_len); | 132 | count, partmap->s_partition_len); |
@@ -440,9 +392,8 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
440 | 392 | ||
441 | mutex_lock(&sbi->s_alloc_mutex); | 393 | mutex_lock(&sbi->s_alloc_mutex); |
442 | partmap = &sbi->s_partmaps[bloc->partitionReferenceNum]; | 394 | partmap = &sbi->s_partmaps[bloc->partitionReferenceNum]; |
443 | if (bloc->logicalBlockNum < 0 || | 395 | if (bloc->logicalBlockNum + count < count || |
444 | (bloc->logicalBlockNum + count) > | 396 | (bloc->logicalBlockNum + count) > partmap->s_partition_len) { |
445 | partmap->s_partition_len) { | ||
446 | udf_debug("%d < %d || %d + %d > %d\n", | 397 | udf_debug("%d < %d || %d + %d > %d\n", |
447 | bloc->logicalBlockNum, 0, bloc->logicalBlockNum, count, | 398 | bloc->logicalBlockNum, 0, bloc->logicalBlockNum, count, |
448 | partmap->s_partition_len); | 399 | partmap->s_partition_len); |