fat: zero out seek range on _fat_get_block
Subsystems (2)
PATCH v4 3/6 fat: zero out seek range on _fat_get_block
From: Namjae Jeon <[email protected]>
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.
--- fs/fat/inode.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
fs/fat/inode.c +23 -1
@@ -54,6 +54,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)
@@ -68,8 +87,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)
Signature · 1 line
1.7.11-rc0
OGAWA Hirofumi
maintainerfs/fat/inode.c static int fat_add_cluster(struct inode *inode) · line 69
Quoted 13 lines · Namjae Jeon
fs/fat/inode.c +13
-0+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) {
Maybe off-by-one error. If iblock == disk_block, phys should not be set by fat_bmap()?
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2014-03-18 23:59 GMT+09:00, OGAWA Hirofumi <[email protected]>:
Quoted 17 lines
Quoted 4 lines · Namjae Jeon
+static void check_fallocated_region(struct inode *inode,
sector_tiblock,fs/fat/inode.c +2
-0+ unsigned long *max_blocks, struct buffer_head *bh_result) +{fs/fat/inode.c static int fat_add_cluster(struct inode *inode) · line 69
Quoted 10 lines
fs/fat/inode.c +10
-0+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) {
Hi OGAWA.
Quoted 2 lines
Maybe off-by-one error. If iblock ==
disk_block, phys should not be set byfat_bmap()?
Yes, right, iblock == disk_block case is not needed in this condition because fat_bmap don't set to phys when iblock==diskblock.(phys will be 0)
So I will change it like this.
if (iblock >= last_block && iblock < disk_block) {
And I will fix your review comments in other patches.
Thanks for review!
Quoted 3 lines
--
OGAWA Hirofumi <[email protected]>