Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[sfrench/cifs-2.6.git] / fs / udf / balloc.c
index b2d96f45c12b97becf57e58b9034b84b1092dd94..19626e2491c4656b56fe672d3a9f3f8a09143c66 100644 (file)
 #define udf_clear_bit(nr, addr) ext2_clear_bit(nr, addr)
 #define udf_set_bit(nr, addr) ext2_set_bit(nr, addr)
 #define udf_test_bit(nr, addr) ext2_test_bit(nr, addr)
-#define udf_find_first_one_bit(addr, size) find_first_one_bit(addr, size)
 #define udf_find_next_one_bit(addr, size, offset) \
-               find_next_one_bit(addr, size, offset)
-
-#define leBPL_to_cpup(x) leNUM_to_cpup(BITS_PER_LONG, x)
-#define leNUM_to_cpup(x, y) xleNUM_to_cpup(x, y)
-#define xleNUM_to_cpup(x, y) (le ## x ## _to_cpup(y))
-#define uintBPL_t uint(BITS_PER_LONG)
-#define uint(x) xuint(x)
-#define xuint(x) __le ## x
-
-static inline int find_next_one_bit(void *addr, int size, int offset)
-{
-       uintBPL_t *p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG);
-       int result = offset & ~(BITS_PER_LONG - 1);
-       unsigned long tmp;
-
-       if (offset >= size)
-               return size;
-       size -= result;
-       offset &= (BITS_PER_LONG - 1);
-       if (offset) {
-               tmp = leBPL_to_cpup(p++);
-               tmp &= ~0UL << offset;
-               if (size < BITS_PER_LONG)
-                       goto found_first;
-               if (tmp)
-                       goto found_middle;
-               size -= BITS_PER_LONG;
-               result += BITS_PER_LONG;
-       }
-       while (size & ~(BITS_PER_LONG - 1)) {
-               tmp = leBPL_to_cpup(p++);
-               if (tmp)
-                       goto found_middle;
-               result += BITS_PER_LONG;
-               size -= BITS_PER_LONG;
-       }
-       if (!size)
-               return result;
-       tmp = leBPL_to_cpup(p);
-found_first:
-       tmp &= ~0UL >> (BITS_PER_LONG - size);
-found_middle:
-       return result + ffz(~tmp);
-}
-
-#define find_first_one_bit(addr, size)\
-       find_next_one_bit((addr), (size), 0)
+               ext2_find_next_bit(addr, size, offset)
 
 static int read_block_bitmap(struct super_block *sb,
                             struct udf_bitmap *bitmap, unsigned int block,
@@ -208,7 +161,7 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
                                        ((char *)bh->b_data)[(bit + i) >> 3]);
                        } else {
                                if (inode)
-                                       vfs_dq_free_block(inode, 1);
+                                       dquot_free_block(inode, 1);
                                udf_add_free_space(sb, sbi->s_partition, 1);
                        }
                }
@@ -260,11 +213,11 @@ static int udf_bitmap_prealloc_blocks(struct super_block *sb,
                while (bit < (sb->s_blocksize << 3) && block_count > 0) {
                        if (!udf_test_bit(bit, bh->b_data))
                                goto out;
-                       else if (vfs_dq_prealloc_block(inode, 1))
+                       else if (dquot_prealloc_block(inode, 1))
                                goto out;
                        else if (!udf_clear_bit(bit, bh->b_data)) {
                                udf_debug("bit already cleared for block %d\n", bit);
-                               vfs_dq_free_block(inode, 1);
+                               dquot_free_block(inode, 1);
                                goto out;
                        }
                        block_count--;
@@ -390,10 +343,14 @@ got_block:
        /*
         * Check quota for allocation of this block.
         */
-       if (inode && vfs_dq_alloc_block(inode, 1)) {
-               mutex_unlock(&sbi->s_alloc_mutex);
-               *err = -EDQUOT;
-               return 0;
+       if (inode) {
+               int ret = dquot_alloc_block(inode, 1);
+
+               if (ret) {
+                       mutex_unlock(&sbi->s_alloc_mutex);
+                       *err = ret;
+                       return 0;
+               }
        }
 
        newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
@@ -449,7 +406,7 @@ static void udf_table_free_blocks(struct super_block *sb,
        /* We do this up front - There are some error conditions that
           could occure, but.. oh well */
        if (inode)
-               vfs_dq_free_block(inode, count);
+               dquot_free_block(inode, count);
        udf_add_free_space(sb, sbi->s_partition, count);
 
        start = bloc->logicalBlockNum + offset;
@@ -694,7 +651,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
                epos.offset -= adsize;
 
                alloc_count = (elen >> sb->s_blocksize_bits);
-               if (inode && vfs_dq_prealloc_block(inode,
+               if (inode && dquot_prealloc_block(inode,
                        alloc_count > block_count ? block_count : alloc_count))
                        alloc_count = 0;
                else if (alloc_count > block_count) {
@@ -797,12 +754,13 @@ static int udf_table_new_block(struct super_block *sb,
        newblock = goal_eloc.logicalBlockNum;
        goal_eloc.logicalBlockNum++;
        goal_elen -= sb->s_blocksize;
-
-       if (inode && vfs_dq_alloc_block(inode, 1)) {
-               brelse(goal_epos.bh);
-               mutex_unlock(&sbi->s_alloc_mutex);
-               *err = -EDQUOT;
-               return 0;
+       if (inode) {
+               *err = dquot_alloc_block(inode, 1);
+               if (*err) {
+                       brelse(goal_epos.bh);
+                       mutex_unlock(&sbi->s_alloc_mutex);
+                       return 0;
+               }
        }
 
        if (goal_elen)