Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / fs / ext2 / balloc.c
index 9f9992b..4c40c07 100644 (file)
@@ -1193,6 +1193,27 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
        return 1;
 }
 
+/*
+ * Returns 1 if the passed-in block region is valid; 0 if some part overlaps
+ * with filesystem metadata blocksi.
+ */
+int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
+                         unsigned int count)
+{
+       if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
+           (start_blk + count < start_blk) ||
+           (start_blk > le32_to_cpu(sbi->s_es->s_blocks_count)))
+               return 0;
+
+       /* Ensure we do not step over superblock */
+       if ((start_blk <= sbi->s_sb_block) &&
+           (start_blk + count >= sbi->s_sb_block))
+               return 0;
+
+
+       return 1;
+}
+
 /*
  * ext2_new_blocks() -- core block(s) allocation function
  * @inode:             file inode