* [PATCH] exfat: free directory cluster when zeroing fails
@ 2026-11-28 21:19 Wesley Atwell
2026-11-29 6:42 ` Namjae Jeon
0 siblings, 1 reply; 2+ messages in thread
From: Wesley Atwell @ 2026-11-28 21:19 UTC (permalink / raw)
To: Yuezhang Mo, Sungjong Seo, Namjae Jeon; +Cc: exfat, Wesley Atwell, linux-kernel
When a synchronous exFAT directory needs another cluster,
exfat_find_empty_entry() allocates one and zeroes it before linking it
into the directory. If the zeroing write fails, the function returns an
error but leaves the new cluster allocated. The directory has not grown,
so the cluster is unreachable and its space remains unavailable.
In a QEMU guest on the exFAT dev tree, a tar extraction to a dirsync
volume hit a targeted block write error while extending a directory.
Tar reported EIO and the new file was absent, but the allocation bitmap
showed one extra 4 KiB cluster in use after remount. The default
fsck.exfat check and repair both called the volume clean.
Free the newly allocated cluster on the zeroing error and return that
error, as exfat_alloc_new_dir() already does for the analogous path.
The healthy extraction still grows the directory. With the fix, the
failed extraction still reports EIO but the bitmap returns to its
original free-cluster count after remount.
OpenAI Codex identified the missing rollback, drafted the fix and
changelog, and prepared the QEMU tar extraction tests. Both kernels
passed the healthy extraction. Under the injected write error, the fix
preserved EIO and restored the original free-cluster count after
remount.
Fixes: 5f2aa075070c ("exfat: add inode operations")
Signed-off-by: Wesley Atwell <atwellwea@gmail.com>
---
fs/exfat/namei.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 307a2130406e..d077051e7ea2 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -345,8 +345,11 @@ int exfat_find_empty_entry(struct inode *inode,
if (ret)
return ret;
- if (exfat_zeroed_cluster(inode, clu.dir))
- return -EIO;
+ ret = exfat_zeroed_cluster(inode, clu.dir);
+ if (ret) {
+ exfat_free_cluster(inode, &clu);
+ return ret;
+ }
if (ei->start_clu == EXFAT_EOF_CLUSTER) {
ei->start_clu = clu.dir;
base-commit: 36edb65f309977762fc001c17dcab748bad4b7c1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] exfat: free directory cluster when zeroing fails
2026-11-28 21:19 [PATCH] exfat: free directory cluster when zeroing fails Wesley Atwell
@ 2026-11-29 6:42 ` Namjae Jeon
0 siblings, 0 replies; 2+ messages in thread
From: Namjae Jeon @ 2026-11-29 6:42 UTC (permalink / raw)
To: Wesley Atwell; +Cc: Yuezhang Mo, Sungjong Seo, exfat, linux-kernel
> @@ -345,8 +345,11 @@ int exfat_find_empty_entry(struct inode *inode,
> if (ret)
> return ret;
>
> - if (exfat_zeroed_cluster(inode, clu.dir))
> - return -EIO;
> + ret = exfat_zeroed_cluster(inode, clu.dir);
> + if (ret) {
> + exfat_free_cluster(inode, &clu);
If clu.flags is ALLOC_FAT_CHAIN, exfat_free_cluster() follows the FAT
to EOF. We need to set clu.flags to ALLOC_NO_FAT_CHAIN before calling
exfat_free_cluster().
> + return ret;
This also propagates -ENOMEM from exfat_zeroed_cluster(). Please drop
the /* -EIO or -ENOSPC */ comments at the exfat_find_empty_entry()
call sites in exfat_add_entry(), exfat_rename_file(), and
exfat_move_file() or leave the existing -EIO return here.
> + }
>
> if (ei->start_clu == EXFAT_EOF_CLUSTER) {
> ei->start_clu = clu.dir;
>
> base-commit: 36edb65f309977762fc001c17dcab748bad4b7c1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 6:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 21:19 [PATCH] exfat: free directory cluster when zeroing fails Wesley Atwell
2026-11-29 6:42 ` Namjae Jeon
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.