Skip to content

Commit

Permalink
erofs-utils: lib: use erofs_map_blocks() for all datalayouts
Browse files Browse the repository at this point in the history
It simplifies the codebase a bit.

Signed-off-by: Gao Xiang <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
hsiangkao committed Jan 21, 2025
1 parent a8a1034 commit c38e066
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
11 changes: 1 addition & 10 deletions dump/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,6 @@ static int erofsdump_readdir(struct erofs_dir_context *ctx)
return 0;
}

static int erofsdump_map_blocks(struct erofs_inode *inode,
struct erofs_map_blocks *map, int flags)
{
if (erofs_inode_is_data_compressed(inode->datalayout))
return z_erofs_map_blocks_iter(inode, map, flags);
return erofs_map_blocks(inode, map, flags);
}

static void erofsdump_show_fileinfo(bool show_extent)
{
const char *ext_fmt[] = {
Expand Down Expand Up @@ -461,8 +453,7 @@ static void erofsdump_show_fileinfo(bool show_extent)
while (map.m_la < inode.i_size) {
struct erofs_map_dev mdev;

err = erofsdump_map_blocks(&inode, &map,
EROFS_GET_BLOCKS_FIEMAP);
err = erofs_map_blocks(&inode, &map, EROFS_GET_BLOCKS_FIEMAP);
if (err) {
erofs_err("failed to get file blocks range");
return;
Expand Down
23 changes: 2 additions & 21 deletions fsck/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,31 +527,12 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
erofs_dbg("verify data chunk of nid(%llu): type(%d)",
inode->nid | 0ULL, inode->datalayout);

switch (inode->datalayout) {
case EROFS_INODE_FLAT_PLAIN:
case EROFS_INODE_FLAT_INLINE:
case EROFS_INODE_CHUNK_BASED:
compressed = false;
break;
case EROFS_INODE_COMPRESSED_FULL:
case EROFS_INODE_COMPRESSED_COMPACT:
compressed = true;
break;
default:
erofs_err("unknown datalayout");
return -EINVAL;
}

compressed = erofs_inode_is_data_compressed(inode->datalayout);
while (pos < inode->i_size) {
unsigned int alloc_rawsize;

map.m_la = pos;
if (compressed)
ret = z_erofs_map_blocks_iter(inode, &map,
EROFS_GET_BLOCKS_FIEMAP);
else
ret = erofs_map_blocks(inode, &map,
EROFS_GET_BLOCKS_FIEMAP);
ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_FIEMAP);
if (ret)
goto out;

Expand Down
12 changes: 10 additions & 2 deletions lib/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ static int erofs_map_blocks_flatmode(struct erofs_inode *inode,
return err;
}

int erofs_map_blocks(struct erofs_inode *inode,
struct erofs_map_blocks *map, int flags)
int __erofs_map_blocks(struct erofs_inode *inode,
struct erofs_map_blocks *map, int flags)
{
struct erofs_inode *vi = inode;
struct erofs_sb_info *sbi = inode->sbi;
Expand Down Expand Up @@ -132,6 +132,14 @@ int erofs_map_blocks(struct erofs_inode *inode,
return err;
}

int erofs_map_blocks(struct erofs_inode *inode,
struct erofs_map_blocks *map, int flags)
{
if (erofs_inode_is_data_compressed(inode->datalayout))
return z_erofs_map_blocks_iter(inode, map, flags);
return __erofs_map_blocks(inode, map, flags);
}

int erofs_map_dev(struct erofs_sb_info *sbi, struct erofs_map_dev *map)
{
struct erofs_device_info *dif;
Expand Down

0 comments on commit c38e066

Please sign in to comment.