Skip to content

Commit 0891c73

Browse files
YuezhangMonamjaejeon
authored andcommitted
exfat: move exfat_chain_set() out of __exfat_resolve_path()
__exfat_resolve_path() mixes two functions. The first one is to resolve and check if the path is valid. The second one is to output the cluster assigned to the directory. The second one is only needed when need to traverse the directory entries, and calling exfat_chain_set() so early causes p_dir to be passed as an argument multiple times, increasing the complexity of the code. This commit moves the call to exfat_chain_set() before traversing directory entries. Signed-off-by: Yuezhang Mo <[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 ac844e9 commit 0891c73

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

fs/exfat/namei.c

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ static int exfat_find_empty_entry(struct inode *inode,
311311
ei->hint_femp.eidx = EXFAT_HINT_NONE;
312312
}
313313

314+
exfat_chain_set(p_dir, ei->start_clu,
315+
EXFAT_B_TO_CLU(i_size_read(inode), sbi), ei->flags);
316+
314317
while ((dentry = exfat_search_empty_slot(sb, &hint_femp, p_dir,
315318
num_entries, es)) < 0) {
316319
if (dentry == -EIO)
@@ -386,14 +389,11 @@ static int exfat_find_empty_entry(struct inode *inode,
386389
* Zero if it was successful; otherwise nonzero.
387390
*/
388391
static int __exfat_resolve_path(struct inode *inode, const unsigned char *path,
389-
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
390-
int lookup)
392+
struct exfat_uni_name *p_uniname, int lookup)
391393
{
392394
int namelen;
393395
int lossy = NLS_NAME_NO_LOSSY;
394396
struct super_block *sb = inode->i_sb;
395-
struct exfat_sb_info *sbi = EXFAT_SB(sb);
396-
struct exfat_inode_info *ei = EXFAT_I(inode);
397397
int pathlen = strlen(path);
398398

399399
/*
@@ -432,24 +432,19 @@ static int __exfat_resolve_path(struct inode *inode, const unsigned char *path,
432432
if ((lossy && !lookup) || !namelen)
433433
return (lossy & NLS_NAME_OVERLEN) ? -ENAMETOOLONG : -EINVAL;
434434

435-
exfat_chain_set(p_dir, ei->start_clu,
436-
EXFAT_B_TO_CLU(i_size_read(inode), sbi), ei->flags);
437-
438435
return 0;
439436
}
440437

441438
static inline int exfat_resolve_path(struct inode *inode,
442-
const unsigned char *path, struct exfat_chain *dir,
443-
struct exfat_uni_name *uni)
439+
const unsigned char *path, struct exfat_uni_name *uni)
444440
{
445-
return __exfat_resolve_path(inode, path, dir, uni, 0);
441+
return __exfat_resolve_path(inode, path, uni, 0);
446442
}
447443

448444
static inline int exfat_resolve_path_for_lookup(struct inode *inode,
449-
const unsigned char *path, struct exfat_chain *dir,
450-
struct exfat_uni_name *uni)
445+
const unsigned char *path, struct exfat_uni_name *uni)
451446
{
452-
return __exfat_resolve_path(inode, path, dir, uni, 1);
447+
return __exfat_resolve_path(inode, path, uni, 1);
453448
}
454449

455450
static inline loff_t exfat_make_i_pos(struct exfat_dir_entry *info)
@@ -471,7 +466,7 @@ static int exfat_add_entry(struct inode *inode, const char *path,
471466
int clu_size = 0;
472467
unsigned int start_clu = EXFAT_FREE_CLUSTER;
473468

474-
ret = exfat_resolve_path(inode, path, p_dir, &uniname);
469+
ret = exfat_resolve_path(inode, path, &uniname);
475470
if (ret)
476471
goto out;
477472

@@ -602,10 +597,13 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
602597
return -ENOENT;
603598

604599
/* check the validity of directory name in the given pathname */
605-
ret = exfat_resolve_path_for_lookup(dir, qname->name, &cdir, &uni_name);
600+
ret = exfat_resolve_path_for_lookup(dir, qname->name, &uni_name);
606601
if (ret)
607602
return ret;
608603

604+
exfat_chain_set(&cdir, ei->start_clu,
605+
EXFAT_B_TO_CLU(i_size_read(dir), sbi), ei->flags);
606+
609607
/* check the validation of hint_stat and initialize it if required */
610608
if (ei->version != (inode_peek_iversion_raw(dir) & 0xffffffff)) {
611609
ei->hint_stat.clu = cdir.dir;
@@ -990,8 +988,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
990988
}
991989

992990
static int exfat_rename_file(struct inode *parent_inode,
993-
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
994-
struct exfat_inode_info *ei)
991+
struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei)
995992
{
996993
int ret, num_new_entries;
997994
struct exfat_dentry *epold, *epnew;
@@ -1016,9 +1013,10 @@ static int exfat_rename_file(struct inode *parent_inode,
10161013

10171014
if (old_es.num_entries < num_new_entries) {
10181015
int newentry;
1016+
struct exfat_chain dir;
10191017

1020-
newentry = exfat_find_empty_entry(parent_inode, p_dir, num_new_entries,
1021-
&new_es);
1018+
newentry = exfat_find_empty_entry(parent_inode, &dir,
1019+
num_new_entries, &new_es);
10221020
if (newentry < 0) {
10231021
ret = newentry; /* -EIO or -ENOSPC */
10241022
goto put_old_es;
@@ -1042,7 +1040,7 @@ static int exfat_rename_file(struct inode *parent_inode,
10421040
goto put_old_es;
10431041

10441042
exfat_remove_entries(parent_inode, &old_es, ES_IDX_FILE);
1045-
ei->dir = *p_dir;
1043+
ei->dir = dir;
10461044
ei->entry = newentry;
10471045
} else {
10481046
if (exfat_get_entry_type(epold) == TYPE_FILE) {
@@ -1061,12 +1059,12 @@ static int exfat_rename_file(struct inode *parent_inode,
10611059
}
10621060

10631061
static int exfat_move_file(struct inode *parent_inode,
1064-
struct exfat_chain *p_newdir, struct exfat_uni_name *p_uniname,
1065-
struct exfat_inode_info *ei)
1062+
struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei)
10661063
{
10671064
int ret, newentry, num_new_entries;
10681065
struct exfat_dentry *epmov, *epnew;
10691066
struct exfat_entry_set_cache mov_es, new_es;
1067+
struct exfat_chain newdir;
10701068

10711069
num_new_entries = exfat_calc_num_entries(p_uniname);
10721070
if (num_new_entries < 0)
@@ -1076,8 +1074,8 @@ static int exfat_move_file(struct inode *parent_inode,
10761074
if (ret)
10771075
return -EIO;
10781076

1079-
newentry = exfat_find_empty_entry(parent_inode, p_newdir, num_new_entries,
1080-
&new_es);
1077+
newentry = exfat_find_empty_entry(parent_inode, &newdir,
1078+
num_new_entries, &new_es);
10811079
if (newentry < 0) {
10821080
ret = newentry; /* -EIO or -ENOSPC */
10831081
goto put_mov_es;
@@ -1098,9 +1096,7 @@ static int exfat_move_file(struct inode *parent_inode,
10981096
exfat_init_ext_entry(&new_es, num_new_entries, p_uniname);
10991097
exfat_remove_entries(parent_inode, &mov_es, ES_IDX_FILE);
11001098

1101-
exfat_chain_set(&ei->dir, p_newdir->dir, p_newdir->size,
1102-
p_newdir->flags);
1103-
1099+
ei->dir = newdir;
11041100
ei->entry = newentry;
11051101

11061102
ret = exfat_put_dentry_set(&new_es, IS_DIRSYNC(parent_inode));
@@ -1121,7 +1117,6 @@ static int __exfat_rename(struct inode *old_parent_inode,
11211117
struct dentry *new_dentry)
11221118
{
11231119
int ret;
1124-
struct exfat_chain newdir;
11251120
struct exfat_uni_name uni_name;
11261121
struct super_block *sb = old_parent_inode->i_sb;
11271122
struct exfat_sb_info *sbi = EXFAT_SB(sb);
@@ -1165,19 +1160,16 @@ static int __exfat_rename(struct inode *old_parent_inode,
11651160
}
11661161

11671162
/* check the validity of directory name in the given new pathname */
1168-
ret = exfat_resolve_path(new_parent_inode, new_path, &newdir,
1169-
&uni_name);
1163+
ret = exfat_resolve_path(new_parent_inode, new_path, &uni_name);
11701164
if (ret)
11711165
goto out;
11721166

11731167
exfat_set_volume_dirty(sb);
11741168

11751169
if (new_parent_inode == old_parent_inode)
1176-
ret = exfat_rename_file(new_parent_inode, &newdir,
1177-
&uni_name, ei);
1170+
ret = exfat_rename_file(new_parent_inode, &uni_name, ei);
11781171
else
1179-
ret = exfat_move_file(new_parent_inode, &newdir,
1180-
&uni_name, ei);
1172+
ret = exfat_move_file(new_parent_inode, &uni_name, ei);
11811173

11821174
if (!ret && new_inode) {
11831175
struct exfat_entry_set_cache es;

0 commit comments

Comments
 (0)