readdir() loses entries on ramfs and tmpfs

From: Pavel Roskin (proski@gnu.org)
Date: Wed Dec 26 2001 - 19:50:11 EST


Hello!

I got a report that GNU Midnight Commander fails to erase some directories
on tmpfs from the first attempt. However, it succeeds the next time.

I could reproduce the problem on 2.4.18-pre1 compiled with gcc-2.96 from
RedHat 7.2.

I have reduced the problem to a simple test. This script creates
directories dir, dir/0, ... dir/168

=========================
#!/bin/sh
rm -rf dir
mkdir dir
i=0
while test $i != 169; do
  mkdir dir/$i
  i=$(($i+1))
done
=========================

And this C program tries to remove all subdirectories under "dir":

=========================
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
int main()
{
    DIR *dir;
    struct dirent *d;
    if (chdir("dir") != 0)
        return 1;
    dir = opendir(".");
    if (!dir)
        return 2;
    while ((d = readdir(dir)) != NULL) {
        printf("%s\n", d->d_name);
        rmdir(d->d_name);
    }
    closedir(dir);
    return 0;
}
=========================

This program succeeds on vfat and ext3 but it fails to remove "dir/0" on
ramfs and tmpfs.

169 is not a random number. It's the minimal number required to reproduce
the problem. Maybe other systems need another value.

Basically, removing a subdirectory in a directory open with opendir()
causes an entry (file or directory) 168 entries later to be skipped by
readdir().

I'm sorry, I cannot elaborate more, but the issue seems to be very
serious.

-- 
Regards,
Pavel Roskin

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Dec 31 2001 - 21:00:13 EST