linux/fs/exfat
Hengyu Liang 8534eb11ac exfat: fix reading a directory whose FAT chain is longer than its size
Commit 08cf4a8181 ("exfat: use exfat_chain_advance helper") made the
directory code walk the clusters of a directory with
exfat_chain_advance().

However, exfat_chain_advance() returns -EIO once it has walked as many
clusters as the size of the directory says. The FAT chain of a directory
can be longer than that, because some cameras stop updating the size,
see commit 1e5654de0f ("exfat: handle wrong stream entry size in
exfat_readdir()"). As of now, opening such a directory fails with EIO as
soon as the chain is two clusters longer than the size. Reading a
directory that has a FAT chain after a seek past its end fails with EIO
too.

The issue can be reproduced with an image in which the size of a
directory with 200 files and 7 clusters is lowered to 2 clusters:

    mount -o loop exfat.img /mnt
    ls /mnt/d | wc -l

Before commit 08cf4a8181 ("exfat: use exfat_chain_advance helper"),
the result is:

    200

After that commit, ls fails with "Input/output error" and the result is:

    0

This patch will make exfat_chain_advance() follow the FAT to its end
when the directory has a FAT chain, as the code did before, and keep the
size check for a directory without one.

Fixes: 08cf4a8181 ("exfat: use exfat_chain_advance helper")
Cc: stable@vger.kernel.org
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
Reviewed-by: Chi Zhiling <chizhiling@kylinos.cn>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-21 08:28:32 +09:00
..
balloc.c exfat: keep FITRIM within the requested range 2026-08-14 23:43:02 +09:00
cache.c exfat: support multi-cluster for exfat_get_cluster 2026-02-12 21:21:51 +09:00
dir.c exfat: remove runtime integer division 2026-10-21 08:28:29 +09:00
exfat_fs.h exfat: fix reading a directory whose FAT chain is longer than its size 2026-10-21 08:28:32 +09:00
exfat_raw.h exfat: fix s_maxbytes 2026-03-31 23:01:07 +09:00
fatent.c exfat: clean stale bdev buffers of newly allocated clusters 2026-10-21 08:28:32 +09:00
file.c exfat: free clusters beyond EOF when a write fails or is short 2026-10-21 08:28:32 +09:00
inode.c exfat: make valid_size and zeroed_size atomic 2026-10-21 08:28:30 +09:00
iomap.c exfat: fix a large buffered write failing when the volume is nearly full 2026-10-21 08:28:31 +09:00
iomap.h exfat: add swap_activate support 2026-06-15 20:01:00 +09:00
Kconfig exfat: add iomap direct I/O support 2026-06-15 20:00:40 +09:00
Makefile exfat: add iomap buffered I/O support 2026-06-15 20:00:23 +09:00
misc.c exfat: check for a directory write error with buffer_write_io_error() 2026-09-10 09:27:25 +02:00
namei.c exfat: make valid_size and zeroed_size atomic 2026-10-21 08:28:30 +09:00
nls.c exfat: fix handling of damaged volume in exfat_create_upcase_table() 2026-06-15 19:55:17 +09:00
super.c exfat: remove runtime integer division 2026-10-21 08:28:29 +09:00