From: Chi Zhiling <chizhiling@kylinos.cn>
This patch introduces exfat_count_contig_clusters to obtain batch entries,
which is an infrastructure used to support iomap.
Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
---
fs/exfat/exfat_fs.h | 2 ++
fs/exfat/fatent.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
index d52893276e9a..421dd7c61cca 100644
--- a/fs/exfat/exfat_fs.h
+++ b/fs/exfat/exfat_fs.h
@@ -449,6 +449,8 @@ int exfat_find_last_cluster(struct super_block *sb, struct exfat_chain *p_chain,
unsigned int *ret_clu);
int exfat_count_num_clusters(struct super_block *sb,
struct exfat_chain *p_chain, unsigned int *ret_count);
+int exfat_count_contig_clusters(struct super_block *sb,
+ struct exfat_chain *p_chain, unsigned int *ret_count);
/* balloc.c */
int exfat_load_bitmap(struct super_block *sb);
diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c
index d980d17176c2..9dcee9524155 100644
--- a/fs/exfat/fatent.c
+++ b/fs/exfat/fatent.c
@@ -524,3 +524,36 @@ int exfat_count_num_clusters(struct super_block *sb,
return 0;
}
+
+int exfat_count_contig_clusters(struct super_block *sb,
+ struct exfat_chain *p_chain, unsigned int *ret_count)
+{
+ struct buffer_head *bh = NULL;
+ unsigned int clu, next_clu;
+ unsigned int count;
+
+ if (!p_chain->dir || p_chain->dir == EXFAT_EOF_CLUSTER) {
+ *ret_count = 0;
+ return 0;
+ }
+
+ if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
+ *ret_count = p_chain->size;
+ return 0;
+ }
+
+ clu = p_chain->dir;
+ for (count = 1; count < p_chain->size; count++) {
+ if (exfat_ent_get(sb, clu, &next_clu, &bh))
+ return -EIO;
+ if (++clu != next_clu)
+ break;
+ }
+
+ /* TODO: Update p_claim to help caller read ahead the next block */
+
+ brelse(bh);
+ *ret_count = count;
+
+ return 0;
+}
--
2.43.0