link(2) behaviour when creating a hardlink to a symlink

ejc eric.j.christeson at gmail.com
Wed Jun 11 14:24:10 PDT 2008


On Wed, Jun 11, 2008 at 3:48 PM, ejc <eric.j.christeson at gmail.com> wrote:
> On Wed, Jun 11, 2008 at 3:27 PM, Jordan Gordeev <jgordeev at dir.bg> wrote:
>> Cvs2svn, a package available in pkgsrc, doesn't extract successfully on
>> DragonFly.
>> During extraction, a link() syscall is made to create a hardlink to a
>> symlink that points to a non-existent file. The link() call fails with
>> ENOENT.
>> I'd like to know if you think that behaviour to be a bug.
>
> I looked up symbolic links in apue2 and link() is listed as a function
> that follows symbolic links.  "If the function follows a symbolic
> link, a pathname argument to the function refers to the file pionted
> to by the symbolic link."
> Looks like this behavior is correct.

Just for kicks I ran a test on a few systems at my disposal:

OSX 10.4.11

dyn253:~/test ejc$ touch foo
dyn253:~/test ejc$ ls -li
total 0
955608 -rw-r--r--   1 ejc  ejc  0 Jun 11 16:12 foo
dyn253:~/test ejc$ ln -s foo bar
dyn253:~/test ejc$ ls -li
total 8
955609 lrwxr-xr-x   1 ejc  ejc  3 Jun 11 16:12 bar -> foo
955608 -rw-r--r--   1 ejc  ejc  0 Jun 11 16:12 foo
dyn253:~/test ejc$ ln bar blah
dyn253:~/test ejc$ ls -li
total 8
955609 lrwxr-xr-x   1 ejc  ejc  3 Jun 11 16:12 bar -> foo
955608 -rw-r--r--   2 ejc  ejc  0 Jun 11 16:12 blah
955608 -rw-r--r--   2 ejc  ejc  0 Jun 11 16:12 foo


FreeBSD 6.3

ejc at chicadee$ touch foo
ejc at chicadee$ ls -li
total 0
16863301 -rw-r--r--  1 ejc  ejc  0 Jun 11 16:14 foo
ejc at chicadee$ ln -s foo bar
ejc at chicadee$ ls -li
total 0
16863303 lrwxr-xr-x  1 ejc  ejc  3 Jun 11 16:14 bar -> foo
16863301 -rw-r--r--  1 ejc  ejc  0 Jun 11 16:14 foo
ejc at chicadee$ ln bar blah
ejc at chicadee$ ls -li
total 0
16863303 lrwxr-xr-x  1 ejc  ejc  3 Jun 11 16:14 bar -> foo
16863301 -rw-r--r--  2 ejc  ejc  0 Jun 11 16:14 blah
16863301 -rw-r--r--  2 ejc  ejc  0 Jun 11 16:14 foo


Slackware 12.0 (Linux 2.6.21.5)

ejc at robin:~/test$ touch foo
ejc at robin:~/test$ ln -s foo bar
ejc at robin:~/test$ rm bar
ejc at robin:~/test$ ls -li
total 0
982125 -rw-r--r-- 1 ejc wheel 0 2008-06-11 16:15 foo
ejc at robin:~/test$ ln -s foo bar
ejc at robin:~/test$ ls -li
total 0
982129 lrwxrwxrwx 1 ejc wheel 3 2008-06-11 16:16 bar -> foo
982125 -rw-r--r-- 1 ejc wheel 0 2008-06-11 16:15 foo
ejc at robin:~/test$ ln bar blah
ejc at robin:~/test$ ls -li
total 0
982129 lrwxrwxrwx 2 ejc wheel 3 2008-06-11 16:16 bar -> foo
982129 lrwxrwxrwx 2 ejc wheel 3 2008-06-11 16:16 blah -> foo
982125 -rw-r--r-- 1 ejc wheel 0 2008-06-11 16:15 foo

OSX and FreeBSD (DragonFlyBSD also) follow the symlink, Linux doesn't
I tried this on a Linux box with a 2.4 series kernel and it performed
the same as 2.6, but I got a warning:
"making a hard link to a symbolic link is not portable"

eric





More information about the Kernel mailing list