Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 7b6bab2

Browse files
YuezhangMonamjaejeon
authored andcommitted
exfat: add __exfat_get_dentry_set() helper
Since exfat_get_dentry_set() invokes the validate functions of exfat_validate_entry(), it only supports getting a directory entry set of an existing file, doesn't support getting an empty entry set. To remove the limitation, add this helper. 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 855684c commit 7b6bab2

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

fs/exfat/dir.c

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,6 @@ struct exfat_dentry *exfat_get_dentry(struct super_block *sb,
775775
}
776776

777777
enum exfat_validate_dentry_mode {
778-
ES_MODE_STARTED,
779778
ES_MODE_GET_FILE_ENTRY,
780779
ES_MODE_GET_STRM_ENTRY,
781780
ES_MODE_GET_NAME_ENTRY,
@@ -790,11 +789,6 @@ static bool exfat_validate_entry(unsigned int type,
790789
return false;
791790

792791
switch (*mode) {
793-
case ES_MODE_STARTED:
794-
if (type != TYPE_FILE && type != TYPE_DIR)
795-
return false;
796-
*mode = ES_MODE_GET_FILE_ENTRY;
797-
break;
798792
case ES_MODE_GET_FILE_ENTRY:
799793
if (type != TYPE_STREAM)
800794
return false;
@@ -834,30 +828,32 @@ struct exfat_dentry *exfat_get_dentry_cached(
834828
}
835829

836830
/*
837-
* Returns a set of dentries for a file or dir.
831+
* Returns a set of dentries.
838832
*
839833
* Note It provides a direct pointer to bh->data via exfat_get_dentry_cached().
840834
* User should call exfat_get_dentry_set() after setting 'modified' to apply
841835
* changes made in this entry set to the real device.
842836
*
843837
* in:
844838
* sb+p_dir+entry: indicates a file/dir
845-
* type: specifies how many dentries should be included.
839+
* num_entries: specifies how many dentries should be included.
840+
* It will be set to es->num_entries if it is not 0.
841+
* If num_entries is 0, es->num_entries will be obtained
842+
* from the first dentry.
843+
* out:
844+
* es: pointer of entry set on success.
846845
* return:
847-
* pointer of entry set on success,
848-
* NULL on failure.
846+
* 0 on success
847+
* -error code on failure
849848
*/
850-
int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
849+
static int __exfat_get_dentry_set(struct exfat_entry_set_cache *es,
851850
struct super_block *sb, struct exfat_chain *p_dir, int entry,
852-
unsigned int type)
851+
unsigned int num_entries)
853852
{
854853
int ret, i, num_bh;
855854
unsigned int off;
856855
sector_t sec;
857856
struct exfat_sb_info *sbi = EXFAT_SB(sb);
858-
struct exfat_dentry *ep;
859-
int num_entries;
860-
enum exfat_validate_dentry_mode mode = ES_MODE_STARTED;
861857
struct buffer_head *bh;
862858

863859
if (p_dir->dir == DIR_DELETED) {
@@ -880,12 +876,18 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
880876
return -EIO;
881877
es->bh[es->num_bh++] = bh;
882878

883-
ep = exfat_get_dentry_cached(es, ES_IDX_FILE);
884-
if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode))
885-
goto put_es;
879+
if (num_entries == ES_ALL_ENTRIES) {
880+
struct exfat_dentry *ep;
881+
882+
ep = exfat_get_dentry_cached(es, ES_IDX_FILE);
883+
if (ep->type != EXFAT_FILE) {
884+
brelse(bh);
885+
return -EIO;
886+
}
887+
888+
num_entries = ep->dentry.file.num_ext + 1;
889+
}
886890

887-
num_entries = type == ES_ALL_ENTRIES ?
888-
ep->dentry.file.num_ext + 1 : type;
889891
es->num_entries = num_entries;
890892

891893
num_bh = EXFAT_B_TO_BLK_ROUND_UP(off + num_entries * DENTRY_SIZE, sb);
@@ -918,8 +920,27 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
918920
es->bh[es->num_bh++] = bh;
919921
}
920922

923+
return 0;
924+
925+
put_es:
926+
exfat_put_dentry_set(es, false);
927+
return -EIO;
928+
}
929+
930+
int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
931+
struct super_block *sb, struct exfat_chain *p_dir,
932+
int entry, unsigned int num_entries)
933+
{
934+
int ret, i;
935+
struct exfat_dentry *ep;
936+
enum exfat_validate_dentry_mode mode = ES_MODE_GET_FILE_ENTRY;
937+
938+
ret = __exfat_get_dentry_set(es, sb, p_dir, entry, num_entries);
939+
if (ret < 0)
940+
return ret;
941+
921942
/* validate cached dentries */
922-
for (i = ES_IDX_STREAM; i < num_entries; i++) {
943+
for (i = ES_IDX_STREAM; i < es->num_entries; i++) {
923944
ep = exfat_get_dentry_cached(es, i);
924945
if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode))
925946
goto put_es;

fs/exfat/exfat_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
501501
int num);
502502
int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
503503
struct super_block *sb, struct exfat_chain *p_dir, int entry,
504-
unsigned int type);
504+
unsigned int num_entries);
505505
int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int sync);
506506
int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir);
507507

0 commit comments

Comments
 (0)