Previously, EROFS uses EIO to indicate that filesystem
is corrupted as well. However, as Pavel said [1], other
filesystems tend to use EUCLEAN(EFSCORRUPTED) instead,
let's follow what others do right now.
Also, add some more prints to the syslog.
[1] https://lore.kernel.org/lkml/
20190813114821.GB11559@amd/
Suggested-by: Pavel Machek <pavel@denx.de>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Link: https://lore.kernel.org/r/20190814103705.60698-1-gaoxiang25@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
vi->xattr_isize + erofs_blkoff(map->m_la);
map->m_plen = inode->i_size - offset;
- /* inline data should locate in one meta block */
+ /* inline data should be located in one meta block */
if (erofs_blkoff(map->m_pa) + map->m_plen > PAGE_SIZE) {
+ errln("inline data cross block boundary @ nid %llu",
+ vi->nid);
DBG_BUGON(1);
- err = -EIO;
+ err = -EFSCORRUPTED;
goto err_out;
}
#endif
}
-static int erofs_fill_dentries(struct dir_context *ctx,
+static int erofs_fill_dentries(struct inode *dir, struct dir_context *ctx,
void *dentry_blk, unsigned int *ofs,
unsigned int nameoff, unsigned int maxsize)
{
/* a corrupted entry is found */
if (unlikely(nameoff + de_namelen > maxsize ||
de_namelen > EROFS_NAME_LEN)) {
+ errln("bogus dirent @ nid %llu", EROFS_V(dir)->nid);
DBG_BUGON(1);
- return -EIO;
+ return -EFSCORRUPTED;
}
debug_one_dentry(d_type, de_name, de_namelen);
if (unlikely(nameoff < sizeof(struct erofs_dirent) ||
nameoff >= PAGE_SIZE)) {
- errln("%s, invalid de[0].nameoff %u",
- __func__, nameoff);
-
- err = -EIO;
+ errln("%s, invalid de[0].nameoff %u @ nid %llu",
+ __func__, nameoff, EROFS_V(dir)->nid);
+ err = -EFSCORRUPTED;
goto skip_this;
}
goto skip_this;
}
- err = erofs_fill_dentries(ctx, de, &ofs, nameoff, maxsize);
+ err = erofs_fill_dentries(dir, ctx, de, &ofs,
+ nameoff, maxsize);
skip_this:
kunmap(dentry_page);
else if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode))
inode->i_rdev = 0;
else
- return -EIO;
+ goto bogusimode;
i_uid_write(inode, le32_to_cpu(v2->i_uid));
i_gid_write(inode, le32_to_cpu(v2->i_gid));
else if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode))
inode->i_rdev = 0;
else
- return -EIO;
+ goto bogusimode;
i_uid_write(inode, le16_to_cpu(v1->i_uid));
i_gid_write(inode, le16_to_cpu(v1->i_gid));
else
inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK;
return 0;
+
+bogusimode:
+ errln("bogus i_mode (%o) @ nid %llu", inode->i_mode, vi->nid);
+ DBG_BUGON(1);
+ return -EFSCORRUPTED;
}
/*
/* inline symlink data shouldn't across page boundary as well */
if (unlikely(m_pofs + inode->i_size > PAGE_SIZE)) {
- DBG_BUGON(1);
kfree(lnk);
- return -EIO;
+ errln("inline data cross block boundary @ nid %llu",
+ vi->nid);
+ DBG_BUGON(1);
+ return -EFSCORRUPTED;
}
/* get in-page inline data */
init_special_inode(inode, inode->i_mode, inode->i_rdev);
goto out_unlock;
} else {
- err = -EIO;
+ err = -EFSCORRUPTED;
goto out_unlock;
}
static inline void z_erofs_exit_zip_subsystem(void) {}
#endif /* !CONFIG_EROFS_FS_ZIP */
+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
+
#endif /* __EROFS_INTERNAL_H */
struct erofs_qstr dname;
if (unlikely(!ndirents)) {
- DBG_BUGON(1);
kunmap_atomic(de);
put_page(page);
- page = ERR_PTR(-EIO);
+ errln("corrupted dir block %d @ nid %llu",
+ mid, EROFS_V(dir)->nid);
+ DBG_BUGON(1);
+ page = ERR_PTR(-EFSCORRUPTED);
goto out;
}
goto out_unlock;
} else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) {
if (unlikely(vi->xattr_isize)) {
+ errln("bogus xattr ibody @ nid %llu", vi->nid);
DBG_BUGON(1);
- ret = -EIO;
+ ret = -EFSCORRUPTED;
goto out_unlock; /* xattr ondisk layout error */
}
ret = -ENOATTR;
/* xattr on-disk corruption: xattr entry beyond xattr_isize */
if (unlikely(*tlimit < entry_sz)) {
DBG_BUGON(1);
- return -EIO;
+ return -EFSCORRUPTED;
}
*tlimit -= entry_sz;
}
int err;
if (lcn < lookback_distance) {
+ errln("bogus lookback distance @ nid %llu", vi->nid);
DBG_BUGON(1);
- return -EIO;
+ return -EFSCORRUPTED;
}
/* load extent head logical cluster if needed */
if (unlikely(!m.lcn)) {
errln("invalid logical cluster 0 at nid %llu",
vi->nid);
- err = -EIO;
+ err = -EFSCORRUPTED;
goto unmap_out;
}
end = (m.lcn << lclusterbits) | m.clusterofs;