Skip to content

Commit ac844e9

Browse files
YuezhangMonamjaejeon
authored andcommitted
exfat: add exfat_get_dentry_set_by_ei() helper
This helper gets the directory entry set of the file for the exfat inode which has been created. It's used to remove all the instances of the pattern it replaces making the code cleaner, it's also a preparation for changing ->dir to record the cluster where the directory entry set is located and changing ->entry to record the index of the directory entry within the cluster. 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 06a2b0b commit ac844e9

File tree

3 files changed

+21
-36
lines changed

3 files changed

+21
-36
lines changed

fs/exfat/exfat_fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
508508
int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
509509
struct super_block *sb, struct exfat_chain *p_dir, int entry,
510510
unsigned int num_entries);
511+
#define exfat_get_dentry_set_by_ei(es, sb, ei) \
512+
exfat_get_dentry_set(es, sb, &(ei)->dir, (ei)->entry, ES_ALL_ENTRIES)
511513
int exfat_get_empty_dentry_set(struct exfat_entry_set_cache *es,
512514
struct super_block *sb, struct exfat_chain *p_dir, int entry,
513515
unsigned int num_entries);

fs/exfat/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int __exfat_write_inode(struct inode *inode, int sync)
4343
exfat_set_volume_dirty(sb);
4444

4545
/* get the directory entry of given file or directory */
46-
if (exfat_get_dentry_set(&es, sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES))
46+
if (exfat_get_dentry_set_by_ei(&es, sb, ei))
4747
return -EIO;
4848
ep = exfat_get_dentry_cached(&es, ES_IDX_FILE);
4949
ep2 = exfat_get_dentry_cached(&es, ES_IDX_STREAM);

fs/exfat/namei.c

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -779,26 +779,23 @@ static struct dentry *exfat_lookup(struct inode *dir, struct dentry *dentry,
779779
/* remove an entry, BUT don't truncate */
780780
static int exfat_unlink(struct inode *dir, struct dentry *dentry)
781781
{
782-
struct exfat_chain cdir;
783782
struct super_block *sb = dir->i_sb;
784783
struct inode *inode = dentry->d_inode;
785784
struct exfat_inode_info *ei = EXFAT_I(inode);
786785
struct exfat_entry_set_cache es;
787-
int entry, err = 0;
786+
int err = 0;
788787

789788
if (unlikely(exfat_forced_shutdown(sb)))
790789
return -EIO;
791790

792791
mutex_lock(&EXFAT_SB(sb)->s_lock);
793-
exfat_chain_dup(&cdir, &ei->dir);
794-
entry = ei->entry;
795792
if (ei->dir.dir == DIR_DELETED) {
796793
exfat_err(sb, "abnormal access to deleted dentry");
797794
err = -ENOENT;
798795
goto unlock;
799796
}
800797

801-
err = exfat_get_dentry_set(&es, sb, &cdir, entry, ES_ALL_ENTRIES);
798+
err = exfat_get_dentry_set_by_ei(&es, sb, ei);
802799
if (err) {
803800
err = -EIO;
804801
goto unlock;
@@ -928,21 +925,18 @@ static int exfat_check_dir_empty(struct super_block *sb,
928925
static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
929926
{
930927
struct inode *inode = dentry->d_inode;
931-
struct exfat_chain cdir, clu_to_free;
928+
struct exfat_chain clu_to_free;
932929
struct super_block *sb = inode->i_sb;
933930
struct exfat_sb_info *sbi = EXFAT_SB(sb);
934931
struct exfat_inode_info *ei = EXFAT_I(inode);
935932
struct exfat_entry_set_cache es;
936-
int entry, err;
933+
int err;
937934

938935
if (unlikely(exfat_forced_shutdown(sb)))
939936
return -EIO;
940937

941938
mutex_lock(&EXFAT_SB(inode->i_sb)->s_lock);
942939

943-
exfat_chain_dup(&cdir, &ei->dir);
944-
entry = ei->entry;
945-
946940
if (ei->dir.dir == DIR_DELETED) {
947941
exfat_err(sb, "abnormal access to deleted dentry");
948942
err = -ENOENT;
@@ -960,7 +954,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
960954
goto unlock;
961955
}
962956

963-
err = exfat_get_dentry_set(&es, sb, &cdir, entry, ES_ALL_ENTRIES);
957+
err = exfat_get_dentry_set_by_ei(&es, sb, ei);
964958
if (err) {
965959
err = -EIO;
966960
goto unlock;
@@ -995,8 +989,8 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
995989
return err;
996990
}
997991

998-
static int exfat_rename_file(struct inode *parent_inode, struct exfat_chain *p_dir,
999-
int oldentry, struct exfat_uni_name *p_uniname,
992+
static int exfat_rename_file(struct inode *parent_inode,
993+
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
1000994
struct exfat_inode_info *ei)
1001995
{
1002996
int ret, num_new_entries;
@@ -1012,7 +1006,7 @@ static int exfat_rename_file(struct inode *parent_inode, struct exfat_chain *p_d
10121006
if (num_new_entries < 0)
10131007
return num_new_entries;
10141008

1015-
ret = exfat_get_dentry_set(&old_es, sb, p_dir, oldentry, ES_ALL_ENTRIES);
1009+
ret = exfat_get_dentry_set_by_ei(&old_es, sb, ei);
10161010
if (ret) {
10171011
ret = -EIO;
10181012
return ret;
@@ -1066,21 +1060,19 @@ static int exfat_rename_file(struct inode *parent_inode, struct exfat_chain *p_d
10661060
return ret;
10671061
}
10681062

1069-
static int exfat_move_file(struct inode *parent_inode, struct exfat_chain *p_olddir,
1070-
int oldentry, struct exfat_chain *p_newdir,
1071-
struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei)
1063+
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)
10721066
{
10731067
int ret, newentry, num_new_entries;
10741068
struct exfat_dentry *epmov, *epnew;
1075-
struct super_block *sb = parent_inode->i_sb;
10761069
struct exfat_entry_set_cache mov_es, new_es;
10771070

10781071
num_new_entries = exfat_calc_num_entries(p_uniname);
10791072
if (num_new_entries < 0)
10801073
return num_new_entries;
10811074

1082-
ret = exfat_get_dentry_set(&mov_es, sb, p_olddir, oldentry,
1083-
ES_ALL_ENTRIES);
1075+
ret = exfat_get_dentry_set_by_ei(&mov_es, parent_inode->i_sb, ei);
10841076
if (ret)
10851077
return -EIO;
10861078

@@ -1129,8 +1121,7 @@ static int __exfat_rename(struct inode *old_parent_inode,
11291121
struct dentry *new_dentry)
11301122
{
11311123
int ret;
1132-
int dentry;
1133-
struct exfat_chain olddir, newdir;
1124+
struct exfat_chain newdir;
11341125
struct exfat_uni_name uni_name;
11351126
struct super_block *sb = old_parent_inode->i_sb;
11361127
struct exfat_sb_info *sbi = EXFAT_SB(sb);
@@ -1147,11 +1138,6 @@ static int __exfat_rename(struct inode *old_parent_inode,
11471138
return -ENOENT;
11481139
}
11491140

1150-
exfat_chain_set(&olddir, EXFAT_I(old_parent_inode)->start_clu,
1151-
EXFAT_B_TO_CLU_ROUND_UP(i_size_read(old_parent_inode), sbi),
1152-
EXFAT_I(old_parent_inode)->flags);
1153-
dentry = ei->entry;
1154-
11551141
/* check whether new dir is existing directory and empty */
11561142
if (new_inode) {
11571143
ret = -EIO;
@@ -1186,21 +1172,18 @@ static int __exfat_rename(struct inode *old_parent_inode,
11861172

11871173
exfat_set_volume_dirty(sb);
11881174

1189-
if (olddir.dir == newdir.dir)
1190-
ret = exfat_rename_file(new_parent_inode, &olddir, dentry,
1175+
if (new_parent_inode == old_parent_inode)
1176+
ret = exfat_rename_file(new_parent_inode, &newdir,
11911177
&uni_name, ei);
11921178
else
1193-
ret = exfat_move_file(new_parent_inode, &olddir, dentry,
1194-
&newdir, &uni_name, ei);
1179+
ret = exfat_move_file(new_parent_inode, &newdir,
1180+
&uni_name, ei);
11951181

11961182
if (!ret && new_inode) {
11971183
struct exfat_entry_set_cache es;
1198-
struct exfat_chain *p_dir = &(new_ei->dir);
1199-
int new_entry = new_ei->entry;
12001184

12011185
/* delete entries of new_dir */
1202-
ret = exfat_get_dentry_set(&es, sb, p_dir, new_entry,
1203-
ES_ALL_ENTRIES);
1186+
ret = exfat_get_dentry_set_by_ei(&es, sb, new_ei);
12041187
if (ret) {
12051188
ret = -EIO;
12061189
goto del_out;

0 commit comments

Comments
 (0)