Skip to content

Commit d8dad25

Browse files
YuezhangMonamjaejeon
authored andcommitted
exfat: fix referencing wrong parent directory information after renaming
During renaming, the parent directory information maybe updated. But the file/directory still references to the old parent directory information. This bug will cause 2 problems. (1) The renamed file can not be written. [10768.175172] exFAT-fs (sda1): error, failed to bmap (inode : 7afd50e4 iblock : 0, err : -5) [10768.184285] exFAT-fs (sda1): Filesystem has been set read-only ash: write error: Input/output error (2) Some dentries of the renamed file/directory are not set to deleted after removing the file/directory. exfat_update_parent_info() is a workaround for the wrong parent directory information being used after renaming. Now that bug is fixed, this is no longer needed, so remove it. Fixes: 5f2aa07 ("exfat: add inode operations") Cc: [email protected] # v5.7+ Signed-off-by: Yuezhang Mo <[email protected]> Reviewed-by: Andy Wu <[email protected]> Reviewed-by: Aoyama Wataru <[email protected]> Reviewed-by: Daniel Palmer <[email protected]> Reviewed-by: Sungjong Seo <[email protected]> Signed-off-by: Namjae Jeon <[email protected]>
1 parent 4b0986a commit d8dad25

File tree

1 file changed

+1
-26
lines changed

1 file changed

+1
-26
lines changed

fs/exfat/namei.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
10801080

10811081
exfat_remove_entries(inode, p_dir, oldentry, 0,
10821082
num_old_entries);
1083+
ei->dir = *p_dir;
10831084
ei->entry = newentry;
10841085
} else {
10851086
if (exfat_get_entry_type(epold) == TYPE_FILE) {
@@ -1167,28 +1168,6 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir,
11671168
return 0;
11681169
}
11691170

1170-
static void exfat_update_parent_info(struct exfat_inode_info *ei,
1171-
struct inode *parent_inode)
1172-
{
1173-
struct exfat_sb_info *sbi = EXFAT_SB(parent_inode->i_sb);
1174-
struct exfat_inode_info *parent_ei = EXFAT_I(parent_inode);
1175-
loff_t parent_isize = i_size_read(parent_inode);
1176-
1177-
/*
1178-
* the problem that struct exfat_inode_info caches wrong parent info.
1179-
*
1180-
* because of flag-mismatch of ei->dir,
1181-
* there is abnormal traversing cluster chain.
1182-
*/
1183-
if (unlikely(parent_ei->flags != ei->dir.flags ||
1184-
parent_isize != EXFAT_CLU_TO_B(ei->dir.size, sbi) ||
1185-
parent_ei->start_clu != ei->dir.dir)) {
1186-
exfat_chain_set(&ei->dir, parent_ei->start_clu,
1187-
EXFAT_B_TO_CLU_ROUND_UP(parent_isize, sbi),
1188-
parent_ei->flags);
1189-
}
1190-
}
1191-
11921171
/* rename or move a old file into a new file */
11931172
static int __exfat_rename(struct inode *old_parent_inode,
11941173
struct exfat_inode_info *ei, struct inode *new_parent_inode,
@@ -1219,8 +1198,6 @@ static int __exfat_rename(struct inode *old_parent_inode,
12191198
return -ENOENT;
12201199
}
12211200

1222-
exfat_update_parent_info(ei, old_parent_inode);
1223-
12241201
exfat_chain_dup(&olddir, &ei->dir);
12251202
dentry = ei->entry;
12261203

@@ -1241,8 +1218,6 @@ static int __exfat_rename(struct inode *old_parent_inode,
12411218
goto out;
12421219
}
12431220

1244-
exfat_update_parent_info(new_ei, new_parent_inode);
1245-
12461221
p_dir = &(new_ei->dir);
12471222
new_entry = new_ei->entry;
12481223
ep = exfat_get_dentry(sb, p_dir, new_entry, &new_bh);

0 commit comments

Comments
 (0)