When one opens a file in subdirectory, and then 'rm -rf' that directory, it
works OK in ext2. It, however, fails on *FAT based filesystems (msdos, vfat,
umsdos) with EBUSY on rmdir(2). It cases problems for example when compiling
kernel on umsdos partition, make(1) has some dependency opened, and then
tries to 'rm -rf' that directory, which fails.
It happens both in 2.2.15pre14 and 2.3.99-pre3 (and probably all the
other versions).
The following proggy demonstrates that.
Any ideas how to fix it (or work around it) ?
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define DIR "inc"
#define FNAME DIR "/test.h"
int main() {
int fd, retval;
retval = mkdir (DIR, 0700);
if (retval < 0) { perror ("Warning: mkdir"); }
fd = open (FNAME, O_RDWR|O_CREAT, 0600);
if (fd < 0) { perror ("FATAL: open"); exit (1); }
retval = unlink (FNAME);
if (retval < 0) { perror ("FATAL: unlink"); exit (2); }
/* if this close(2) is uncommented, it works OK even on vfat/umsdos */
/* close(fd); */
retval = rmdir (DIR);
if (retval < 0) { perror ("FATAL: rmdir"); exit (3); }
fprintf (stderr, "All passed OK\n"); exit (0);
}
--
Opinions above are GNU-copylefted.