The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] exfat: free directory cluster when zeroing fails
@ 2026-11-28 21:19 Wesley Atwell
  0 siblings, 0 replies; only message 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] only message in thread

only message in thread, other threads:[~2026-11-28 21:19 UTC | newest]

Thread overview: (only message) (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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox