Kirk has said it took decades to get rename(2) right... it was by far the hardest system call to get right, especially in the face of concurrency.

Warner

Warner

On Wed, Dec 29, 2021, 9:11 AM Clem Cole <clemc@ccc.com> wrote:
Just get the 4.1 man pages and it says: "Directories may only be moved within the same parent directory."

On Wed, Dec 29, 2021 at 10:44 AM Will Senn <will.senn@gmail.com> wrote:
On 12/29/21 9:17 AM, Clem Cole wrote:
Not until the BSD rename system call,.

Try it on V6 or V7 and you will get 'directory exists' as an error.

Sure enough. I never really noticed. I guess cuz I was careful about creating directories in the first place.

Think about the UNIX FS and the link system call. How is mv implemented?   You link the file to the new directory and the unlink it from the old one.   But a directory file can not be in two directories at the same time as the .. link would fail.      When Joy created the rename system call it became possible.  Until System V picked it up (IIRC was SVR3), only system that supported the BSD world.

Nice summary. I will add it to my systems programming investigations list.
What I have forgotten is if the BSD mv command for 4.1 supported it.  If it did then it was not atomic -- it would have had to create the new directory, move the contents independently and then remove the old one.

FWIW: when we did the first SMP UNIX at Masscomp we had supported the BSD FS and the 4.1c/4.2 system calls.   Joy's implementation of rename was a real mess.   Making it atomic, supporting an SMP and deal with all the recovery paths on an error took some work.  It's funny, the rename system call is a simple idea, but on a failure when partially thru it, makes unwinding the partial completion an interesting problem.
It's impressive what early work was done and how few today really understand the challenges that were met and overcome to give us our cushy oses.

Clem

On Wed, Dec 29, 2021 at 9:34 AM Will Senn <will.senn@gmail.com> wrote:
I'm a little flummoxed in trying to move some directories around in svr2. Shouldn't the following work?

    mkdir a
    mkdir b
    mv a b

I get the following error:
    mv: b exists

I tried many of the possible variants including:
mv a b/
mv: b/ exists
mv a b/a
mv: directory rename only
cd b
mv ../a .
mv: . exists
mv ../a ./
mv: ./ exists
mv ../a ./a
mv: directory rename only

If moving directories into existing directories wasn't allowed in those days, 1) how were directories managed? and 2) when did moving directories into directories become a thing?