Also reworked error handling in a couple of places.
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
         */
        if (!attr->non_res) {
                if (vbo[1] + bytes_per_off > le32_to_cpu(attr->res.data_size)) {
-                       ntfs_inode_err(&ni->vfs_inode, "is corrupted");
+                       _ntfs_bad_inode(&ni->vfs_inode);
                        return -EINVAL;
                }
                addr = resident_data(attr);
 
        attr = ni_find_attr(ni, NULL, &le, ATTR_DATA, NULL, 0, NULL, &mi);
        if (!attr) {
-               ntfs_bad_inode(&ni->vfs_inode, "no data attribute");
+               _ntfs_bad_inode(&ni->vfs_inode);
                return -ENOENT;
        }
 
 
                ctx->pos = pos;
        } else if (err < 0) {
                if (err == -EINVAL)
-                       ntfs_inode_err(dir, "directory corrupted");
+                       _ntfs_bad_inode(dir);
                ctx->pos = eod;
        }
 
 
                goto out;
 
        err = mi_get(ni->mi.sbi, rno, &r);
-       if (err)
+       if (err) {
+               _ntfs_bad_inode(&ni->vfs_inode);
                return err;
+       }
 
        ni_add_mi(ni, r);
 
        return attr;
 
 out:
-       ntfs_inode_err(&ni->vfs_inode, "failed to parse mft record");
-       ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR);
+       _ntfs_bad_inode(&ni->vfs_inode);
        return NULL;
 }
 
            vcn <= le64_to_cpu(attr->nres.evcn))
                return attr;
 
+       _ntfs_bad_inode(&ni->vfs_inode);
        return NULL;
 }
 
                roff = le16_to_cpu(attr->nres.run_off);
 
                if (roff > asize) {
-                       _ntfs_bad_inode(&ni->vfs_inode);
-                       return -EINVAL;
+                       /* ni_enum_attr_ex checks this case. */
+                       continue;
                }
 
                /* run==1 means unpack and deallocate. */
 
 
        ntfs_inode_err(inode, "%s", hint);
        make_bad_inode(inode);
-       ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
+       /* Avoid recursion if bad inode is $Volume. */
+       if (inode->i_ino != MFT_REC_VOL &&
+           !(sbi->flags & NTFS_FLAGS_LOG_REPLAYING)) {
+               ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
+       }
 }
 
 /*
 
 
 ok:
        if (!index_buf_check(ib, bytes, &vbn)) {
-               ntfs_inode_err(&ni->vfs_inode, "directory corrupted");
-               ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR);
+               _ntfs_bad_inode(&ni->vfs_inode);
                err = -EINVAL;
                goto out;
        }
 
 out:
        if (err == -E_NTFS_CORRUPT) {
-               ntfs_inode_err(&ni->vfs_inode, "directory corrupted");
-               ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR);
+               _ntfs_bad_inode(&ni->vfs_inode);
                err = -EINVAL;
        }
 
 
        if (!std5)
                goto out;
 
+       if (is_bad_inode(inode))
+               goto out;
+
        if (!is_match && name) {
                err = -ENOENT;
                goto out;