aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/balloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/udf/balloc.c')
-rw-r--r--fs/udf/balloc.c86
1 files changed, 22 insertions, 64 deletions
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
index 82372e332f08..19626e2491c4 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
45static 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);
75found_first:
76 tmp &= ~0UL >> (BITS_PER_LONG - size);
77found_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
84static int read_block_bitmap(struct super_block *sb, 37static int read_block_bitmap(struct super_block *sb,
85 struct udf_bitmap *bitmap, unsigned int block, 38 struct udf_bitmap *bitmap, unsigned int block,
@@ -208,7 +161,7 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
208 ((char *)bh->b_data)[(bit + i) >> 3]); 161 ((char *)bh->b_data)[(bit + i) >> 3]);
209 } else { 162 } else {
210 if (inode) 163 if (inode)
211 vfs_dq_free_block(inode, 1); 164 dquot_free_block(inode, 1);
212 udf_add_free_space(sb, sbi->s_partition, 1); 165 udf_add_free_space(sb, sbi->s_partition, 1);
213 } 166 }
214 } 167 }
@@ -260,11 +213,11 @@ static int udf_bitmap_prealloc_blocks(struct super_block *sb,
260 while (bit < (sb->s_blocksize << 3) && block_count > 0) { 213 while (bit < (sb->s_blocksize << 3) && block_count > 0) {
261 if (!udf_test_bit(bit, bh->b_data)) 214 if (!udf_test_bit(bit, bh->b_data))
262 goto out; 215 goto out;
263 else if (vfs_dq_prealloc_block(inode, 1)) 216 else if (dquot_prealloc_block(inode, 1))
264 goto out; 217 goto out;
265 else if (!udf_clear_bit(bit, bh->b_data)) { 218 else if (!udf_clear_bit(bit, bh->b_data)) {
266 udf_debug("bit already cleared for block %d\n", bit); 219 udf_debug("bit already cleared for block %d\n", bit);
267 vfs_dq_free_block(inode, 1); 220 dquot_free_block(inode, 1);
268 goto out; 221 goto out;
269 } 222 }
270 block_count--; 223 block_count--;
@@ -390,10 +343,14 @@ got_block:
390 /* 343 /*
391 * Check quota for allocation of this block. 344 * Check quota for allocation of this block.
392 */ 345 */
393 if (inode && vfs_dq_alloc_block(inode, 1)) { 346 if (inode) {
394 mutex_unlock(&sbi->s_alloc_mutex); 347 int ret = dquot_alloc_block(inode, 1);
395 *err = -EDQUOT; 348
396 return 0; 349 if (ret) {
350 mutex_unlock(&sbi->s_alloc_mutex);
351 *err = ret;
352 return 0;
353 }
397 } 354 }
398 355
399 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) - 356 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
@@ -449,7 +406,7 @@ static void udf_table_free_blocks(struct super_block *sb,
449 /* We do this up front - There are some error conditions that 406 /* We do this up front - There are some error conditions that
450 could occure, but.. oh well */ 407 could occure, but.. oh well */
451 if (inode) 408 if (inode)
452 vfs_dq_free_block(inode, count); 409 dquot_free_block(inode, count);
453 udf_add_free_space(sb, sbi->s_partition, count); 410 udf_add_free_space(sb, sbi->s_partition, count);
454 411
455 start = bloc->logicalBlockNum + offset; 412 start = bloc->logicalBlockNum + offset;
@@ -547,7 +504,7 @@ static void udf_table_free_blocks(struct super_block *sb,
547 } 504 }
548 505
549 if (epos.offset + (2 * adsize) > sb->s_blocksize) { 506 if (epos.offset + (2 * adsize) > sb->s_blocksize) {
550 char *sptr, *dptr; 507 unsigned char *sptr, *dptr;
551 int loffset; 508 int loffset;
552 509
553 brelse(oepos.bh); 510 brelse(oepos.bh);
@@ -694,7 +651,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
694 epos.offset -= adsize; 651 epos.offset -= adsize;
695 652
696 alloc_count = (elen >> sb->s_blocksize_bits); 653 alloc_count = (elen >> sb->s_blocksize_bits);
697 if (inode && vfs_dq_prealloc_block(inode, 654 if (inode && dquot_prealloc_block(inode,
698 alloc_count > block_count ? block_count : alloc_count)) 655 alloc_count > block_count ? block_count : alloc_count))
699 alloc_count = 0; 656 alloc_count = 0;
700 else if (alloc_count > block_count) { 657 else if (alloc_count > block_count) {
@@ -797,12 +754,13 @@ static int udf_table_new_block(struct super_block *sb,
797 newblock = goal_eloc.logicalBlockNum; 754 newblock = goal_eloc.logicalBlockNum;
798 goal_eloc.logicalBlockNum++; 755 goal_eloc.logicalBlockNum++;
799 goal_elen -= sb->s_blocksize; 756 goal_elen -= sb->s_blocksize;
800 757 if (inode) {
801 if (inode && vfs_dq_alloc_block(inode, 1)) { 758 *err = dquot_alloc_block(inode, 1);
802 brelse(goal_epos.bh); 759 if (*err) {
803 mutex_unlock(&sbi->s_alloc_mutex); 760 brelse(goal_epos.bh);
804 *err = -EDQUOT; 761 mutex_unlock(&sbi->s_alloc_mutex);
805 return 0; 762 return 0;
763 }
806 } 764 }
807 765
808 if (goal_elen) 766 if (goal_elen)