Skip to content

Commit ff39899

Browse files
YuezhangMonamjaejeon
authored andcommitted
exfat: simplify empty entry hint
This commit adds exfat_set_empty_hint()/exfat_reset_empty_hint() to reduce code complexity and make code more readable. Signed-off-by: Yuezhang Mo <[email protected]> Reviewed-by: Andy Wu <[email protected]> Reviewed-by: Aoyama Wataru <[email protected]> Reviewed-by: Sungjong Seo <[email protected]> Signed-off-by: Namjae Jeon <[email protected]>
1 parent 830b3c6 commit ff39899

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

fs/exfat/dir.c

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,29 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
897897
return NULL;
898898
}
899899

900+
static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp)
901+
{
902+
hint_femp->eidx = EXFAT_HINT_NONE;
903+
hint_femp->count = 0;
904+
}
905+
906+
static inline void exfat_set_empty_hint(struct exfat_inode_info *ei,
907+
struct exfat_hint_femp *candi_empty, struct exfat_chain *clu,
908+
int dentry, int num_entries)
909+
{
910+
if (ei->hint_femp.eidx == EXFAT_HINT_NONE ||
911+
ei->hint_femp.eidx > dentry) {
912+
if (candi_empty->count == 0) {
913+
candi_empty->cur = *clu;
914+
candi_empty->eidx = dentry;
915+
}
916+
917+
candi_empty->count++;
918+
if (candi_empty->count == num_entries)
919+
ei->hint_femp = *candi_empty;
920+
}
921+
}
922+
900923
enum {
901924
DIRENT_STEP_FILE,
902925
DIRENT_STEP_STRM,
@@ -921,7 +944,7 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
921944
{
922945
int i, rewind = 0, dentry = 0, end_eidx = 0, num_ext = 0, len;
923946
int order, step, name_len = 0;
924-
int dentries_per_clu, num_empty = 0;
947+
int dentries_per_clu;
925948
unsigned int entry_type;
926949
unsigned short *uniname = NULL;
927950
struct exfat_chain clu;
@@ -939,10 +962,13 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
939962
end_eidx = dentry;
940963
}
941964

942-
candi_empty.eidx = EXFAT_HINT_NONE;
965+
exfat_reset_empty_hint(&ei->hint_femp);
966+
943967
rewind:
944968
order = 0;
945969
step = DIRENT_STEP_FILE;
970+
exfat_reset_empty_hint(&candi_empty);
971+
946972
while (clu.dir != EXFAT_EOF_CLUSTER) {
947973
i = dentry & (dentries_per_clu - 1);
948974
for (; i < dentries_per_clu; i++, dentry++) {
@@ -962,35 +988,16 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
962988
entry_type == TYPE_DELETED) {
963989
step = DIRENT_STEP_FILE;
964990

965-
num_empty++;
966-
if (candi_empty.eidx == EXFAT_HINT_NONE &&
967-
num_empty == 1) {
968-
exfat_chain_set(&candi_empty.cur,
969-
clu.dir, clu.size, clu.flags);
970-
}
971-
972-
if (candi_empty.eidx == EXFAT_HINT_NONE &&
973-
num_empty >= num_entries) {
974-
candi_empty.eidx =
975-
dentry - (num_empty - 1);
976-
WARN_ON(candi_empty.eidx < 0);
977-
candi_empty.count = num_empty;
978-
979-
if (ei->hint_femp.eidx ==
980-
EXFAT_HINT_NONE ||
981-
candi_empty.eidx <=
982-
ei->hint_femp.eidx)
983-
ei->hint_femp = candi_empty;
984-
}
991+
exfat_set_empty_hint(ei, &candi_empty, &clu,
992+
dentry, num_entries);
985993

986994
brelse(bh);
987995
if (entry_type == TYPE_UNUSED)
988996
goto not_found;
989997
continue;
990998
}
991999

992-
num_empty = 0;
993-
candi_empty.eidx = EXFAT_HINT_NONE;
1000+
exfat_reset_empty_hint(&candi_empty);
9941001

9951002
if (entry_type == TYPE_FILE || entry_type == TYPE_DIR) {
9961003
step = DIRENT_STEP_FILE;
@@ -1090,9 +1097,6 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
10901097
rewind = 1;
10911098
dentry = 0;
10921099
clu.dir = p_dir->dir;
1093-
/* reset empty hint */
1094-
num_empty = 0;
1095-
candi_empty.eidx = EXFAT_HINT_NONE;
10961100
goto rewind;
10971101
}
10981102

0 commit comments

Comments
 (0)