]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
fat: zero out seek range on _fat_get_block
authorNamjae Jeon <namjae.jeon@samsung.com>
Thu, 26 Jun 2014 00:43:23 +0000 (10:43 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 27 Jun 2014 04:21:53 +0000 (14:21 +1000)
For normal buffered write operations, normally if we try to write to an
offset > than file size, it does a cont_expand_zero till that offset.
Now, in case of fallocated regions, since the blocks are already
allocated.  So, make it zero out that buffers for those blocks till the
seek'ed offset.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/fat/inode.c

index d08f7ab0ae88e7afa65f17f8cdcbeca8ed730208..df4be1932f684f4a33bc1840735eff7e07153101 100644 (file)
@@ -116,6 +116,25 @@ static int fat_add_cluster(struct inode *inode)
        return err;
 }
 
+static void check_fallocated_region(struct inode *inode, sector_t iblock,
+               unsigned long *max_blocks, struct buffer_head *bh_result)
+{
+       struct super_block *sb = inode->i_sb;
+       sector_t last_block, disk_block;
+       const unsigned long blocksize = sb->s_blocksize;
+       const unsigned char blocksize_bits = sb->s_blocksize_bits;
+
+       last_block = (MSDOS_I(inode)->mmu_private + (blocksize - 1))
+               >> blocksize_bits;
+       disk_block = (MSDOS_I(inode)->i_disksize + (blocksize - 1))
+               >> blocksize_bits;
+       if (iblock >= last_block && iblock <= disk_block) {
+               MSDOS_I(inode)->mmu_private += *max_blocks << blocksize_bits;
+               set_buffer_new(bh_result);
+       }
+
+}
+
 static inline int __fat_get_block(struct inode *inode, sector_t iblock,
                                  unsigned long *max_blocks,
                                  struct buffer_head *bh_result, int create)
@@ -130,8 +149,11 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock,
        if (err)
                return err;
        if (phys) {
-               map_bh(bh_result, sb, phys);
                *max_blocks = min(mapped_blocks, *max_blocks);
+               if (create)
+                       check_fallocated_region(inode, iblock, max_blocks,
+                               bh_result);
+               map_bh(bh_result, sb, phys);
                return 0;
        }
        if (!create)