Skip to content

Commit e2db652

Browse files
aalexandrovichgregkh
authored andcommitted
fs/ntfs3: Unify inode corruption marking with _ntfs_bad_inode()
[ Upstream commit 55ad333 ] Also reworked error handling in a couple of places. Signed-off-by: Konstantin Komarov <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 44e35bf commit e2db652

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

fs/ntfs3/attrib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ int attr_wof_frame_info(struct ntfs_inode *ni, struct ATTRIB *attr,
14061406
*/
14071407
if (!attr->non_res) {
14081408
if (vbo[1] + bytes_per_off > le32_to_cpu(attr->res.data_size)) {
1409-
ntfs_inode_err(&ni->vfs_inode, "is corrupted");
1409+
_ntfs_bad_inode(&ni->vfs_inode);
14101410
return -EINVAL;
14111411
}
14121412
addr = resident_data(attr);
@@ -2587,7 +2587,7 @@ int attr_force_nonresident(struct ntfs_inode *ni)
25872587

25882588
attr = ni_find_attr(ni, NULL, &le, ATTR_DATA, NULL, 0, NULL, &mi);
25892589
if (!attr) {
2590-
ntfs_bad_inode(&ni->vfs_inode, "no data attribute");
2590+
_ntfs_bad_inode(&ni->vfs_inode);
25912591
return -ENOENT;
25922592
}
25932593

fs/ntfs3/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ static int ntfs_readdir(struct file *file, struct dir_context *ctx)
512512
ctx->pos = pos;
513513
} else if (err < 0) {
514514
if (err == -EINVAL)
515-
ntfs_inode_err(dir, "directory corrupted");
515+
_ntfs_bad_inode(dir);
516516
ctx->pos = eod;
517517
}
518518

fs/ntfs3/frecord.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ int ni_load_mi_ex(struct ntfs_inode *ni, CLST rno, struct mft_inode **mi)
148148
goto out;
149149

150150
err = mi_get(ni->mi.sbi, rno, &r);
151-
if (err)
151+
if (err) {
152+
_ntfs_bad_inode(&ni->vfs_inode);
152153
return err;
154+
}
153155

154156
ni_add_mi(ni, r);
155157

@@ -238,8 +240,7 @@ struct ATTRIB *ni_find_attr(struct ntfs_inode *ni, struct ATTRIB *attr,
238240
return attr;
239241

240242
out:
241-
ntfs_inode_err(&ni->vfs_inode, "failed to parse mft record");
242-
ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR);
243+
_ntfs_bad_inode(&ni->vfs_inode);
243244
return NULL;
244245
}
245246

@@ -330,6 +331,7 @@ struct ATTRIB *ni_load_attr(struct ntfs_inode *ni, enum ATTR_TYPE type,
330331
vcn <= le64_to_cpu(attr->nres.evcn))
331332
return attr;
332333

334+
_ntfs_bad_inode(&ni->vfs_inode);
333335
return NULL;
334336
}
335337

@@ -1604,8 +1606,8 @@ int ni_delete_all(struct ntfs_inode *ni)
16041606
roff = le16_to_cpu(attr->nres.run_off);
16051607

16061608
if (roff > asize) {
1607-
_ntfs_bad_inode(&ni->vfs_inode);
1608-
return -EINVAL;
1609+
/* ni_enum_attr_ex checks this case. */
1610+
continue;
16091611
}
16101612

16111613
/* run==1 means unpack and deallocate. */

fs/ntfs3/fsntfs.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,11 @@ void ntfs_bad_inode(struct inode *inode, const char *hint)
908908

909909
ntfs_inode_err(inode, "%s", hint);
910910
make_bad_inode(inode);
911-
ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
911+
/* Avoid recursion if bad inode is $Volume. */
912+
if (inode->i_ino != MFT_REC_VOL &&
913+
!(sbi->flags & NTFS_FLAGS_LOG_REPLAYING)) {
914+
ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
915+
}
912916
}
913917

914918
/*

fs/ntfs3/index.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,7 @@ int indx_read(struct ntfs_index *indx, struct ntfs_inode *ni, CLST vbn,
10941094

10951095
ok:
10961096
if (!index_buf_check(ib, bytes, &vbn)) {
1097-
ntfs_inode_err(&ni->vfs_inode, "directory corrupted");
1098-
ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR);
1097+
_ntfs_bad_inode(&ni->vfs_inode);
10991098
err = -EINVAL;
11001099
goto out;
11011100
}
@@ -1117,8 +1116,7 @@ int indx_read(struct ntfs_index *indx, struct ntfs_inode *ni, CLST vbn,
11171116

11181117
out:
11191118
if (err == -E_NTFS_CORRUPT) {
1120-
ntfs_inode_err(&ni->vfs_inode, "directory corrupted");
1121-
ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR);
1119+
_ntfs_bad_inode(&ni->vfs_inode);
11221120
err = -EINVAL;
11231121
}
11241122

fs/ntfs3/inode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ static struct inode *ntfs_read_mft(struct inode *inode,
410410
if (!std5)
411411
goto out;
412412

413+
if (is_bad_inode(inode))
414+
goto out;
415+
413416
if (!is_match && name) {
414417
err = -ENOENT;
415418
goto out;

0 commit comments

Comments
 (0)