Whamcloud - gitweb
LU-10641 e2fsck: avoid write inode attemp in readonly mode
[tools/e2fsprogs.git] / e2fsck / pass4.c
index d9210ea..6569cc1 100644 (file)
@@ -46,12 +46,6 @@ static int disconnect_inode(e2fsck_t ctx, ext2_ino_t i,
                if (ext2fs_test_inode_bitmap2(ctx->inode_ea_map, i)) {
                        ext2fs_icount_store(ctx->inode_count, i, 1);
                        return 0;
-               } else {
-                       /* Zero the link count so that when inode is linked to
-                        * lost+found it has correct link count */
-                       inode->i_links_count = 0;
-                       e2fsck_write_inode(ctx, i, inode, "disconnect_inode");
-                       ext2fs_icount_store(ctx->inode_link_info, i, 0);
                }
        }
 
@@ -88,6 +82,13 @@ static int disconnect_inode(e2fsck_t ctx, ext2_ino_t i,
         * Prompt to reconnect.
         */
        if (fix_problem(ctx, PR_4_UNATTACHED_INODE, &pctx)) {
+               if (inode->i_flags & EXT4_EA_INODE_FL) {
+                       /* Zero the link count so that when inode is linked to
+                        * lost+found it has correct link count */
+                       inode->i_links_count = 0;
+                       e2fsck_write_inode(ctx, i, inode, "disconnect_inode");
+                       ext2fs_icount_store(ctx->inode_link_info, i, 0);
+               }
                if (e2fsck_reconnect_file(ctx, i))
                        ext2fs_unmark_valid(fs);
        } else {