Subject: Re: chmod & symlink broken in 1.6
To: Andrew Brown <atatat@atatdot.net>
From: Greywolf <greywolf@starwolf.com>
List: tech-kern
Date: 10/29/2002 21:31:20
On Tue, 29 Oct 2002, Andrew Brown wrote:

# ah, good point.  yes, to make a hardlink to a symlink when the
# location of the new link might not work would be pointless.  link(2)
# should, therefore, traverse the symlink.

...to what end?  Don't you think that kind of special-cases symlinks?
[Never mind that symlinks *are* a "special case"...]

If I do:

	...
	(void) close(open("/var/tmp/file",O_CREAT|O_TRUNC|O_RDWR,0644));
	(void) symlink("/var/tmp/file", "/var/tmp/symlink");
	(void) link("/var/tmp/symlink","/var/tmp/linktosymlink");

Then barring any problems with creation during that sequence (which I'm
aware I'm ignoring because of course there won't be any ;) ), I should
end up with (assuming a umask of 022):

49 -rw-r--r--  1 root      wheel          0 [curtime] file
50 lrwxr-xr-x  2 root      wheel         13 [curtime] symlink -> /var/tmp/file
50 lrwxr-xr-x  2 root      wheel         13 [curtime] linktosymlink -> /var/tmp/file

Indeed, this is precisely the projected, expected and verified result.

If link(2) starts traversing symlinks, I'm going to get a little worried.
Besides, what if the symlink points off-device?

# unless you wish to rule out the possibility of creating a symlink that
# points to something that doesn't exist.  :)

No.

# >If you want a hard link to an actual file, readlink()/link() becomes
# >the way to go.
#
# to a point, yes.

Well, I don't see much of an alternate.  link(2) was never designed with
follow semantics in mind.  It does a very simple operation:

	- adds a directory entry with the inum of the original
	- increments the link count on the inode

[with locking, filesystem semantics, space and access checks, of course]

Making link(2) traverse the link is, I believe, "broken".

The other system calls traversing make a modicum of sense; however,
I believe the extensions for symperm allow for some very clever
filesystem manipulations!

				--*greywolf;
--
"Hello, I've just upgraded my OS to Windows 2000..."
"Yes...?"
"Well, my computer doesn't work now."
"Yes, you just said that a second ago."