* [PATCH v2] exfat: free directory cluster when zeroing fails
@ 2026-11-29 22:31 Wesley Atwell
2026-11-30 0:03 ` Namjae Jeon
0 siblings, 1 reply; 2+ messages in thread
From: Wesley Atwell @ 2026-11-29 22:31 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 only the newly allocated cluster if zeroing fails. Allocation can
mark the temporary cluster as a FAT chain before it is linked to the
directory, so set its flag to ALLOC_NO_FAT_CHAIN before freeing it.
Return EIO as before. With the fix, the failed extraction still reports
EIO, but the bitmap returns to its original free-cluster count after
remount. The healthy extraction still grows the directory.
This contribution was developed with AI assistance.
Fixes: 5f2aa075070c ("exfat: add inode operations")
Link: https://lore.kernel.org/all/kernel-7be3083ed7a0fec5-v1.atwellwea@gmail.com/
Signed-off-by: Wesley Atwell <atwellwea@gmail.com>
---
Changes since v1:
- Free only the new cluster when allocation switches to a FAT chain.
- Preserve the original EIO return and its callers' errno comments.
v1: https://lore.kernel.org/all/kernel-7be3083ed7a0fec5-v1.atwellwea@gmail.com/
fs/exfat/namei.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 307a2130406e7..f7cc1b4f391cd 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))
+ if (exfat_zeroed_cluster(inode, clu.dir)) {
+ clu.flags = ALLOC_NO_FAT_CHAIN;
+ exfat_free_cluster(inode, &clu);
return -EIO;
+ }
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 v2] exfat: free directory cluster when zeroing fails
2026-11-29 22:31 [PATCH v2] exfat: free directory cluster when zeroing fails Wesley Atwell
@ 2026-11-30 0:03 ` Namjae Jeon
0 siblings, 0 replies; 2+ messages in thread
From: Namjae Jeon @ 2026-11-30 0:03 UTC (permalink / raw)
To: Wesley Atwell; +Cc: Yuezhang Mo, Sungjong Seo, exfat, linux-kernel
On Mon, Nov 30, 2026 at 7:31 AM Wesley Atwell <atwellwea@gmail.com> wrote:
>
> 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 only the newly allocated cluster if zeroing fails. Allocation can
> mark the temporary cluster as a FAT chain before it is linked to the
> directory, so set its flag to ALLOC_NO_FAT_CHAIN before freeing it.
> Return EIO as before. With the fix, the failed extraction still reports
> EIO, but the bitmap returns to its original free-cluster count after
> remount. The healthy extraction still grows the directory.
>
> This contribution was developed with AI assistance.
>
> Fixes: 5f2aa075070c ("exfat: add inode operations")
> Link: https://lore.kernel.org/all/kernel-7be3083ed7a0fec5-v1.atwellwea@gmail.com/
> Signed-off-by: Wesley Atwell <atwellwea@gmail.com>
Applied it to #dev.
Thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 0:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 22:31 [PATCH v2] exfat: free directory cluster when zeroing fails Wesley Atwell
2026-11-30 0:03 ` 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.