19.5 link (5909)

This procedure implements a system call which enters a new name for an existing file into the directory structure. Arguments to the procedure are the existing and the new names of the file;

5914:

Look up the existing file name;

5917:

If the file already has 127 different names, quit in disgust;

5921:

If the existing file turns out to be a directory, then only the super-user may rename it;

5926:

Unlock the existing file “inode” This is locked when the first call on “namei” does an “iget” (7534, 7664).

Under what conditions would the failure to unlock the “inode” here be disastrous? The chances that the existing file would be a directory encountered in the search for the new name would seem slight, if not impossible. Most probably the relevant circumstance is where the system is attempting to recreate an alternative file name or alias, which already exists;

5927:

Search the directory for the second name, with the intention of creating a new entry;

5930:

There is an existing file with the second name;

5935:

“u.u_pdir” is set as a side effect of the call on “namei” (5928). Check that the directory resides on the same device as the file;

5940:

Write a new directory entry (see below);

5941:

Increase the “link” count for the file.