Add additional on-disk inode checks.

Reviewed by:    pfg
MFC after:      1 week

Differential Revision:    https://reviews.freebsd.org/D19323
This commit is contained in:
Fedor Uporov 2019-03-04 10:55:01 +00:00
parent 6e38bf94e5
commit daa2d62da2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=344752
4 changed files with 40 additions and 4 deletions

View File

@ -629,6 +629,8 @@ ext2_ei_csum_verify(struct inode *ip, struct ext2fs_dinode *ei)
if (!memcmp(ei, &ei_zero, sizeof(struct ext2fs_dinode)))
return (0);
printf("WARNING: Bad inode %ju csum - run fsck\n", ip->i_number);
return (EIO);
}

View File

@ -34,7 +34,6 @@
#include <sys/stat.h>
#include <sys/vnode.h>
#include <fs/ext2fs/ext2fs.h>
#include <fs/ext2fs/fs.h>
#include <fs/ext2fs/inode.h>
#include <fs/ext2fs/ext2fs.h>
@ -92,8 +91,31 @@ ext2_print_inode(struct inode *in)
int
ext2_ei2i(struct ext2fs_dinode *ei, struct inode *ip)
{
struct m_ext2fs *fs = ip->i_e2fs;
if ((ip->i_number < EXT2_FIRST_INO(fs) && ip->i_number != EXT2_ROOTINO) ||
(ip->i_number < EXT2_ROOTINO) ||
(ip->i_number > fs->e2fs->e2fs_icount)) {
printf("ext2fs: bad inode number %ju\n", ip->i_number);
return (EINVAL);
}
if (ip->i_number == EXT2_ROOTINO && ei->e2di_nlink == 0) {
printf("ext2fs: root inode unallocated\n");
return (EINVAL);
}
ip->i_nlink = ei->e2di_nlink;
/* Check extra inode size */
if (EXT2_INODE_SIZE(fs) > E2FS_REV0_INODE_SIZE) {
if (E2FS_REV0_INODE_SIZE + ei->e2di_extra_isize >
EXT2_INODE_SIZE(fs) || (ei->e2di_extra_isize & 3)) {
printf("ext2fs: bad extra inode size %u, inode size=%u\n",
ei->e2di_extra_isize, EXT2_INODE_SIZE(fs));
return (EINVAL);
}
}
/*
* Godmar thinks - if the link count is zero, then the inode is
* unused - according to ext2 standards. Ufs marks this fact by

View File

@ -773,11 +773,18 @@ ext2_reload(struct mount *mp, struct thread *td)
MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
return (error);
}
ext2_ei2i((struct ext2fs_dinode *)((char *)bp->b_data +
error = ext2_ei2i((struct ext2fs_dinode *)((char *)bp->b_data +
EXT2_INODE_SIZE(fs) * ino_to_fsbo(fs, ip->i_number)), ip);
brelse(bp);
VOP_UNLOCK(vp, 0);
vrele(vp);
if (error) {
MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
return (error);
}
}
return (0);
}
@ -1208,8 +1215,6 @@ ext2_vget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp)
error = ext2_ei2i((struct ext2fs_dinode *)((char *)bp->b_data +
EXT2_INODE_SIZE(fs) * ino_to_fsbo(fs, ino)), ip);
if (error) {
printf("ext2fs: Bad inode %lu csum - run fsck\n",
(unsigned long)ino);
brelse(bp);
vput(vp);
*vpp = NULL;

View File

@ -422,4 +422,11 @@ struct ext2_gd {
EXT2F_INCOMPAT_64BIT) ? ((s)->e2fs_bsize / sizeof(struct ext2_gd)) : \
((s)->e2fs_bsize / E2FS_REV0_GD_SIZE))
/*
* Macro-instructions used to manage inodes
*/
#define EXT2_FIRST_INO(s) ((EXT2_SB(s)->e2fs->e2fs_rev == E2FS_REV0) ? \
EXT2_FIRSTINO : \
EXT2_SB(s)->e2fs->e2fs_first_ino)
#endif /* !_FS_EXT2FS_EXT2FS_H_ */