]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
fat: permit to return phy block number by fibmap in fallocated region
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)
Make the fibmap call the return the proper physical block number for any
offset request in the fallocated range.

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/cache.c
fs/fat/fat.h
fs/fat/inode.c

index a132666920e66ef15a6d553406f9de03d6ec09fa..e26bc9a22ac923258e1c6fddae5096d8f4a38fd7 100644 (file)
@@ -303,6 +303,31 @@ static int fat_bmap_cluster(struct inode *inode, int cluster)
        return dclus;
 }
 
+static int fat_get_mapped_cluster(struct inode *inode, sector_t sector,
+                                 sector_t last_block,
+                                 unsigned long *mapped_blocks, sector_t *bmap)
+{
+       struct super_block *sb = inode->i_sb;
+       struct msdos_sb_info *sbi = MSDOS_SB(sb);
+       int cluster, offset;
+
+       cluster = sector >> (sbi->cluster_bits - sb->s_blocksize_bits);
+       offset  = sector & (sbi->sec_per_clus - 1);
+       cluster = fat_bmap_cluster(inode, cluster);
+
+       if (cluster < 0)
+               return cluster;
+
+       else if (cluster) {
+               *bmap = fat_clus_to_blknr(sbi, cluster) + offset;
+               *mapped_blocks = sbi->sec_per_clus - offset;
+               if (*mapped_blocks > last_block - sector)
+                       *mapped_blocks = last_block - sector;
+       }
+
+       return 0;
+}
+
 int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
             unsigned long *mapped_blocks, int create)
 {
@@ -311,7 +336,6 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
        const unsigned long blocksize = sb->s_blocksize;
        const unsigned char blocksize_bits = sb->s_blocksize_bits;
        sector_t last_block;
-       int cluster, offset;
 
        *phys = 0;
        *mapped_blocks = 0;
@@ -338,16 +362,30 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
                        return 0;
        }
 
-       cluster = sector >> (sbi->cluster_bits - sb->s_blocksize_bits);
-       offset  = sector & (sbi->sec_per_clus - 1);
-       cluster = fat_bmap_cluster(inode, cluster);
-       if (cluster < 0)
-               return cluster;
-       else if (cluster) {
-               *phys = fat_clus_to_blknr(sbi, cluster) + offset;
-               *mapped_blocks = sbi->sec_per_clus - offset;
-               if (*mapped_blocks > last_block - sector)
-                       *mapped_blocks = last_block - sector;
-       }
-       return 0;
+       return fat_get_mapped_cluster(inode, sector, last_block, mapped_blocks,
+                                     phys);
+}
+
+int fat_bmap2(struct inode *inode, sector_t sector,
+             unsigned long *mapped_blocks, struct buffer_head *bh_result,
+             int create, sector_t *bmap)
+{
+       struct super_block *sb = inode->i_sb;
+       sector_t last_block;
+       const unsigned long blocksize = sb->s_blocksize;
+       const unsigned char blocksize_bits = sb->s_blocksize_bits;
+
+       BUG_ON(create != 0);
+
+       *bmap = 0;
+       *mapped_blocks = 0;
+
+       last_block = (MSDOS_I(inode)->i_disksize + (blocksize - 1))
+               >> blocksize_bits;
+
+       if (sector >= last_block)
+               return 0;
+
+       return fat_get_mapped_cluster(inode, sector, last_block, mapped_blocks,
+                                     bmap);
 }
index f6bcaa7f1a10029245c6fae1c469a7f58749927d..13b7202bd651535ff7ee66b3d006d97c21f018c3 100644 (file)
@@ -291,6 +291,9 @@ extern int fat_get_cluster(struct inode *inode, int cluster,
                           int *fclus, int *dclus);
 extern int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
                    unsigned long *mapped_blocks, int create);
+extern int fat_bmap2(struct inode *inode, sector_t sector,
+                    unsigned long *mapped_blocks,
+                    struct buffer_head *bh_result, int create, sector_t *bmap);
 
 /* fat/dir.c */
 extern const struct file_operations fat_dir_operations;
index e45a3bbfe04248150be58f9bac4c4eda05501b6c..c3b86c58ad8834325834a8d83a2da976a89955f2 100644 (file)
@@ -312,13 +312,36 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb,
        return ret;
 }
 
+static int fat_get_block_bmap(struct inode *inode, sector_t iblock,
+               struct buffer_head *bh_result, int create)
+{
+       struct super_block *sb = inode->i_sb;
+       unsigned long max_blocks = bh_result->b_size >> inode->i_blkbits;
+       int err;
+       sector_t bmap;
+       unsigned long mapped_blocks;
+
+       err = fat_bmap2(inode, iblock, &mapped_blocks, bh_result, create,
+                       &bmap);
+       if (err)
+               return err;
+
+       if (bmap) {
+               map_bh(bh_result, sb, bmap);
+               max_blocks = min(mapped_blocks, max_blocks);
+       }
+
+       bh_result->b_size = max_blocks << sb->s_blocksize_bits;
+       return 0;
+}
+
 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);
-       blocknr = generic_block_bmap(mapping, block, fat_get_block);
+       blocknr = generic_block_bmap(mapping, block, fat_get_block_bmap);
        up_read(&MSDOS_I(mapping->host)->truncate_lock);
 
        return blocknr;