From 93f6c59d707e3a2cda5426e22f34e3763164cca9 Mon Sep 17 00:00:00 2001 From: Namjae Jeon Date: Fri, 3 Jan 2014 14:10:26 +1100 Subject: [PATCH] fat: permit to return phy block number by fibmap in fallocated region Make the fibmap call the return the proper physical block number for any offset request in the fallocated range. Signed-off-by: Namjae Jeon Signed-off-by: Amit Sahrawat Cc: OGAWA Hirofumi Signed-off-by: Andrew Morton --- fs/fat/cache.c | 16 ++++++++++++++-- fs/fat/inode.c | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fs/fat/cache.c b/fs/fat/cache.c index c56bd7e4af92..77778227911a 100644 --- a/fs/fat/cache.c +++ b/fs/fat/cache.c @@ -312,6 +312,7 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys, const unsigned char blocksize_bits = sb->s_blocksize_bits; sector_t last_block; int cluster, offset; + loff_t i_size = i_size_read(inode); *phys = 0; *mapped_blocks = 0; @@ -323,10 +324,20 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys, return 0; } - last_block = (i_size_read(inode) + (blocksize - 1)) >> blocksize_bits; + last_block = (i_size + (blocksize - 1)) >> blocksize_bits; if (sector >= last_block) { - if (!create) + if (!create) { + /* + * to map cluster in case of read request + * for a block in fallocated region + */ + if (MSDOS_I(inode)->i_disksize > + round_up(i_size, sb->s_blocksize)) { + goto out_map_cluster; + } + return 0; + } /* * Both ->mmu_private and ->i_disksize can access @@ -339,6 +350,7 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys, return 0; } +out_map_cluster: cluster = sector >> (sbi->cluster_bits - sb->s_blocksize_bits); offset = sector & (sbi->sec_per_clus - 1); cluster = fat_bmap_cluster(inode, cluster); diff --git a/fs/fat/inode.c b/fs/fat/inode.c index ffa2eccc62a2..4b796d5d735f 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -245,9 +245,9 @@ static sector_t _fat_bmap(struct address_space *mapping, sector_t block) sector_t blocknr; /* fat_get_cluster() assumes the requested blocknr isn't truncated. */ - down_read(&MSDOS_I(mapping->host)->truncate_lock); + mutex_lock(&mapping->host->i_mutex); blocknr = generic_block_bmap(mapping, block, fat_get_block); - up_read(&MSDOS_I(mapping->host)->truncate_lock); + mutex_unlock(&mapping->host->i_mutex); return blocknr; } -- 2.39.5