Re: Endless getdents() in vfat filesystem
From: Richard Weinberger
Date: Sat Nov 14 2015 - 05:33:16 EST
On Sat, Nov 14, 2015 at 2:19 AM, Vegard Nossum <vegard.nossum@xxxxxxxxxx> wrote:
> Hi,
>
> Using the attached disk image I observe that getdents() never returns
> the end of the directory, i.e. mounting the disk image on a loopback
> device and running 'ls' under strace shows an endless stream of:
>
> getdents(3, /* 2 entries */, 32768) = 48
> getdents(3, /* 2 entries */, 32768) = 48
> getdents(3, /* 2 entries */, 32768) = 48
> ...
Please more details. Is this image hand crafted?
If not, how has it been created? Is is supposed to work?
>From a quick look it seems as the root directory is bad but we report
progress in ->iterate.
ctx->pos is 2, we set it back to 0, because of the faked dot entries.
but fat_get_entry() did not make any progress and we report 0 back to VFS.
So, VFS sees progress and the game continues.
Does the attached patch help?
--
Thanks,
//richard
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index 4afc4d9..7f66a38 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -586,8 +586,12 @@ static int __fat_readdir(struct inode *inode, struct file *file,
bh = NULL;
get_new:
- if (fat_get_entry(inode, &cpos, &bh, &de) == -1)
+ if (fat_get_entry(inode, &cpos, &bh, &de) == -1) {
+ if (cpos == 0)
+ cpos = 2;
+
goto end_of_dir;
+ }
parse_record:
nr_slots = 0;
/*