tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Adding linux_link(2) system call, second round



On Mon 01 Aug 2011 at 10:50:50 +0200, Matthias Drochner wrote:
> While the "DESCRIPTION" chapter doesn't tell it explicitely,
> we have the following in "ERRORS":
> 
> [ELOOP]
>  A loop exists in symbolic links encountered during resolution of the path1
>  or path2 argument.
> 
> This implies that the intention is that symlinks are followed.

Non-final symlinks are always followed, even for lchmod(2), readlink(2)
and similar functions, right? For instance, readlink(2)'s man page also
mentions ELOOP.

Another argument that allowing hard links to symlinks is "only natural":
The rename(2) operation does it in any case (on ffs). And one *can* rename
symlinks.

From /usr/src/sys/ufs/ufs/ufs_vnops.c:

/*
 * Rename vnode operation
 *      rename("foo", "bar");
 * is essentially
 *      unlink("bar");
 *      link("foo", "bar");
 *      unlink("foo");
 * but ``atomically''.  Can't do full commit without saving state in the
 * inode on disk which isn't feasible at this time.  Best we can do is
 * always guarantee the target exists.

The code below that doesn't appear to special-case symlinks, only
directories.

FreeBSD also allows hard links to symlinks, with the ln -P option.
(This must have been introduced in version 7 or 8; 6.1 doesn't have it
but 8.1 does)

LN(1)                   FreeBSD General Commands Manual                  LN(1)

NAME
     ln, link -- link files

SYNOPSIS
     ln [-L | -P | -s [-F]] [-f | -iw] [-hnv] source_file [target_file]
     ln [-L | -P | -s [-F]] [-f | -iw] [-hnv] source_file ... target_dir
     link source_file target_file

DESCRIPTION
...
     -P    When creating a hard link to a symbolic link, create a hard link to
           the symbolic link itself.  This option cancels the -L option.

test$ ln -s foo bar
test$ l
total 8
drwxr-xr-x   2 olafs  vb   3 Aug  1 12:25 ./
drwxr-xr-x  23 olafs  vb  29 Aug  1 12:25 ../
lrwxr-xr-x   1 olafs  vb   3 Aug  1 12:25 bar@ -> foo
test$ ln -P bar baz
test$ l
total 8
drwxr-xr-x   2 olafs  vb   4 Aug  1 12:25 ./
drwxr-xr-x  23 olafs  vb  29 Aug  1 12:25 ../
lrwxr-xr-x   2 olafs  vb   3 Aug  1 12:25 bar@ -> foo
lrwxr-xr-x   2 olafs  vb   3 Aug  1 12:25 baz@ -> foo

I tested both on ffs and zfs. The results are the same.


-Olaf.
-- 
___ Olaf 'Rhialto' Seibert  -- There's no point being grown-up if you 
\X/ rhialto/at/xs4all.nl    -- can't be childish sometimes. -The 4th Doctor


Home | Main Index | Thread Index | Old Index