From: Linus Torvalds (torvalds@klaava.Helsinki.FI)
Date: 01/29/93


From: torvalds@klaava.Helsinki.FI (Linus Torvalds)
Subject: Re: 2 files with the same name in single directory, 0.99pl3, extfs
Date: Fri, 29 Jan 1993 09:22:12 GMT

In article <1993Jan26.235759.15592@mwhh.hanse.de> markus@mwhh.hanse.de (Markus Witt) writes:
>probreak@matt.ksu.ksu.edu (James Michael Chacon) writes:
>
>[regarding two files with the same name in one directory]
>
>> This hasn't come up in a while, but it can happen. Linus posted a while
>> back that if you thrash the file system hard enough then multiple files
>> with the same names can be created like this. To get rid of them is easy
>> though.
>>
>> If you just type rm <filename>, then the first one it finds will be deleted,
>> and the second one left alone. If you want to save the first one, just mv
>> it to a different name, since again it will be the first one found.
>
>Is this a bug in the file systems, in the kernel or what?
>How likely is this to happen. What do you call "trash the fs hard enough?"

Yes, it's a bug - there is a race-condition when two processes are
trying to create the same file (same name, anyway) at the same time. I
didn't bother to do extensive checks for this: it's a lot of code for a
problem that is very hard to see (I think this is the second time it has
come up on c.o.l), and which isn't too serious anyway.

To get two files with the same name you have to:

 - be low on memory. The buffer cache has to suffer real bad. Get
   linux swapping hard, and then start copying big files.
 - (at least) two processes trying to create the same file at once.

I tried it out a long time ago (even before the problem came up on c.o.l
the first time), and yes, it was reasonably easy to do if you know how.
I didn't fix it, as it really generally needs extreme circumstances to
happen.

                Linus