[PATCH 3/4] fat: support adding multiple clusters

From: Matheus Alves de Almeida

Date: Wed Oct 07 2026 - 22:12:29 EST


fat_add_cluster() currently adds only 1 cluster to the file's chain.
Implement support for adding more in one call and rename the function
to reflect the new behavior.

Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@xxxxxxxxxxxx>
---
fs/fat/fat.h | 2 +-
fs/fat/file.c | 2 +-
fs/fat/inode.c | 8 ++++----
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/fat/fat.h b/fs/fat/fat.h
index 75ac0239a..683fb68a7 100644
--- a/fs/fat/fat.h
+++ b/fs/fat/fat.h
@@ -440,7 +440,7 @@ static inline unsigned long fat_dir_hash(int logstart)
{
return hash_32(logstart, FAT_HASH_BITS);
}
-extern int fat_add_cluster(struct inode *inode);
+extern int fat_add_clusters(struct inode *inode, int nr_cluster);

/* fat/misc.c */
extern __printf(3, 4) __cold
diff --git a/fs/fat/file.c b/fs/fat/file.c
index 1c835ca5f..41d49e9de 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -292,7 +292,7 @@ static long fat_fallocate(struct file *file, int mode,

/* Start the allocation.We are not zeroing out the clusters */
while (nr_cluster-- > 0) {
- err = fat_add_cluster(inode);
+ err = fat_add_clusters(inode, 1);
if (err)
goto error;
}
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index f775a004c..44fc9b556 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -101,16 +101,16 @@ static struct fat_floppy_defaults {
},
};

-int fat_add_cluster(struct inode *inode)
+int fat_add_clusters(struct inode *inode, int nr_cluster)
{
int err, cluster;

- err = fat_alloc_clusters(inode, &cluster, 1);
+ err = fat_alloc_clusters(inode, &cluster, nr_cluster);
if (err)
return err;
/* FIXME: this cluster should be added after data of this
* cluster is writed */
- err = fat_chain_add(inode, cluster, 1);
+ err = fat_chain_add(inode, cluster, nr_cluster);
if (err)
fat_free_clusters(inode, cluster);
return err;
@@ -152,7 +152,7 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock,
*/
if (!offset && !(iblock < last_block)) {
/* TODO: multiple cluster allocation would be desirable. */
- err = fat_add_cluster(inode);
+ err = fat_add_clusters(inode, 1);
if (err)
return err;
}
--
2.43.0