diff options
Diffstat (limited to 'fs/udf/balloc.c')
-rw-r--r-- | fs/udf/balloc.c | 98 |
1 files changed, 27 insertions, 71 deletions
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c index 1e068535b58b..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); |
@@ -208,7 +160,7 @@ static void udf_bitmap_free_blocks(struct super_block *sb, | |||
208 | ((char *)bh->b_data)[(bit + i) >> 3]); | 160 | ((char *)bh->b_data)[(bit + i) >> 3]); |
209 | } else { | 161 | } else { |
210 | if (inode) | 162 | if (inode) |
211 | vfs_dq_free_block(inode, 1); | 163 | dquot_free_block(inode, 1); |
212 | udf_add_free_space(sb, sbi->s_partition, 1); | 164 | udf_add_free_space(sb, sbi->s_partition, 1); |
213 | } | 165 | } |
214 | } | 166 | } |
@@ -260,11 +212,11 @@ static int udf_bitmap_prealloc_blocks(struct super_block *sb, | |||
260 | while (bit < (sb->s_blocksize << 3) && block_count > 0) { | 212 | while (bit < (sb->s_blocksize << 3) && block_count > 0) { |
261 | if (!udf_test_bit(bit, bh->b_data)) | 213 | if (!udf_test_bit(bit, bh->b_data)) |
262 | goto out; | 214 | goto out; |
263 | else if (vfs_dq_prealloc_block(inode, 1)) | 215 | else if (dquot_prealloc_block(inode, 1)) |
264 | goto out; | 216 | goto out; |
265 | else if (!udf_clear_bit(bit, bh->b_data)) { | 217 | else if (!udf_clear_bit(bit, bh->b_data)) { |
266 | udf_debug("bit already cleared for block %d\n", bit); | 218 | udf_debug("bit already cleared for block %d\n", bit); |
267 | vfs_dq_free_block(inode, 1); | 219 | dquot_free_block(inode, 1); |
268 | goto out; | 220 | goto out; |
269 | } | 221 | } |
270 | block_count--; | 222 | block_count--; |
@@ -390,10 +342,14 @@ got_block: | |||
390 | /* | 342 | /* |
391 | * Check quota for allocation of this block. | 343 | * Check quota for allocation of this block. |
392 | */ | 344 | */ |
393 | if (inode && vfs_dq_alloc_block(inode, 1)) { | 345 | if (inode) { |
394 | mutex_unlock(&sbi->s_alloc_mutex); | 346 | int ret = dquot_alloc_block(inode, 1); |
395 | *err = -EDQUOT; | 347 | |
396 | return 0; | 348 | if (ret) { |
349 | mutex_unlock(&sbi->s_alloc_mutex); | ||
350 | *err = ret; | ||
351 | return 0; | ||
352 | } | ||
397 | } | 353 | } |
398 | 354 | ||
399 | newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) - | 355 | newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) - |
@@ -436,11 +392,10 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
436 | 392 | ||
437 | mutex_lock(&sbi->s_alloc_mutex); | 393 | mutex_lock(&sbi->s_alloc_mutex); |
438 | partmap = &sbi->s_partmaps[bloc->partitionReferenceNum]; | 394 | partmap = &sbi->s_partmaps[bloc->partitionReferenceNum]; |
439 | if (bloc->logicalBlockNum < 0 || | 395 | if (bloc->logicalBlockNum + count < count || |
440 | (bloc->logicalBlockNum + count) > | 396 | (bloc->logicalBlockNum + count) > partmap->s_partition_len) { |
441 | partmap->s_partition_len) { | ||
442 | udf_debug("%d < %d || %d + %d > %d\n", | 397 | udf_debug("%d < %d || %d + %d > %d\n", |
443 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, | 398 | bloc->logicalBlockNum, 0, bloc->logicalBlockNum, count, |
444 | partmap->s_partition_len); | 399 | partmap->s_partition_len); |
445 | goto error_return; | 400 | goto error_return; |
446 | } | 401 | } |
@@ -449,7 +404,7 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
449 | /* We do this up front - There are some error conditions that | 404 | /* We do this up front - There are some error conditions that |
450 | could occure, but.. oh well */ | 405 | could occure, but.. oh well */ |
451 | if (inode) | 406 | if (inode) |
452 | vfs_dq_free_block(inode, count); | 407 | dquot_free_block(inode, count); |
453 | udf_add_free_space(sb, sbi->s_partition, count); | 408 | udf_add_free_space(sb, sbi->s_partition, count); |
454 | 409 | ||
455 | start = bloc->logicalBlockNum + offset; | 410 | start = bloc->logicalBlockNum + offset; |
@@ -547,7 +502,7 @@ static void udf_table_free_blocks(struct super_block *sb, | |||
547 | } | 502 | } |
548 | 503 | ||
549 | if (epos.offset + (2 * adsize) > sb->s_blocksize) { | 504 | if (epos.offset + (2 * adsize) > sb->s_blocksize) { |
550 | char *sptr, *dptr; | 505 | unsigned char *sptr, *dptr; |
551 | int loffset; | 506 | int loffset; |
552 | 507 | ||
553 | brelse(oepos.bh); | 508 | brelse(oepos.bh); |
@@ -694,7 +649,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb, | |||
694 | epos.offset -= adsize; | 649 | epos.offset -= adsize; |
695 | 650 | ||
696 | alloc_count = (elen >> sb->s_blocksize_bits); | 651 | alloc_count = (elen >> sb->s_blocksize_bits); |
697 | if (inode && vfs_dq_prealloc_block(inode, | 652 | if (inode && dquot_prealloc_block(inode, |
698 | alloc_count > block_count ? block_count : alloc_count)) | 653 | alloc_count > block_count ? block_count : alloc_count)) |
699 | alloc_count = 0; | 654 | alloc_count = 0; |
700 | else if (alloc_count > block_count) { | 655 | else if (alloc_count > block_count) { |
@@ -797,12 +752,13 @@ static int udf_table_new_block(struct super_block *sb, | |||
797 | newblock = goal_eloc.logicalBlockNum; | 752 | newblock = goal_eloc.logicalBlockNum; |
798 | goal_eloc.logicalBlockNum++; | 753 | goal_eloc.logicalBlockNum++; |
799 | goal_elen -= sb->s_blocksize; | 754 | goal_elen -= sb->s_blocksize; |
800 | 755 | if (inode) { | |
801 | if (inode && vfs_dq_alloc_block(inode, 1)) { | 756 | *err = dquot_alloc_block(inode, 1); |
802 | brelse(goal_epos.bh); | 757 | if (*err) { |
803 | mutex_unlock(&sbi->s_alloc_mutex); | 758 | brelse(goal_epos.bh); |
804 | *err = -EDQUOT; | 759 | mutex_unlock(&sbi->s_alloc_mutex); |
805 | return 0; | 760 | return 0; |
761 | } | ||
806 | } | 762 | } |
807 | 763 | ||
808 | if (goal_elen) | 764 | if (goal_elen) |