Commit d8b3df8b authored by Huang Jianan's avatar Huang Jianan Committed by Gao Xiang
Browse files

erofs: avoid using generic_block_bmap

Surprisingly, `block' in sector_t indicates the number of
i_blkbits-sized blocks rather than sectors for bmap.

In addition, considering buffer_head limits mapped size to 32-bits,
should avoid using generic_block_bmap.

Link: https://lore.kernel.org/r/20201209115740.18802-1-huangjianan@oppo.com


Fixes: 9da681e0 ("staging: erofs: support bmap")
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Reviewed-by: default avatarGao Xiang <hsiangkao@redhat.com>
Signed-off-by: default avatarHuang Jianan <huangjianan@oppo.com>
Signed-off-by: default avatarGuo Weichao <guoweichao@oppo.com>
[ Gao Xiang: slightly update the commit message description. ]
Signed-off-by: default avatarGao Xiang <hsiangkao@redhat.com>
parent 1825c8d7
Loading
Loading
Loading
Loading
+7 −19
Original line number Diff line number Diff line
@@ -312,27 +312,12 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
		submit_bio(bio);
}

static int erofs_get_block(struct inode *inode, sector_t iblock,
			   struct buffer_head *bh, int create)
{
	struct erofs_map_blocks map = {
		.m_la = iblock << 9,
	};
	int err;

	err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
	if (err)
		return err;

	if (map.m_flags & EROFS_MAP_MAPPED)
		bh->b_blocknr = erofs_blknr(map.m_pa);

	return err;
}

static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
{
	struct inode *inode = mapping->host;
	struct erofs_map_blocks map = {
		.m_la = blknr_to_addr(block),
	};

	if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
		erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;
@@ -341,7 +326,10 @@ static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
			return 0;
	}

	return generic_block_bmap(mapping, block, erofs_get_block);
	if (!erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW))
		return erofs_blknr(map.m_pa);

	return 0;
}

/* for uncompressed (aligned) files and raw access for other files */