Skip to content

Commit d16621e

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 d9c699f commit d16621e

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

Diff for: fs/ntfs3/attrib.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ int attr_wof_frame_info(struct ntfs_inode *ni, struct ATTRIB *attr,
14071407
*/
14081408
if (!attr->non_res) {
14091409
if (vbo[1] + bytes_per_off > le32_to_cpu(attr->res.data_size)) {
1410-
ntfs_inode_err(&ni->vfs_inode, "is corrupted");
1410+
_ntfs_bad_inode(&ni->vfs_inode);
14111411
return -EINVAL;
14121412
}
14131413
addr = resident_data(attr);
@@ -2588,7 +2588,7 @@ int attr_force_nonresident(struct ntfs_inode *ni)
25882588

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

Diff for: fs/ntfs3/dir.c

+1-1
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

Diff for: fs/ntfs3/frecord.c

+7-5
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

@@ -239,8 +241,7 @@ struct ATTRIB *ni_find_attr(struct ntfs_inode *ni, struct ATTRIB *attr,
239241
return attr;
240242

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

@@ -332,6 +333,7 @@ struct ATTRIB *ni_load_attr(struct ntfs_inode *ni, enum ATTR_TYPE type,
332333
vcn <= le64_to_cpu(attr->nres.evcn))
333334
return attr;
334335

336+
_ntfs_bad_inode(&ni->vfs_inode);
335337
return NULL;
336338
}
337339

@@ -1607,8 +1609,8 @@ int ni_delete_all(struct ntfs_inode *ni)
16071609
roff = le16_to_cpu(attr->nres.run_off);
16081610

16091611
if (roff > asize) {
1610-
_ntfs_bad_inode(&ni->vfs_inode);
1611-
return -EINVAL;
1612+
/* ni_enum_attr_ex checks this case. */
1613+
continue;
16121614
}
16131615

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

Diff for: fs/ntfs3/fsntfs.c

+5-1
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
/*

Diff for: fs/ntfs3/index.c

+2-4
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

Diff for: fs/ntfs3/inode.c

+3
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)